/* ------------------------------------------------------------------------- */ void start_app_thread (int ricetta) { /* Lancia i thread di ogni applicazione. Ai thread verrà passato solo un numero progressivo (1..4) che troverá una associazione implicita con il numero delle stazioni. La struttura dati relativa è accessibile a livello globale */ int r,i; applica_t *s; for (i=1; i<=_nsta; i++) { LTL [i-1] = fifo_create (); LRL [i-1] = fifo_create (); prog_crc [i-1] = 5; s = (applica_t*) malloc (sizeof(applica_t)); (*s).napp = i; (*s).ricetta = ricetta; switch (i) { case 1 : r = pthread_create (&mc_thread_g, NULL, app_thread1, s); break; case 2 : r = pthread_create (&mc_thread_g, NULL, app_thread2, s); break; case 3 : r = pthread_create (&mc_thread_g, NULL, app_thread3, s); break; case 4 : r = pthread_create (&mc_thread_g, NULL, app_thread4, s); break; } if (r) { printf ("Errore nella creazione del thread dell'applicazione numero %d\n", i); printf ("Codice di errore riportato da pthread_create(): %d\n",r); exit(-1); } } }
static int start(sox_effect_t * effp) { priv_t * p = (priv_t *) effp->priv; fifo_create(&p->input_fifo, (int)sizeof(double)); memset(fifo_reserve(&p->input_fifo, p->filter_ptr->post_peak), 0, sizeof(double) * p->filter_ptr->post_peak); fifo_create(&p->output_fifo, (int)sizeof(double)); return SOX_SUCCESS; }
/* allocate memory and do data initialization, threads initialization, also call reset write/read pointers */ int bsreader_open(void) { int ret = 0; u32 max_entry_num; lock_all(); if (G_ready) { printf("already opened\n"); return -1; } //init iav and test iav state, it's expected iav should not be in encoding, before open bsreader if (init_iav() < 0) { ret = -3; goto error_catch; } max_entry_num = G_bsreader_init_data.max_buffered_frame_num; myFIFO[0] = fifo_create(G_bsreader_init_data.ring_buf_size[0], sizeof(bs_info_t), max_entry_num); myFIFO[1] = fifo_create(G_bsreader_init_data.ring_buf_size[1], sizeof(bs_info_t), max_entry_num); myFIFO[2] = fifo_create(G_bsreader_init_data.ring_buf_size[2], sizeof(bs_info_t), max_entry_num); myFIFO[3] = fifo_create(G_bsreader_init_data.ring_buf_size[3], sizeof(bs_info_t), max_entry_num); //init cavlc if (G_bsreader_init_data.cavlc_possible) { if (init_cavlc() < 0) { printf("init cavlc in bsreader error \n"); ret = -2; goto error_catch; } } //create thread after all other initialization is done if (create_working_thread() < 0) { printf("create working thread error \n"); ret = -1; goto error_catch; } G_ready = 1; unlock_all(); return 0; error_catch: cancel_working_thread(); if (G_bsreader_init_data.cavlc_possible) { destroy_cavlc(); } unlock_all(); printf("bsreader opened.\n"); return ret; }
static void arp_announce_func(void** state) { // Nic initialization void* malloc_pool = malloc(POOL_SIZE); init_memory_pool(POOL_SIZE, malloc_pool, 0); __nics[0] = malloc(sizeof(NIC)); __nic_count++; __nics[0]->mac = 0x10c37b9309d1; __nics[0]->pool_size = POOL_SIZE; __nics[0]->pool = malloc_pool; __nics[0]->output_buffer = fifo_create(8, malloc_pool); __nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool); uint32_t spa = 0xc0a80a6f; arp_announce(__nics[0], spa); Packet* packet = fifo_pop(__nics[0]->output_buffer); assert_memory_equal(packet->buffer + packet->start, arp_announce_packet, 46); destroy_memory_pool(malloc_pool); free(malloc_pool); malloc_pool = NULL; }
// -----[ _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); }
int dogechat_plugin_init (struct t_dogechat_plugin *plugin, int argc, char *argv[]) { char str_option[256]; /* make C compiler happy */ (void) argc; (void) argv; dogechat_plugin = plugin; fifo_quiet = 1; fifo_create (); snprintf (str_option, sizeof (str_option), "plugins.var.fifo.%s", FIFO_OPTION_NAME); dogechat_hook_config (str_option, &fifo_config_cb, NULL); fifo_command_init (); fifo_info_init (); fifo_quiet = 0; return DOGECHAT_RC_OK; }
void adc_open(int fifo_sz) { adc1_fifo = fifo_create(fifo_sz); assert(adc1_fifo != NULL); tim2_config(); adc_configure(); }
static void arp_pack_func(void** state) { // Nic initialization void* malloc_pool = malloc(POOL_SIZE); init_memory_pool(POOL_SIZE, malloc_pool, 0); __nics[0] = malloc(sizeof(NIC)); __nic_count++; __nics[0]->mac = 0x10c37b9309d1; __nics[0]->pool_size = POOL_SIZE; __nics[0]->pool = malloc_pool; __nics[0]->output_buffer = fifo_create(8, malloc_pool); __nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool); uint32_t spa = 0xc0a80a6f; uint32_t dpa = 0xc0a80a90; arp_request(__nics[0], dpa, spa); Packet* packet = fifo_pop(__nics[0]->output_buffer); uint32_t comp_size = packet->end; packet->end = 0; arp_pack(packet); // Checking packet->end assert_int_equal(comp_size, packet->end); destroy_memory_pool(malloc_pool); free(malloc_pool); malloc_pool = NULL; }
int C_put_fifo (int argc, char **argv) { int value = 0; int i = 1; /* value start index in argv */ if (_G_p_fifo == NULL) { _G_p_fifo = fifo_create (_FIFO_NUM, sizeof (int)); } /* create FIFO failed */ if (_G_p_fifo == NULL) { serial_printf("Create FIFO failed!"); return CMD_ERROR; } /* read the put values */ for (; i < argc; i++) { value = 0; sscanf (argv[i], "%d", (unsigned int *)&value); if (fifo_put (_G_p_fifo, &value) == OS_STATUS_ERROR) { serial_printf("The FIFO is full!"); return CMD_ERROR; } serial_printf("Put: %d\n", value); } serial_printf("The put operation is Done."); return CMD_OK; }
sched_t * sched_static_create(simulator_t * sim) { sched_static_t * sched= (sched_static_t *) MALLOC(sizeof(sched_static_t)); // Initialize public part (type + ops) sched->type= SCHEDULER_STATIC; sched->sim= sim; sched->ops.destroy = _destroy; sched->ops.cancel = _cancel; sched->ops.clear = _clear; sched->ops.run = _run; sched->ops.post = _post; sched->ops.num_events = _num_events; sched->ops.event_at = _event_at; sched->ops.dump_events = _dump_events; sched->ops.set_log_process= _set_log_progress; sched->ops.cur_time = _cur_time; // Initialize private part sched->events= fifo_create(EVENT_QUEUE_DEPTH, _fifo_event_destroy); fifo_set_option(sched->events, FIFO_OPTION_GROW_EXPONENTIAL, 1); sched->cur_time= 0; sched->pProgressLogStream= NULL; return (sched_t *) sched; }
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); } }
void adc_open(void) { DMA2_Stream0_fifo = fifo_create(FIFO_SZ); assert(DMA2_Stream0_fifo != NULL); Timer1Config(); adc_configure(); ADC_SoftwareStartConv(ADC1); }
/*** * Create a thread pool, including a fifo of tasks. * Starts consuming threads immediately. */ thread_pool_t *thread_pool_create( const char *name, int thread_count ) { assert( thread_count > 0 ); thread_pool_t *pool = (thread_pool_t*) malloc( sizeof( thread_pool_t ) ); pool->mutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t)); dna_mutex_init(pool->mutex); pool->wait = (pthread_cond_t*) malloc(sizeof(pthread_cond_t)); dna_cond_init(pool->wait); pool->name = name; pool->tasks = fifo_create("(tasks)", 50 ); pool->thread_queue = fifo_create("(threads)", thread_count ); int i = 0; for ( i = 0; i < thread_count; i++ ) { dna_thread_context_t *context = dna_thread_context_create(i+1); execution_args_t *args = execution_args_create(pool, context); dna_thread_context_execute(context, &execute_task_thread_internal, args); fifo_push( pool->thread_queue, context ); } return pool; }
static void arp_process_func(void** state) { // Timer setting timer_init("IntelCore(TM) i5-4670 CPU @ 3.40GHz"); // Nic initialization void* malloc_pool = malloc(POOL_SIZE); init_memory_pool(POOL_SIZE, malloc_pool, 0); __nics[0] = malloc(sizeof(NIC)); __nic_count++; __nics[0]->mac = 0x74d4358f66cb; __nics[0]->pool_size = POOL_SIZE; __nics[0]->pool = malloc_pool; __nics[0]->output_buffer = fifo_create(8, malloc_pool); __nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool); // Arp request Packet* packet = nic_alloc(__nics[0], sizeof(arp_request_packet)); memcpy(packet->buffer + packet->start, arp_request_packet, sizeof(arp_request_packet)); Ether* ether = (Ether*)(packet->buffer + packet->start); ARP* arp = (ARP*)ether->payload; uint32_t addr = endian32(arp->tpa); nic_ip_add(__nics[0], addr); assert_true(arp_process(packet)); packet = fifo_pop(__nics[0]->output_buffer); assert_memory_equal(packet->buffer + packet->start, arp_reply_packet, 42); nic_free(packet); packet = NULL; // Arp response packet = nic_alloc(__nics[0], sizeof(arp_reply_packet)); memcpy(packet->buffer + packet->start, arp_reply_packet, sizeof(arp_reply_packet)); ether = (Ether*)(packet->buffer + packet->start); arp = (ARP*)ether->payload; addr = endian32(arp->tpa); nic_ip_add(__nics[0], addr); uint8_t comp_mac[6] = { 0xcb, 0x66, 0x8f, 0x35, 0xd4, 0x74 }; uint32_t sip = endian32(arp->spa); Map* arp_table = nic_config_get(packet->nic, "net.arp.arptable"); assert_true(arp_process(packet)); ARPEntity* entity = map_get(arp_table, (void*)(uintptr_t)sip); assert_memory_equal((uint8_t*)&entity->mac, comp_mac, 6); destroy_memory_pool(malloc_pool); free(malloc_pool); malloc_pool = NULL; }
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); }
void fifo_config_change_file_enabled (const void *pointer, void *data, struct t_config_option *option) { /* make C compiler happy */ (void) pointer; (void) data; (void) option; fifo_remove (); if (weechat_config_boolean (fifo_config_file_enabled)) fifo_create (); }
void fast_dac_open(int dac1_fifo_size,int dac2_fifo_size) { memset(dac1_buf, 32768, sizeof(short)*DAC_DUC_BUF_SZ); memset(dac2_buf, 32768, sizeof(short)*DAC_BUF_SZ); /* Create fifos */ dac1_fifo = fifo_create(dac1_fifo_size); dac2_fifo = fifo_create(dac2_fifo_size); assert(dac1_fifo != NULL); assert(dac2_fifo != NULL); /* Turn on the clocks we need -----------------------------------------------*/ /* DMA1 clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); /* GPIOA clock enable (to be used with DAC) */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* GPIO Pin configuration DAC1->PA.4, DAC2->PA.5 configuration --------------*/ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Timer and DAC 1 & 2 Configuration ----------------------------------------*/ tim7_config(); tim6_config(); dac1_config(); dac2_config(); init_debug_blinky(); }
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); }
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); } }
void fifo_config_change_file_path (const void *pointer, void *data, struct t_config_option *option) { /* make C compiler happy */ (void) pointer; (void) data; (void) option; fifo_quiet = 1; fifo_remove (); fifo_create (); fifo_quiet = 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); } }
int main() { pthread_t awriter_thread; int i,j; short read_buf[READ_SZ]; int n_out = 0; int sucess; f = fifo_create(FIFO_SZ); #ifdef USE_THREADS pthread_create(&awriter_thread, NULL, writer_thread, NULL); #endif for(i=0; i<LOOPS; ) { #ifndef USE_THREADS writer(); #endif #ifdef USE_MUTEX pthread_mutex_lock(&mutex); #endif sucess = (fifo_read(f, read_buf, READ_SZ) == 0); #ifdef USE_MUTEX pthread_mutex_unlock(&mutex); #endif if (sucess) { for(j=0; j<READ_SZ; j++) { if (read_buf[j] != n_out) printf("error: %d %d\n", read_buf[j], n_out); n_out++; if (n_out == N_MAX) n_out = 0; } i++; } } #ifdef USE_THREADS run_thread = 0; pthread_join(awriter_thread,NULL); #endif return 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 ); }
int main (void) { long long put = 0, get = 0; char str[32]; fifo_t fifo = fifo_create(); while (1) { int i; int block = random() % BLOCK; for (i = 0; i < block; i++) { if ((put & DISPLAY) == DISPLAY) { printf("%lli... (size %lli)\r", put, put - get); fflush(stdout); } sprintf(str, "%lli", put++); fifo_add(fifo, str); } block = random() % BLOCK; for (i = 0; i < block; i++) { char* out = fifo_getdel(fifo); if (!out) break; long long test = atoll(out); if (test != get) { fprintf(stderr, "error, getting %lli (%s), should be %lli\n", test, out, get); exit(1); } get++; free(out); } } return 0; }
testcase testcase_create(int num_students, int num_jobs) { int i; int num_vertices = num_students + num_jobs + 1; testcase t = malloc(sizeof(testcase_t)); t->num_students = num_students; t->num_jobs = num_jobs; t->num_vertices = num_vertices; t->adjacencies = malloc(num_vertices*sizeof(fifo)); for(i=0; i<num_vertices; i++) { t->adjacencies[i] = fifo_create(); } t->pair_g1 = malloc(num_vertices*sizeof(int)); t->pair_g2 = malloc(num_vertices*sizeof(int)); t->dist = malloc(num_vertices*sizeof(int)); t->matching = 0; return t; }
int fifo_config_cb (void *data, const char *option, const char *value) { /* make C compiler happy */ (void) data; (void) option; if (dogechat_strcasecmp (value, "on") == 0) { if (fifo_fd < 0) fifo_create (); } else { if (fifo_fd >= 0) fifo_remove (); } return DOGECHAT_RC_OK; }
static void arp_get_mac_func(void** state) { //timer setting timer_init("IntelCore(TM) i5-4670 CPU @ 3.40GHz"); // Nic initialization void* malloc_pool = malloc(POOL_SIZE); init_memory_pool(POOL_SIZE, malloc_pool, 0); __nics[0] = malloc(sizeof(NIC)); __nic_count++; __nics[0]->mac = 0x74d4358f66cb; __nics[0]->pool_size = POOL_SIZE; __nics[0]->pool = malloc_pool; __nics[0]->output_buffer = fifo_create(8, malloc_pool); __nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool); Packet* packet = nic_alloc(__nics[0], sizeof(arp_reply_packet)); memcpy(packet->buffer + packet->start, arp_reply_packet, sizeof(arp_reply_packet)); Ether* ether = (Ether*)(packet->buffer + packet->start); ARP* arp = (ARP*)ether->payload; uint32_t addr = endian32(arp->tpa); nic_ip_add(__nics[0], addr); if(!arp_process(packet)) return; uint32_t spa = 0xc0a80a6f; uint32_t dpa = 0xc0a80a90; uint64_t comp_tha = 0x74d4358f66cb; uint64_t d_mac = arp_get_mac(__nics[0], dpa, spa); assert_memory_equal((uint8_t*)&d_mac, (uint8_t*)&comp_tha, 6); destroy_memory_pool(malloc_pool); free(malloc_pool); malloc_pool = NULL; }
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; }
void dac_open(void) { memset(dac_buf, 32768, sizeof(short)*DAC_BUF_SZ); /* Create fifo */ DMA1_Stream6_fifo = fifo_create(FIFO_SZ); assert(DMA1_Stream6_fifo != NULL); /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Preconfiguration before using DAC----------------------------------------*/ GPIO_InitTypeDef GPIO_InitStructure; /* DMA1 clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); /* GPIOA clock enable (to be used with DAC) */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* TIM6 Configuration ------------------------------------------------------*/ TIM6_Config(); DAC_Ch2_Config(); }
int main(int argc, char *argv[]) { pthread_t thrs[NENQER+NDEQER]; int i, j; int qlen=FIFO_LEN_DEFAULT; if (argc>1) { qlen=atoi(argv[1]); } q=fifo_create(qlen); /* smaller buffer to saturate the buffer */ # if (CHECK) chararr=(char *)calloc(NITER*NENQER, sizeof(char)); # endif for (i=0; i<NENQER; i++) pthread_create(thrs+i, NULL, enquer, NULL); for (; i<NENQER+NDEQER; i++) pthread_create(thrs+i, NULL, dequer, NULL); for (i=0; i<NENQER; i++) pthread_join(thrs[i], NULL); for (j=0; j<NDEQER; j++) fifo_enqueue(q, (void *)0); for (; i<NENQER+NDEQER; i++) pthread_join(thrs[i], NULL); # if (CHECK) for (j=0; j<NITER*NENQER; j++) if (chararr[j]==0) { printf("%d hasn't been seen\n", j+1); } # endif return 0; }