int main(void) { struct symbol sym; wk_table = hmap_init(MAP_SIZE, 15*sizeof(char), sizeof(int), hash); init_wk_table(wk_table); sym_table = hmap_init(MAP_SIZE, ID_SIZE*sizeof(char), sizeof(struct symbol), hash); undeclared_vars = squeue_init(100, sizeof(struct symbol)); codeInit(); yyparse(); finalizeCode(); hmap_free(wk_table); hmap_free(sym_table); squeue_free(undeclared_vars); return SUCCESS; }
/* * Initialize IP squeues. */ void ip_squeue_init(void (*callback)(squeue_t *)) { int i; squeue_set_t *sqs; ASSERT(sqset_global_list == NULL); ip_squeue_create_callback = callback; squeue_init(); mutex_init(&sqset_lock, NULL, MUTEX_DEFAULT, NULL); sqset_global_list = kmem_zalloc(sizeof (squeue_set_t *) * (NCPU+1), KM_SLEEP); sqset_global_size = 0; /* * We are called at system boot time and we don't * expect memory allocation failure. */ sqs = ip_squeue_set_create(-1); ASSERT(sqs != NULL); mutex_enter(&cpu_lock); /* Create squeue for each active CPU available */ for (i = 0; i < NCPU; i++) { cpu_t *cp = cpu_get(i); if (CPU_ISON(cp) && cp->cpu_squeue_set == NULL) { /* * We are called at system boot time and we don't * expect memory allocation failure then */ cp->cpu_squeue_set = ip_squeue_set_create(cp->cpu_id); ASSERT(cp->cpu_squeue_set != NULL); } } register_cpu_setup_func(ip_squeue_cpu_setup, NULL); mutex_exit(&cpu_lock); }
int main (int argc, char**argv) { int ret = 0; int heartbeat_usec = 50000; //20Hz is ok by default uint64_t last_beat = 0; Log_info ("cloudvpn starting"); Log (0, "You are using CloudVPN, which is Free software."); Log (0, "For more information please see the GNU GPL license,"); Log (0, "which you should have received along with this program."); setup_sighandler (kill_cloudvpn); /* * initialization */ if (!config_parse (argc, argv) ) { Log_error ("failed to parse config, terminating."); ret = 1; goto failed_config; } if (!config_get_int ("heartbeat", heartbeat_usec) ) heartbeat_usec = 50000; Log_info ("heartbeat is set to %d usec", heartbeat_usec); timestamp_update(); //get initial timestamp status_init(); route_init(); squeue_init(); network_init(); if (poll_init() ) { Log_fatal ("poll initialization failed"); ret = 2; goto failed_poll; } if (do_memlock() ) { Log_fatal ("locking process to memory failed"); ret = 3; goto failed_poll; } if (comm_load() ) { Log_fatal ("failed to load comm data"); ret = 4; goto failed_poll; } if (comm_init() ) { Log_fatal ("communication initialization failed"); ret = 5; goto failed_comm; } if (gate_init() ) { Log_fatal ("gate initialization failed"); ret = 6; goto failed_gate; } if (do_chroot() ) { Log_fatal ("chrooting failed"); ret = 7; goto failed_sec; } if (do_switch_user() ) { Log_fatal ("user switch failed"); ret = 8; goto failed_sec; } /* * main loop */ Log_info ("initialization complete, entering main loop"); last_beat = 0; //update immediately. while (!g_terminate) { timestamp_update(); if ( (timestamp() - last_beat) < (unsigned int) heartbeat_usec) { //poll more stuff poll_wait_for_event (heartbeat_usec - timestamp() + last_beat); //send the results comm_flush_data(); gate_flush_data(); continue; } last_beat = timestamp(); gate_periodic_update(); comm_periodic_update(); route_periodic_update(); status_try_export(); } /* * deinitialization */ Log_info ("shutting down"); failed_sec: gate_shutdown(); failed_gate: comm_shutdown(); failed_comm: if (poll_deinit() ) Log_warn ("poll_deinit somehow failed!"); failed_poll: failed_config: if (!ret) Log_info ("cloudvpn exiting gracefully"); else Log_error ("cloudvpn exiting with code %d", ret); return ret; }
int main(void) { struct object obj; struct object *obp; const void *vp; unsigned long num; unsigned long cmp; squeue_init(&sq, buf, QUEUE_SIZE, sizeof(struct object)); printf("h t u\n"); dump(); /* check size is zero */ test_assert(squeue_size(&sq) == 0); test_assert(squeue_SIZE(&sq) == 0); printf("\n"); /* check enq works */ for (num = 0; num < QUEUE_SIZE; ++num) { obj.num = num << 1; test_assert(squeue_enq(&sq, &obj) == 1); dump(); } printf("\n"); /* check size is correct */ test_assert(squeue_bytes(&sq) == QUEUE_SIZE * sizeof(struct object)); test_assert(squeue_BYTES(&sq) == QUEUE_SIZE * sizeof(struct object)); test_assert(squeue_size(&sq) == QUEUE_SIZE); test_assert(squeue_SIZE(&sq) == QUEUE_SIZE); /* check deny overflow */ test_assert(squeue_enq(&sq, 0) == 0); dump(); printf("\n"); /* check deq works */ for (num = 0; num < QUEUE_SIZE; ++num) { test_assert(squeue_peek(&sq, (void **) &obp) == 1); cmp = obp->num; test_assert(cmp == num << 1); test_assert(squeue_deq(&sq, (void **) &obp)); cmp = obp->num; test_assert(cmp == num << 1); dump(); } printf("\n"); /* check deny underflow */ test_assert(squeue_deq(&sq, 0) == 0); dump(); printf("\n"); /* check enq works */ for (num = 0; num < QUEUE_SIZE; ++num) { obj.num = num << 1; test_assert(squeue_enq(&sq, &obj) == 1); dump(); } printf("\n"); /* check size is correct */ test_assert(squeue_bytes(&sq) == QUEUE_SIZE * sizeof(struct object)); test_assert(squeue_BYTES(&sq) == QUEUE_SIZE * sizeof(struct object)); test_assert(squeue_size(&sq) == QUEUE_SIZE); test_assert(squeue_SIZE(&sq) == QUEUE_SIZE); /* check deny overflow */ test_assert(squeue_enq(&sq, 0) == 0); dump(); printf("\n"); /* check deq works */ for (num = 0; num < QUEUE_SIZE; ++num) { test_assert(squeue_peek(&sq, (void **) &obp) == 1); cmp = obp->num; test_assert(cmp == num << 1); test_assert(squeue_deq(&sq, (void **) &obp)); cmp = obp->num; test_assert(cmp == num << 1); dump(); } printf("\n"); /* check data works */ vp = squeue_data(&sq); test_assert(vp == buf); vp = squeue_DATA(&sq); test_assert(vp == buf); return 0; }