Beispiel #1
0
/*
 * initializes the LKM
 * calls functions to create/init the following:
 *		the stats file in /proc
 * 		the device node in /dev
 *		the fifo_queue is initialized
 */
static int __init fifo_mod_init(void)
{
	int err;

	err = fifo_init(&fifo, size);
	if (err)
	{
		printk(KERN_INFO "--- %s: fifo_init failed!\n", mod_name);	
		return err;
	}

	proc_stats = proc_create(
		"deeds_fifo_stats", 0444, 0, &stat_fops);

	if (0 == proc_stats) 
	{
		printk(KERN_INFO "--- %s: creation of /proc/deeds_fifo_stats failed!\n", mod_name);
		fifo_destroy(&fifo);
		return -1;
	}
	
	err = create_dev_node();
	if (err)
	{
		printk(KERN_INFO "--- %s: cdev (and node) creation failed!\n", mod_name);	
		proc_remove(proc_stats);
		fifo_destroy(&fifo);
		return err;
	}

	printk(KERN_INFO "--- %s: is being loaded.\n", mod_name);
	return err;
}
Beispiel #2
0
static void file_write_func() {
	int file_fd = 0;
	int file_context = 0;

	int size = 1024;
	char* buffer;

	__malloc_pool = malloc(0x40000);
	init_memory_pool(0x40000, __malloc_pool, 0);

	buffer = malloc(size); 

	__fio = fio_create(__malloc_pool);

	timer_init("Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz");
	event_init();
	file_init();

	for(int i = 0; i < 256; i++) {
		file_context = file_fd = i;
		
		sprintf(buffer, "Write Test %d", file_fd);
		int status = file_read(file_fd, buffer, size, write_callback, &file_context);

		__fio->output_buffer->head = i;
		__fio->output_buffer->tail = i + 1;

		FIORequest* output_buffer = malloc(sizeof(FIORequest));
		output_buffer->type = FILE_T_WRITE;
		output_buffer->context = &file_context;
		output_buffer->fd = file_fd;
		output_buffer->id = (__fio->request_id - 1) % FIO_MAX_REQUEST_ID;

		output_buffer->op.file_io.buffer = buffer;
		output_buffer->op.file_io.size = size;
		
		__fio->output_buffer->array[i] = output_buffer;

		assert_int_equal(status, FIO_OK);

		event_loop();
	}

	fifo_destroy(__fio->input_buffer);
	fifo_destroy(__fio->output_buffer);
	__free(__fio, __malloc_pool);
	
	destroy_memory_pool(__malloc_pool);	
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Beispiel #3
0
// initialize module (executed when using insmod)
static int __init fifo_mod_init(void)
{
	int err;

	// create the procfs entry
	procfs_config = proc_create(
		"fifo_config", 0666, 0, &config_fops);

	// check for null-pointer
	if (0 == procfs_config) 
	{
		printk(KERN_INFO "--- %s: creation of proc/fifo_config failed!\n", mod_name);
		return -1;
	}

	err = fifo_init(&dev, 1024);
	if (err)
	{
		printk(KERN_INFO "--- %s: fifo_init failed!\n", mod_name);	
		proc_remove(procfs_config);
		return err;
	}
	
	err = create_dev_nodes();
	if (err)
	{
		printk(KERN_INFO "--- %s: cdev_node creation failed!\n", mod_name);	
		proc_remove(procfs_config);
		fifo_destroy(&dev);
		return err;
	}

	printk(KERN_INFO "--- %s: is being loaded.\n", mod_name);
	return 0;
}
// -----[ _clear ]---------------------------------------------------
static void _clear(sched_t * self)
{
  sched_static_t * sched= (sched_static_t *) self;
  fifo_destroy(&sched->events);
  sched->events= fifo_create(EVENT_QUEUE_DEPTH, _fifo_event_destroy);
  fifo_set_option(sched->events, FIFO_OPTION_GROW_EXPONENTIAL, 1);
}
Beispiel #5
0
void test_fifo() {
  dna_log(INFO,  "<-------------------- test_fifo ---------------------");
  int j = 0;
  for (j = 0; j < 10; j++) {
    fifo_t *fifo = fifo_create("<test fifo>", 0);
    fifo_destroy(fifo);
  }
}
Beispiel #6
0
extern void test_cubefifo_init_fifo(void)
{
  fifo_t *fifo;

  fifo = init_fifo(5, 0);
  CU_ASSERT(fifo != NULL);
  fifo_destroy(fifo);
}
Beispiel #7
0
extern void test_cubefifo_empty_fifo(void)
{
  fifo_t *fifo;

  fifo = init_fifo(5, 0);
  CU_ASSERT(empty_fifo(fifo) == 0);
  fifo_destroy(fifo);
}
Beispiel #8
0
int main(int argc, char *argv[]) {
  pthread_t tid[3];
  struct xillyfifo fifo;
  unsigned int fifo_size;

  if ((argc != 2) && (argc != 3)) {
    fprintf(stderr, "Usage: %s fifo_size [read-file]\n", argv[0]);
    exit(1);
  }

  fifo_size = atoi(argv[1]);

  if (fifo_size == 0) {
    fprintf(stderr, "Bad fifo_size argument %s\n", argv[1]);
    exit(1);
  }

  if (fifo_init(&fifo, fifo_size)) {
    perror("Failed to init");
    exit(1);
  }

  if (argc > 2) {
    read_fd = open(argv[2], O_RDONLY);

    if (read_fd < 0) {
      perror("Failed to open read file");
      exit(1);
    }
  }

  if (pthread_create(&tid[0], NULL, read_thread, &fifo)) {
    perror("Failed to create thread");
    exit(1);
  }

  if (pthread_create(&tid[1], NULL, write_thread, &fifo)) {
    perror("Failed to create thread");
    exit(1);
  }

  if (pthread_create(&tid[2], NULL, status_thread, &fifo)) {
    perror("Failed to create thread");
    exit(1);
  }

  pthread_join(tid[0], NULL);
  pthread_join(tid[1], NULL);

  fifo.done = 2; // This is a hack for the status thread
  pthread_join(tid[2], NULL);

  fifo_destroy(&fifo);

  pthread_exit(NULL);

  return 0;
}
Beispiel #9
0
static void __exit fifo_mod_cleanup(void)
{
	destroy_dev_node(3);
	proc_remove(proc_stats);

	fifo_destroy(&fifo);

	printk(KERN_INFO "--- %s: is being unloaded.\n", mod_name);
}
Beispiel #10
0
// cleanup module (executed when using rmmod)
static void __exit fifo_cleanup(void)
{
	proc_remove(procfs_config);

	fifo_destroy(&dev);
	destroy_dev_nodes(2,2);

	printk(KERN_INFO "--- %s: is being unloaded.\n", mod_name);
}
Beispiel #11
0
static void file_opendir_func() {
	int file_fd = 0;
	int file_context = 0;

	__malloc_pool = malloc(0x40000);
	init_memory_pool(0x40000, __malloc_pool, 0);

	__fio = fio_create(__malloc_pool);					
	
	timer_init("Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz");
	event_init();
	file_init();

	/* check context & fd unitl get to Max request id */ 
	for(int i = 0; i < 256; i++) {
		file_context = i;
		int status = file_opendir("Test", opendir_callback, &file_context);

		__fio->output_buffer->head = i;
		__fio->output_buffer->tail = i + 1;

		/* FIORequest that put in to output_buffer of __fio */
		FIORequest* output_buffer = malloc(sizeof(FIORequest));
		output_buffer->type = FILE_T_OPENDIR;
		output_buffer->context = &file_context;

		output_buffer->id = (__fio->request_id - 1) % FIO_MAX_REQUEST_ID;
		output_buffer->fd = file_fd = i;

		__fio->output_buffer->array[i] = output_buffer;

		assert_int_equal(FIO_OK, status);

		event_loop();
	}

	fifo_destroy(__fio->input_buffer);
	fifo_destroy(__fio->output_buffer);
	__free(__fio, __malloc_pool);
	
	destroy_memory_pool(__malloc_pool);	
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Beispiel #12
0
static void file_close_func() {
	int file_fd = 0;
	int file_context = 0;

	__malloc_pool = malloc(0x40000);
	init_memory_pool(0x40000, __malloc_pool, 0);

	__fio = fio_create(__malloc_pool);

	timer_init("Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz");
	event_init();
	file_init();
	
	for(int i = 0; i < 256; i++) {
		file_context = file_fd = i;

		int status = file_close(file_fd, close_callback, &file_context);

		__fio->output_buffer->head = i;
		__fio->output_buffer->tail = i + 1;

		FIORequest* output_buffer = malloc(sizeof(FIORequest));
		output_buffer->type = FILE_T_CLOSE;
		output_buffer->context = &file_context;
		output_buffer->id = (__fio->request_id - 1) % FIO_MAX_REQUEST_ID;
		output_buffer->fd = file_fd;

		__fio->output_buffer->array[i] = output_buffer;

		assert_int_equal(status, FIO_OK);

		event_loop();
	}	

	fifo_destroy(__fio->input_buffer);
	fifo_destroy(__fio->output_buffer);
	__free(__fio, __malloc_pool);
	
	destroy_memory_pool(__malloc_pool);	
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Beispiel #13
0
void function_one (Node * nn) {
  Fifo * fifo = fifo_create ();
  while (NULL != nn) {
    printf ("%c", nn->data);
    for (nn = nn->cld; NULL != nn; nn = nn->sbl) {
      fifo_append (fifo, nn);
    }
    nn = fifo_extract (fifo);
  }
  fifo_destroy (fifo);
}
Beispiel #14
0
void testcase_destroy(testcase t) {
	int i;
	for(i=0; i<t->num_vertices; i++) {
		fifo_destroy(t->adjacencies[i]);
	}
	free(t->adjacencies);
	free(t->pair_g1);
	free(t->pair_g2);
	free(t->dist);
	free(t);
}
Beispiel #15
0
void thread_pool_destroy( thread_pool_t *pool ) {
  dna_log(DEBUG, "Inside thread_pool_destroy()");
  if ( pool ) {
    dna_log(DEBUG, "Telling threads to exit...");
    thread_pool_join_all(pool);
    dna_log(DEBUG, "Destroying execution context fifo...");
    fifo_destroy( pool->thread_queue );
    pool->thread_queue = NULL;
    dna_log(DEBUG, "Destroying tasks in fifo...");
    while ( !fifo_is_empty( pool->tasks ) ) {
      task_t *task = (task_t*) fifo_pop( pool->tasks );
      task_destroy( task );
    }
    fifo_destroy( pool->tasks );
    pool->tasks = NULL;
    dna_log(DEBUG, "Freeing thread context pool \"%s\".", pool->name);
    dna_mutex_destroy( pool->mutex );
    dna_cond_destroy( pool->wait );
    free(pool->mutex);
    free(pool->wait);
    free( pool );
  }
}
Beispiel #16
0
bool hopcroft_karp_bfs(testcase t) {
	fifo q = fifo_create();
	fifo_item item;
	int v, u;

	/* for each v in G1 */
	for(v=1; v<t->num_students+1; v++) {
		/* if Pair_G1[v] == NIL */
		if(t->pair_g1[v] == NIL) {
			/* Dist[v] = 0 */
			t->dist[v] = 0;
			/* Enqueue(Q, v) */
			fifo_queue(q, v);
		}
		/* else */
		else {
			/* Dist[v] = INFINITE */
			t->dist[v] = INFINITE;
		}
	}

	/* Dist[NIL] = INFINITE */
	t->dist[NIL] = INFINITE;

	/* while Empty(Q) == false */
	while(q->size != 0) {
		/* v = Dequeue(Q) */
		v = fifo_dequeue(q);
		/* if Dist[v] < Dist[NIL] */
		if(t->dist[v] < t->dist[NIL]) {
			/* for each u in Adv[v] */
			for(item = t->adjacencies[v]->first; item != NULL; item = item->next) {
				u = item->value;
				/* if Dist[ Pair_G2[u] ] == INFINITE */
				if(t->dist[t->pair_g2[u]] == INFINITE) {
					/* Dist{ Pair_G2[u] ] = Dist[v] + 1 */
					t->dist[t->pair_g2[u]] = t->dist[v] + 1;
					/* Enqueue(Q, Pair_G2[u]) */
					fifo_queue(q, t->pair_g2[u]);
				}
			}
		}
	}

	/* return Dist[NIL] != INFINITE */
	fifo_destroy(q);
	return (t->dist[NIL] != INFINITE);
}
Beispiel #17
0
void test_empty_thread_pool() {
  dna_log(INFO,  "<-------------------- test_empty_thread_pool ---------------------");
  int i = 0;
  for (i = 0; i < 10 ; i++ ) {
    dna_log(INFO, ">> --- cycle %i --- <<", i+1);
    // global here, for all threads to share
    fifo = fifo_create("values", 0);
    dna_log(DEBUG, "starting thread pool");
    thread_pool_t *pool = thread_pool_create("main pool", 1);
    dna_log(DEBUG, "destroying thread pool");
    thread_pool_exit_all(pool);
    thread_pool_destroy(pool);
    fifo_check();
    fifo_destroy(fifo);
  }
}
Beispiel #18
0
void sleep_for( long seconds ) {
  dna_log(DEBUG, "Sleeping for %lu", seconds);
  struct timespec interval = {
      .tv_sec = (time_t) seconds,
      .tv_nsec = 0
  };
  nanosleep(&interval, NULL);
}

void test_empty_fifo() {
  dna_log(INFO,  "<-------------------- test_empty_fifo ---------------------");
  int j = 0;
  for (j = 0; j < 10; j++) {
    fifo_t *fifo = fifo_create(" <test fifo>", 0);
    fifo_destroy(fifo);
  }
}
Beispiel #19
0
void test_busy_thread_pool() {
  dna_log(INFO,  "<-------------------- test_busy_thread_pool  ---------------------");
  fifo = fifo_create("<(busy_thread_pool) value fifo>", 0);
  thread_pool_t *pool = thread_pool_create("<busy thread pool>", 8); // should auto-determine thread count maybe?
  dna_log(DEBUG, "adding %i tasks to the queue...", ELEMS);
  int i = 0;
  for( i = 0; i < ELEMS; i++ ) {
    thread_pool_enqueue(pool, &fifo_fill, NULL);
  }
  dna_log(DEBUG, "waiting for threads to complete on their own...");
  thread_pool_exit_all(pool);
  thread_pool_join_all( pool );
  dna_log(DEBUG, "destroying thread pool...");
  thread_pool_destroy( pool );
  fifo_check();
  dna_log(DEBUG, "destroying global value fifo.");
  fifo_destroy( fifo );
}
Beispiel #20
0
// -----[ _destroy ]-------------------------------------------------
static void _destroy(sched_t ** sched_ref)
{
  sched_static_t * sched;
  if (*sched_ref != NULL) {

    sched= (sched_static_t *) *sched_ref;

    // Free private part
    if (sched->events->current_depth > 0)
      cbgp_warn("%d event%s still in simulation queue.\n",
		sched->events->current_depth,
		(sched->events->current_depth>1?"s":""));
    fifo_destroy(&sched->events);
    if (sched->pProgressLogStream != NULL)
      stream_destroy(&sched->pProgressLogStream);

    FREE(sched);
    *sched_ref= NULL;
  }
}
Beispiel #21
0
int main (int argc, char *argv[])
{
	struct arg_t *kom_arg, arg;
	pid_t child_pid;
	int fifofd1;

	/* Setup a signal handler for SIGINT */
	signal(SIGINT, int_proc);
	signal(SIGTERM, int_proc);

	kom_arg = &arg;
	Cmdline (kom_arg, argc, argv);

	if (kom_arg->v)
	{
		printf ("%s: version %s\n", argv[0], PACKAGE_VERSION);
		return EXIT_FAILURE;
	}

	verbose = kom_arg->V; 

	if (verbose) printf ("start\n");

	fifofd1 = fifo_create (FILENAME, 4096, 0);

	child_pid = fork ();
	if (child_pid == 0) child_process ();

	while (!stop)
	{
		fifo_write (fifofd1, "Hallo", 5);
		printf ("write\n");
		sleep (1);
	}

	fifo_destroy (fifofd1);

	if (verbose) printf ("done\n");

	return EXIT_SUCCESS;
}
Beispiel #22
0
void degenerator_compute (Degenerator_t * degenerator){
	int cur_iter;
	

	pDEBUG("Iterating %d times\n", degenerator->_iterations);
	for (cur_iter = 0; cur_iter < degenerator->_iterations; cur_iter++){
		if ((cur_iter % degenerator->_iterations_offset) == 0){
			// faire des calculs (nombre de composantes connexes)
			store_reset (degenerator->_store, STORE_RESET_ALL ^ STORE_RESET_DEGREE);

			Fifo_t * fifo_idx = fifo_create(degenerator->_size);
			store_connexity (degenerator->_store, fifo_idx);

			fprintf(degenerator->_io->output, "%d %ld\n", cur_iter, fifo_get_size (fifo_idx));
			fifo_destroy(fifo_idx);
			// afficher la courbe...
		}
		// Choisir un noeud selon une certaine méthode...
		nodeindex_t selected_node = (degenerator_select_mode_table[degenerator->_select_mode])(degenerator);
		printf("Node %ld\n", selected_node);

		store_del_node(degenerator->_store, selected_node);
	}
}
Beispiel #23
0
void neighbour_list_scan_neighbours(struct sr_instance * sr, struct neighbour_list * nl)
{
    struct fifo * delete_list = fifo_create();
    struct neighbour * n;
    int flood = 0;
    mutex_lock(nl->mutex);
    assoc_array_walk_array(nl->array,neighbour_list_scan_neighbour,delete_list);

    while((n = fifo_pop(delete_list)))
    {
        flood = 1;
        assoc_array_delete(nl->array,&n->router_id);
    }

    fifo_destroy(delete_list);
    
    if(flood)
    {
        link_state_graph_update_forwarding_table(sr);
        interface_list_send_flood(sr);
    }
    mutex_unlock(nl->mutex);
    router_notify(sr,flood ? ROUTER_UPDATE_OSPF : ROUTER_UPDATE_OSPF_TTL);
}
Beispiel #24
0
int __cdecl main(int argc, char *argv[]) {
#define N_FRAME 100
#define N_PATCH 600000//(1<<LFSR_SIZE)
  const char* readfn = "\\\\.\\xillybus_rd"
	  , * writefn = "\\\\.\\xillybus_wr";
  HANDLE tid[2];
  struct xillyfifo fifo;
  unsigned int fifo_size = 4096*16;
  int write_fd, bTalk2FPGA = (int)(argc < 2);
  unsigned int n_frame = 0;
  unsigned int msg, n_msg;
  int rd;
  FILE* pixel_coeff_f = fopen("reducer_coeff_0.bin", "rb")
    , *ds_coeff_f = fopen("ds_0.bin", "rb");
  if(!pixel_coeff_f) {
    perror("Failed to open reducer_coeff");
    exit(errno);
  }
  if(!ds_coeff_f) {
    perror("Failed to open ds_coeff");
    exit(errno);
  }

  if(bTalk2FPGA) {
    //printf("Press any key to connect to FPGA\n"); getchar();
    write_fd = _open(writefn, O_WRONLY | _O_BINARY);
    if (write_fd < 0) {
      if (errno == ENODEV)
        fprintf(stderr, "(Maybe %s a write-only file?)\n", writefn);

      fprintf(stderr, "Failed to open %s", writefn);
      exit(1);
    }

    // If more than one FIFO is created, use the total memory needed instead
    // of fifo_size with SetProcessWorkingSetSize()
    if(fifo_size > 20000
      && !SetProcessWorkingSetSize(GetCurrentProcess()
            , 1024*1024 + fifo_size, 2048*1024 + fifo_size))
      errorprint("Failed to enlarge unswappable RAM limit", GetLastError());

    if (fifo_init(&fifo, fifo_size)) {
      perror("Failed to init");
      exit(1);
    }

    read_fd = _open(readfn, O_RDONLY | _O_BINARY);
    if (read_fd < 0) {
      perror("Failed to open read file");
      exit(1);
    }

    if (_setmode(1, _O_BINARY) < 0)
      fprintf(stderr, "Failed to set binary mode for standard output\n");

    // default security, default stack size, default startup flags
    tid[0] = CreateThread(NULL, 0, read_thread, &fifo, 0, NULL);
    if (tid[0] == NULL) {
      errorprint("Failed to create read thread", GetLastError());
      exit(1);
    }
    tid[1] = CreateThread(NULL, 0, report_thread, &fifo, 0, NULL);
    if (tid[1] == NULL) {
      errorprint("Failed to create report thread", GetLastError());
      exit(1);
    }
  }//end if(bTalk2FPGA)

  for(n_msg = 0; !feof(pixel_coeff_f); ) {
    rd = fread(&msg, sizeof(msg), 1, pixel_coeff_f);
    if(bTalk2FPGA) allwrite(write_fd, (unsigned char*)&msg, sizeof(msg));
    printf("weights 0x%08X\n", msg);
  } //end for

  for(; !feof(ds_coeff_f); ) {
    rd = fread(&msg, sizeof(msg), 1, ds_coeff_f);
    printf("DS 0x%08X\n", msg);
    if(bTalk2FPGA) allwrite(write_fd, (unsigned char*)&msg, sizeof(msg));
  } //end for

cleanup:
  if(bTalk2FPGA) {
    unsigned int msg = ~0;//Make the FPGA close the rd file
    allwrite(write_fd, (unsigned char*)&msg, sizeof(msg));
    _close(write_fd);
    _close(read_fd);

    // Wait for threads to exit
    if (WaitForSingleObject(tid[0], INFINITE) != WAIT_OBJECT_0) 
      errorprint("Failed waiting for read_thread to terminate"
        , GetLastError());
    fifo_destroy(&fifo);
  }
  fclose(ds_coeff_f);
  fclose(pixel_coeff_f);
  printf("Press any key to exit\n"); getchar();
  return 0;
}
Beispiel #25
0
cmm_error_t
cnt_init(char         *filename,
         cmm_nodeid_t local_node_id)
{
    int filefd;
    fifo_t *elems;
    cnt_entry_t *entry;
    cmm_error_t err = CMM_OK;

    if ( pthread_mutex_init( &cnt_mutex, NULL ) ) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
		 "pthread_mutex_init failed" );
        return(CMM_EOTHER);
    }

    filefd = open( filename, O_RDONLY );
    if (filefd == -1) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
		 "Failed to open file %s in O_RDONLY mode",
		 filename );
        return( CMM_EINVAL );
    }

    elems = fifo_init(NULL);
    if (!elems) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
		 "fifo_init failed" );
        close(filefd);
        return( CMM_ENOMEM );
    }

    while ((entry = readEntry(filefd))) {
        err = fifo_add_elem( elems,
                             entry );
        if (err != CMM_OK) {
            cm_trace(CM_TRACE_LEVEL_ERROR, 
		     "fifo_add_elem failed [%d]",
		     err );
            break;
        }
    }

    if (err == CMM_OK) {
        err = cnt_create_table( local_node_id,
                                elems );
        if (err != CMM_OK) {
            cm_trace(CM_TRACE_LEVEL_ERROR, 
		     "cnt_create_table failed [%d]",
		     err );
        }
    }

    if (err == CMM_OK) {
        err = cnt_update_dns();
        if (err != CMM_OK) {
            cm_trace(CM_TRACE_LEVEL_ERROR, 
		     "cnt_update_dns failed [%d]",
		     err );
        }
    }

    if (err != CMM_OK) {
        while ((entry = fifo_extract_elem(elems))) {
            free(entry);
        }
    }

    fifo_destroy(elems);
    elems = NULL;

    if (err == CMM_OK) {
	cm_trace(CM_TRACE_LEVEL_DEBUG,
		 "The CNT initialized properly" );
    }

    return(err);
}
Beispiel #26
0
Datei: main.c Projekt: hsgg/quark
int
main (int argc, char **argv)
{
#ifdef USE_GCONF
    GConfClient *gconf;
#endif

    char *dir;
    struct sigaction action;
    sigset_t sigset;

    main_status = QUARK_STARTING;

    /* initialize the locale */
    if (!setlocale(LC_ALL, ""))
	g_warning("Couldn't set locale from environment.\n");
    bindtextdomain(PACKAGE_NAME, LOCALEDIR);
    bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
    textdomain(PACKAGE_NAME);

    /* set up signal handler */
    sigemptyset (&sigset);
    action.sa_handler = signal_handler;
    action.sa_mask = sigset;
    action.sa_flags = SA_NOCLDSTOP;
    sigaction (SIGTERM, &action, (struct sigaction *) NULL);
    sigaction (SIGINT, &action, (struct sigaction *) NULL);
    sigaction (SIGHUP, &action, (struct sigaction *) NULL);

    g_type_init ();
    gnome_vfs_init ();

#ifdef USE_GCONF
    gconf = gconf_client_get_default ();
    gconf_client_add_dir (gconf, QUARK_GCONF_ROOT,
                          GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
    gconf_client_notify_add (gconf, QUARK_GCONF_ROOT, config_changed, NULL,
                             NULL, NULL);
#endif

    /* make the directory we use in ~ */
    dir = g_build_filename (g_get_home_dir(), ".quark", NULL);
    mkdir (dir, S_IRWXU|S_IRWXG|S_IRWXO);
    g_free (dir);

    loop = g_main_loop_new (NULL, FALSE);

    if (!fifo_open ()) {
        g_critical("failed to open fifo");
        return 1;
    }

    music_init ();

    g_static_mutex_lock (&main_mutex);
    playlist_init ();
#ifdef USE_GCONF
    config_load (gconf);
#endif
    main_status = QUARK_RUNNING;
    g_static_mutex_unlock (&main_mutex);

    g_main_loop_run (loop);

    g_static_mutex_lock (&main_mutex);
    main_status = QUARK_EXITING;
#ifdef USE_GCONF
    config_save (gconf);
#endif
    playlist_destroy ();
    g_static_mutex_unlock (&main_mutex);

    music_destroy ();

    fifo_destroy ();
    g_main_loop_unref (loop);
#ifdef USE_GCONF
    g_object_unref (G_OBJECT (gconf));
#endif

    gnome_vfs_shutdown ();

    return 0;
}
int main(int argc, char *argv[]) {
    enum                    { MAX_RETRIES = 100 };
    enum                    { SLEEP_US    = 1000 };
    bool                      attach = false;
    _xcc_status               cc;
    bool                      client = false;
    int                       count;
    int                       count_read;
    int                       count_written;
    bool                      dif = false;
    double                    dloop;
    double                    dms;
    double                    dsec;
    int                       err;
    bool                      exec = false;
    int                       ferr;
    bool                      fin = false;
    MS_Mon_Process_Info_Type  info;
    MS_Mon_Process_Info_Type *infop;
    int                       inx;
    int                       inx2;
    int                       inx3;
    short                     len;
    short                     lerr;
    short                     lerr2;
    int                       loop = 10;
    int                       max;
    int                       nid;
    pid_t                     pid;
    int                       sargc;
    ssize_t                   size;
    int                       snid;
    int                       spid;
    bool                      startup = false;
    xzsys_ddl_smsg_def       *sys_msgp = (xzsys_ddl_smsg_def *) recv_buffer;
    int                       sys_msg;
    int                       sys_msg_count;
    bool                      verbose = false;
    TAD                       zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-dif",       TA_Bool, TA_NOMAX,    &dif       },
      { "-exec",      TA_Bool, TA_NOMAX,    &exec      },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxsp",     TA_Int,  TA_NOMAX,    &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-startup",   TA_Bool, TA_NOMAX,    &startup   },
      { "-trace",     TA_Bool, TA_NOMAX,    &trace     },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "-verbose",   TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    sprintf(fifo1, "%s-%s", FIFO1, getenv("USER"));
    sprintf(fifo2, "%s-%s", FIFO2, getenv("USER"));
    if (trace)
        msg_init_trace();
    if (exec)
        return 0;
    if (startup) {
        err = fifo_open(fifo1, O_WRONLY);
        assert(err != -1);
        ffds[1] = err;
        err = fifo_open(fifo2, O_RDONLY);
        assert(err != -1);
        ffds[0] = err;
        if (trace)
            trace_printf("cli: writing fifo\n");
        size = write(ffds[1], recv_buffer, 1);
        if (trace)
            trace_printf("cli: fifo write, size=%d\n", (int) size);
        assert(size == 1);
        if (trace)
            trace_printf("cli: fifo written\n");
        close(ffds[1]);
        return 0;
    }
    if (attach)
        ferr = file_init_attach(&argc, &argv, false, NULL);
    else
        ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    util_test_start(client);
    ferr = msg_mon_process_startup(true); // system messages
    util_check("msg_mon_process_startup", ferr);
    ferr = msg_mon_get_my_process_name(procname, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);
    ferr = msg_mon_get_process_info(procname, &nid, &pid);
    TEST_CHK_FEOK(ferr);

    if (trace)
        trace_printf("proc=%s, nid=%d, pid=%d\n", procname, nid, pid);
    dloop = (double) loop;
    for (inx = 0; inx < T_MAX; inx++)
        t_elapsed[inx] = 0.0;
    if (client) {
        printf("loop=%d, maxsp=%d\n", loop, maxsp);
        sargc = argc;
        assert(sargc < MAX_ARGS);
        for (inx2 = 0; inx2 < argc; inx2++) {
            if (strcmp(argv[inx2], "-client") == 0)
                sargv[inx2] = (char *) "-server";
            else
                sargv[inx2] = argv[inx2];
            if (strcmp(argv[inx2], "-attach") == 0)
                sargv[inx2] = (char *) "-server";
        }
        sargv[argc] = NULL;
        sprintf(sprog, "%s/%s", getenv("PWD"), argv[0]);
        time_start(T_TOTAL);
        for (inx = 0; inx < loop; inx += maxsp) {
            if (dif)
                snid = -1;
            else
                snid = nid;
            max = loop - inx;
            if (max > maxsp)
                max = maxsp;
            for (inx2 = 0; inx2 < max; inx2++)
                sname[inx2][0] = 0; // mon picks name
            if (trace)
                trace_printf("cli: newproc, inx=%d\n", inx);
            time_start(T_NEWPROC);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_start_process(sprog,                  // prog
                                             sname[inx2],            // name
                                             sname[inx2],            // ret_name
                                             sargc,                  // argc
                                             sargv,                  // argv
                                             TPT_REF2(sphandle,inx2),// phandle
                                             false,                  // open
                                             &soid[inx2],            // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             false,                  // debug
                                             false,                  // backup
                                             &snid,                  // nid
                                             &spid,                  // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_NEWPROC);
            time_elapsed(T_NEWPROC);

            // wait here until processes are 'up'
            // so that open timing is correct
            inx3 = 0;
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_get_process_info_detail(sname[inx2], &info);
                TEST_CHK_FEOK(ferr);
                if (info.state != MS_Mon_State_Up) {
                    inx3++;
                    if (inx3 > MAX_RETRIES) {
                        printf("process %s did not enter 'UP' state\n", sname[inx2]);
                        assert(inx3 < MAX_RETRIES);
                    }
                    usleep(SLEEP_US);
                    inx2--;
                    continue;
                } else
                    inx3 = 0;
            }

            if (trace)
                trace_printf("cli: open, inx=%d\n", inx);
            time_start(T_OPEN);
            for (inx2 = 0; inx2 < max; inx2++) {
                if (trace)
                    trace_printf("cli: opening inx=%d, name=%s\n", inx, sname[inx2]);
                len = (short) strlen(sname[inx2]);
                ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2],
                                   0, 0, 0,
                                   0, 0, 0, 0);
                if (trace)
                    trace_printf("cli: open, inx=%d, name=%s, ferr=%d\n",
                           inx, sname[inx2], ferr);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_OPEN);
            time_elapsed(T_OPEN);

            if (trace)
                trace_printf("cli: procinfo, inx=%d\n", inx);
            time_start(T_PROCINFO);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_get_process_info_detail(sname[inx2], &info);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_PROCINFO);
            time_elapsed(T_PROCINFO);

            if (trace)
                trace_printf("cli: procinfo-type, inx=%d\n", inx);
            time_start(T_PROCINFO_TYPE);
            ferr = msg_mon_get_process_info_type(MS_ProcessType_Generic,
                                                 &count,
                                                 MAX_SRV,
                                                 infotype);
            TEST_CHK_FEOK(ferr);
            time_stop(T_PROCINFO_TYPE);
            time_elapsed(T_PROCINFO_TYPE);
            if (verbose) {
                for (inx2 = 0; inx2 < count; inx2++) {
                    infop = &infotype[inx2];
                    char s_em = infop->event_messages ? 'E' : '-';
                    char s_sm = infop->system_messages ? 'S' : '-';
                    char s_pr = infop->pending_replication ? 'R' : '-';
                    char s_pd = infop->pending_delete ? 'D' : '-';
                    char s_s  = infop->state == MS_Mon_State_Up ? 'A' : 'U';
                    char s_o  = infop->opened ? 'O' : '-';
                    char s_p  = infop->paired ? 'P' : infop->backup ? 'B' : '-';
                    printf("%3.3d,%8.8d %3.3d %d %c%c%c%c%c%c%c %-11s %-11s %-15s\n",
                           infop->nid,
                           infop->pid,
                           infop->priority,
                           infop->state,
                           s_em, s_sm, s_pr, s_pd, s_s, s_o, s_p,
                           infop->process_name,
                           infop->parent_name,
                           infop->program);
                }
            }

            if (trace)
                trace_printf("cli: close, inx=%d\n", inx);
            time_start(T_CLOSE);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = BFILE_CLOSE_(sfilenum[inx2]);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_CLOSE);
            time_elapsed(T_CLOSE);

            // re-open/close
            for (inx2 = 0; inx2 < max; inx2++) {
                if (trace)
                    trace_printf("cli: re-opening inx=%d, name=%s\n",
                           inx, sname[inx2]);
                len = (short) strlen(sname[inx2]);
                ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2],
                                   0, 0, 0,
                                   0, 0, 0, 0);
                TEST_CHK_FEOK(ferr);
            }
            if (trace)
                trace_printf("cli: re-close, inx=%d\n", inx);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = BFILE_CLOSE_(sfilenum[inx2]);
                TEST_CHK_FEOK(ferr);
            }

            if (trace)
                trace_printf("cli: newproc-forkexec, inx=%d\n", inx);
            sargc = 2;
            sargv[0] = argv[0];
            sargv[1] = (char *) "-exec";
            if (trace)
                sargv[sargc++] = (char *) "-trace";
            sargv[sargc] = NULL;
            time_start(T_FORKEXEC);
            for (inx2 = 0; inx2 < max; inx2++) {
                pid = fork();
                assert(pid >= 0);
                if (pid == 0) {
                    // child
                    err = execv(sprog, sargv);
                    assert(err == 0);
                }
            }
            time_stop(T_FORKEXEC);
            time_elapsed(T_FORKEXEC);

            if (trace)
                trace_printf("cli: newproc-forkexec-su, inx=%d\n", inx);
            sargc = 2;
            sargv[0] = argv[0];
            sargv[1] = (char *) "-startup";
            if (trace)
                sargv[sargc++] = (char *) "-trace";
            sargv[sargc] = NULL;
            time_start(T_FORKEXEC_SU);
            for (inx2 = 0; inx2 < max; inx2++) {
                fifo_create(fifo1, fifo2);
                pid = fork();
                assert(pid >= 0);
                if (pid > 0) {
                    // parent
                    err = fifo_open(fifo1, O_RDONLY);
                    assert(err != -1);
                    ffds[0] = err;
                    err = fifo_open(fifo2, O_WRONLY);
                    assert(err != -1);
                    ffds[1] = err;
                    if (trace)
                        trace_printf("cli: reading fifo, inx=%d\n", inx2);
                    size = ::read(ffds[0], recv_buffer, 1);
                    if (trace)
                        trace_printf("cli: fifo read, size=%d\n", (int) size);
                    assert(size == 1);
                    if (trace)
                        trace_printf("cli: fifo read, inx=%d\n", inx2);
                    ::read(ffds[0], recv_buffer, 1);
                    err = fifo_close(ffds[0]);
                    assert(err == 0);
                    err = fifo_close(ffds[1]);
                    assert(err == 0);
                    fifo_destroy(fifo1, fifo1);
                } else {
                    // child
                    err = execv(sprog, sargv);
                    assert(err == 0);
                }
            }
            fifo_destroy(fifo2, fifo2);
            time_stop(T_FORKEXEC_SU);
            time_elapsed(T_FORKEXEC_SU);
        }
    } else {
        sys_msg_count = 0;
        time_start(T_TOTAL);
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0); // sys msgs
        TEST_CHK_FEOK(ferr);
        for (inx = 0; !fin; inx++) {
            if (trace)
                trace_printf("srv: readupdate, inx=%d\n", inx);
            cc = BREADUPDATEX(filenumr,
                              recv_buffer,
                              4,
                              &count_read,
                              0);
            sys_msg = _xstatus_ne(cc);
            if (trace && sys_msg)
                trace_printf("srv: rcvd sys msg=%d\n",
                             sys_msgp->u_z_msg.z_msgnumber[0]);
            if (sys_msg) {
                sys_msg_count++;
                inx--;
            }
            lerr2 = BFILE_GETINFO_(filenumr, &lerr);
            TEST_CHK_FEIGNORE(lerr2);
            if (trace)
                trace_printf("srv: reply, inx=%d\n", inx);
            cc = BREPLYX(recv_buffer,
                         (unsigned short) 0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            if (sys_msg_count >= 4)
                fin = true;
        }
    }
    time_stop(T_TOTAL);
    time_elapsed(T_TOTAL);

    if (client) {
        dsec = time_sec(T_TOTAL);
        dms = dsec * 1000.0;
        printf("elapsed=%f\n", dms);
        printf("open/close/newprocess/processinfo/forkexec=%d\n", loop);
        dsec = time_sec(T_OPEN);
        dms = dsec * 1000.0;
        printf("open            : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_CLOSE);
        dms = dsec * 1000.0;
        printf("close           : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_PROCINFO);
        dms = dsec * 1000.0;
        printf("procinfo        : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_PROCINFO_TYPE);
        dms = dsec * 1000.0;
        printf("procinfo-type   : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_NEWPROC);
        dms = dsec * 1000.0;
        printf("newproc         : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_FORKEXEC);
        dms = dsec * 1000.0;
        printf("forkexec        : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_FORKEXEC_SU);
        dms = dsec * 1000.0;
        printf("forkexec-startup: total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #28
0
extern int opnorm(const double *M, majority_t maj,
		  size_t m, size_t n,
		  double p, double q,
		  opnorm_opt_t opt,
		  double *norm,
		  double *vmax,
		  opnorm_stats_t *pstats)
{
  if ( (p <= 1.0) || (isinf(p) == 1) )
    {
      errno = EDOM;
      return OPNORM_EDOM_P;
    }

  if ( q < 1.0 )
    {
      errno = EDOM;
      return OPNORM_EDOM_Q;
    }

  if ( opt.eps <= 0.0 )
    {
      errno = EDOM;
      return OPNORM_EDOM_EPS;
    }

  if ( opt.eps <= DBL_EPSILON )
    {
      return OPNORM_INACC;
    }

  /* prepare shared thread data */

  tdat_shared_t ts =
    {
      .n = n,
      .m = m,
      .p = p,
      .q = q,
      .M = M,
      .eps = opt.eps,
      .tmax = 0,
      .vmax = vmax
    };

  /*
    mutexes - we maintain seperate mutexes for the
    fifo (queue and dequeue) and for the tmax variable,
    since the latter has a much higher access cadence
  */

  if (pthread_mutex_init(&(ts.fifolock), NULL) < 0)
    return OPNORM_FIFO;

  if (pthread_mutex_init(&(ts.maxlock), NULL) < 0)
    return OPNORM_FIFO;

  /*
    choose matrix-vector multiply function depending
    on the specified matrix majority (matvec.c)
  */

  switch (maj)
    {
    case row_major:
      ts.matvec = matvec_row_major;
      break;
    case column_major:
      ts.matvec = matvec_column_major;
      break;
    default:
      return OPNORM_BUG;
    }

  /* initialise the cube queue */

  if ( !(ts.fifo = init_fifo(n, opt.fifomax)) )
    return OPNORM_FIFO;

  /* Lipschitz constant for the radial projection */

  if (lcrp(p, &(ts.LCRP)) != 0)
    return OPNORM_BUG;

  /*
    surface cube diameter - the diameter of a (n-1)-cube
    of side one measured with the lp norm
  */

  ts.SCD = pow(n-1, 1/p);

  /* get number of threads */

  int nt = 1;

#if (defined HAVE_SYSCONF) && (defined _SC_NPROCESSORS_ONLN)

  nt = sysconf(_SC_NPROCESSORS_ONLN);

#endif

  char *ntenv = getenv("OPNORM_NTHREAD");

  if (ntenv)
    nt = atoi(ntenv);

  if (nt < 1)
    return OPNORM_THREAD;

  if (nt > MAX_THREADS)
    nt = MAX_THREADS;

  /*
    set up per-thread data - the status is set to
    OPNORM_USER since this field is assigned (to
    something else) before the worker threads exit
    normally. Having this as the default value means
    that those threads don't need to assign this
    field in response to a pthread_cancel() (which
    would require adding cleanup functions)
  */

  tdat_t td[nt];

  for (int i = 0 ; i < nt ; i++)
    {
      td[i].nfifo  = 0;
      td[i].neval  = 0;
      td[i].status = OPNORM_USER;
      td[i].shared = &ts;
    }

#ifdef HAVE_SIGNAL_H

  /* setup the signal handling thread */

  sigset_t sigset;

  sigemptyset(&sigset);
  sigaddset(&sigset, SIGQUIT);
  sigaddset(&sigset, SIGINT);
  sigaddset(&sigset, SIGUSR1);

  if (pthread_sigmask(SIG_BLOCK, &sigset, NULL) < 0)
    return OPNORM_THREAD;

#endif

  /* run worker threads */

  pthread_t thread[nt];

  for (int i = 0 ; i < nt ; i++)
    {
      if (pthread_create(thread + i,
			 NULL,
			 (void* (*)(void*))worker,
			 td + i) < 0)
	return OPNORM_THREAD;
    }

#ifdef HAVE_SIGNAL_H

  /* run signal handling thread */

  stdat_t stdat =
    {
      .n = nt,
      .thread = thread,
      .sigset = &sigset
    };

  pthread_t sigth;

  if (pthread_create(&sigth,
		     NULL,
		     (void* (*)(void*)) sigthread,
		     (void*) &stdat) < 0)
    return OPNORM_THREAD;

#endif

  /* join worker threads */

  for (int i = 0 ; i < nt ; i++)
    {
      if (pthread_join(thread[i], NULL) < 0)
	return OPNORM_THREAD;
    }

#ifdef HAVE_SIGNAL_H

  /* cancel and join the signal thread */

  if (pthread_cancel(sigth) < 0)
    return OPNORM_THREAD;

  if (pthread_join(sigth, NULL) < 0)
    return OPNORM_THREAD;

#endif

  /* harvest statistics */

  opnorm_stats_t stats =
    {
      .neval   = 0,
      .nfifo   = 0,
      .fifomax = 0,
      .nthread = nt
    };

  for (int i = 0 ; i < nt ; i++)
    {
      stats.nfifo += td[i].nfifo;
      stats.neval += td[i].neval;
    }

  stats.fifomax = fifo_peak(ts.fifo);

  /* clean up fifo */

  if (empty_fifo(ts.fifo) != 0)
    return OPNORM_FIFO;

  fifo_destroy(ts.fifo);

  /* clean up mutexes */

  if (pthread_mutex_destroy(&(ts.fifolock)) < 0)
    return OPNORM_THREAD;

  if (pthread_mutex_destroy(&(ts.maxlock)) < 0)
    return OPNORM_THREAD;

  /*
    harvest return values - the first that we find that
    is not OPNORM_OK we return
  */

  for (int i = 0 ; i < nt ; i++)
    {
      if ( td[i].status != OPNORM_OK )
	return td[i].status;
    }

  /* assign results */

  if (norm) *norm = ts.tmax;
  if (pstats) *pstats = stats;

  return OPNORM_OK;
}

/* error messages for opnorm() return values */

extern const char* opnorm_strerror(int err)
{
  return status_string(err);
}
Beispiel #29
0
int main(int argc, char *argv[])
{
    PaStreamParameters  inputParameters, outputParameters;
    PaStream*           stream;
    PaError             err = paNoError;
    paTestData          data;
    int                 i;

    /* init callback data */

    for(i=0; i<MEM8; i++)
	data.in8k[i] = 0.0;
    for(i=0; i<FDMDV_OS_TAPS; i++)
	data.in48k[i] = 0.0;

    data.infifo = fifo_create(2*N48);
    data.outfifo = fifo_create(2*N48);

    /* init port audio */

    err = Pa_Initialize();
    if( err != paNoError ) goto done;

    inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */
    if (inputParameters.device == paNoDevice) {
        fprintf(stderr,"Error: No default input device.\n");
        goto done;
    }
    inputParameters.channelCount = NUM_CHANNELS;         /* stereo input */
    inputParameters.sampleFormat = paInt16;
    inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
    inputParameters.hostApiSpecificStreamInfo = NULL;

    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
    if (outputParameters.device == paNoDevice) {
        fprintf(stderr,"Error: No default output device.\n");
        goto done;
    }
    outputParameters.channelCount = NUM_CHANNELS;         /* stereo output */
    outputParameters.sampleFormat = paInt16;
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
    outputParameters.hostApiSpecificStreamInfo = NULL;

    /* Play some audio --------------------------------------------- */

    err = Pa_OpenStream(
              &stream,
	      &inputParameters,
              &outputParameters,
              SAMPLE_RATE,
              512,
              paClipOff,      
              callback,
              &data );
    if( err != paNoError ) goto done;

    err = Pa_StartStream( stream );
    if( err != paNoError ) goto done;

    while( ( err = Pa_IsStreamActive( stream ) ) == 1 )
    {
        Pa_Sleep(100);
    }
    if( err < 0 ) goto done;

    err = Pa_CloseStream( stream );
    if( err != paNoError ) goto done;


done:
    Pa_Terminate();
    if( err != paNoError )
    {
        fprintf( stderr, "An error occured while using the portaudio stream\n" );
        fprintf( stderr, "Error number: %d\n", err );
        fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
        err = 1;          /* Always return 0 or 1, but no other return codes. */
    }

    fifo_destroy(data.infifo);
    fifo_destroy(data.outfifo);

    return err;
}
static void do_report() {
	union {
		void *ptr;
		ip_report_t *r;
	} r_u;
	struct in_addr ia;

	fifo_order(rfifo, &compare_ip_report_port, 1); /* JZ */
	fifo_order(rfifo, &compare_ip_report_addr, 1); /* JZ */

	while ((r_u.ptr=fifo_pop(rfifo)) != NULL) {
		char *extra=NULL;

		push_report_modules((const void *)r_u.ptr); /* ADD to it */
		push_output_modules((const void *)r_u.ptr); /* display it somehow */

		extra=get_report_extra(r_u.r);

		if (port_open(r_u.r->proto, r_u.r->type, r_u.r->subtype)) {
			ia.s_addr=r_u.r->host_addr;
			if (extra != NULL) {
				MSG(M_OUT, "Open     \t%16s[%5d]\t\tFrom %s\tttl %d %s", getservname(r_u.r->sport), r_u.r->sport, inet_ntoa(ia), r_u.r->ttl, extra);
			}
			else {
				MSG(M_OUT, "Open     \t%16s[%5d]\t\tFrom %s\tttl %d", getservname(r_u.r->sport), r_u.r->sport, inet_ntoa(ia), r_u.r->ttl);
			}
		}
		else if (port_closed(r_u.r->proto, r_u.r->type, r_u.r->subtype)) {
			struct in_addr ia2;
			char tmp[32];

			memset(&ia2, 0, sizeof(ia2));
			ia2.s_addr=r_u.r->trace_addr;

			ia.s_addr=r_u.r->host_addr;
			snprintf(tmp, sizeof(tmp) -1, "%s", inet_ntoa(ia));

			if (r_u.r->trace_addr != r_u.r->host_addr) {
				/* treason uncloaked */

				if (extra != NULL) {
					MSG(M_OUT, "Closed   \t%16s[%5d]\t\tTo   %s\tttl %d From %s %s", getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, inet_ntoa(ia2), extra);
				}
				else {
					MSG(M_OUT, "Closed   \t%16s[%5d]\t\tTo   %s\tttl %d From %s", getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, inet_ntoa(ia2));
				}
			}
			else {
				if (extra != NULL) {
					MSG(M_OUT, "Closed   \t%16s[%5d]\t\tFrom %s\tttl %d %s", getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, extra);
				}
				else {
					MSG(M_OUT, "Closed   \t%16s[%5d]\t\tFrom %s\tttl %d", getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl);
				}
			}
		} /* end PORT CLOSED */
		else {
			struct in_addr ia2;
			char tmp[32];

			memset(&ia2, 0, sizeof(ia2));
			ia2.s_addr=r_u.r->trace_addr;

			ia.s_addr=r_u.r->host_addr;
			snprintf(tmp, sizeof(tmp) -1, "%s", inet_ntoa(ia));

			if (r_u.r->trace_addr != r_u.r->host_addr) {
				/* treason uncloaked */

				if (r_u.r->proto == IPPROTO_ICMP) {
					if (extra != NULL) {
						MSG(M_OUT, "T%.02dC%.02d   \t%16s[%5d]\t\tTo   %s\tttl %d From %s %s", r_u.r->type, r_u.r->subtype, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, inet_ntoa(ia2), extra);
					}
					else {
						MSG(M_OUT, "T%.02dC%.02d   \t%16s[%5d]\t\tTo   %s\tttl %d From %s", r_u.r->type, r_u.r->subtype, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, inet_ntoa(ia2));
					}
				}
				else if (r_u.r->proto == IPPROTO_TCP) {
					char tcpflags[16];

					str_tcpflags(tcpflags, r_u.r->type);
					if (extra != NULL) {
						MSG(M_OUT, "TCP%s\t%16s[%5d]\t\tTo   %s\tttl %d From %s %s", tcpflags, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, inet_ntoa(ia2), extra);
					}
					else {
						MSG(M_OUT, "TCP%s\t%16s[%5d]\t\tTo   %s\tttl %d From %s", tcpflags, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, inet_ntoa(ia2));
					}
				}
				else if (r_u.r->proto == IPPROTO_UDP) {
					PANIC("now this is silly [1]");
				}
				else {
					PANIC("now this is silly [2]");
				}
			}
			else {
				if (r_u.r->proto == IPPROTO_ICMP) {
					if (extra != NULL) {
						MSG(M_OUT, "T%.02dC%.02d   \t%16s[%5d]\t\tTo   %s\tttl %d %s", r_u.r->type, r_u.r->subtype, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, extra);
					}
					else {
						MSG(M_OUT, "T%.02dC%.02d   \t%16s[%5d]\t\tTo   %s\tttl %d", r_u.r->type, r_u.r->subtype, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl);
					}
				}
				else if (r_u.r->proto == IPPROTO_TCP) {
					char tcpflags[16];

					str_tcpflags(tcpflags, r_u.r->type);
					if (extra != NULL) {
						MSG(M_OUT, "TCP%s\t%16s[%5d]\t\tTo   %s\tttl %d %s", tcpflags, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl, extra);
					}
					else {
						MSG(M_OUT, "TCP%s\t%16s[%5d]\t\tTo   %s\tttl %d", tcpflags, getservname(r_u.r->sport), r_u.r->sport, tmp, r_u.r->ttl);
					}
				}
				else if (r_u.r->proto == IPPROTO_UDP) {
					PANIC("now this is silly [3]");
				}
				else {
					PANIC("now this is silly [4]");
				}
			}
		} /* end Not port OPEN or CLOSED */
		fifo_destroy(r_u.r->od_q);
		xfree(r_u.ptr);
	}

	fifo_destroy(rfifo);

	return;
}