static char *test_q_transfer() { packet *q = q_create(); packet *rq = q_create(); packet p = pkt_create(DATA, 1, 2, 3, 4); packet p2; q_write(p, 0, rq, 4); q_transfer(rq, q, 4); q_read(&p2, 0, q, 4); mu_assert("FAIL: test_q_transfer", (p.x == p2.x) && (p.y == p2.y)); q_destroy(q); q_destroy(rq); return NULL; }
void kitchen_destroy(struct kitchen *k) { int i; // Destroy the queue elements while (!q_empty(k->group_list)) { kfree(q_remhead(k->group_list)); } // Destroy the queue q_destroy(k->group_list); // Destroy the cv cv_destroy(k->kitchen_cv); // Destroy the entrance lock lock_destroy(k->kitchen_lock); // Destroy the bowl locks for (i = 0; i < NumBowls; i++) { lock_destroy(k->bowl_locks[i]); } // Destroy the bowl lock array kfree(k->bowl_locks); // Destroy the kitchen kfree(k); // Clear the pointer k = NULL; }
char * test_peek(void) { int v; mu_assert("init", q_init() == q_success); mu_assert("insert", q_insert(18) == q_success); mu_assert("peek", q_peek(&v) == q_success); mu_assert("value", v == 18); mu_assert("destroy", q_destroy() == q_success); return NULL; }
/* * Cleanup function. * * The queue objects to being destroyed if it's got stuff in it. * Use scheduler_killall to make sure this is the case. During * ordinary shutdown, normally it should be. */ void scheduler_shutdown(void) { scheduler_killall(); assert(curspl>0); q_destroy(runqueue); runqueue = NULL; }
char * test_one_insert_remove(void) { int v; mu_assert("init", q_init() == q_success); mu_assert("insert", q_insert(16) == q_success); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 16); mu_assert("destroy", q_destroy() == q_success); return NULL; }
static char *test_q_set_last_op() { packet *q = q_create(); q_set_last_op(WRITE, 0, 0, q, N); mu_assert("FAIL: test_q_set_last_op [1]", q_last_op_is_write(0, 0, q, N)); q_set_last_op(READ, 4, 0, q, N); mu_assert("FAIL: test_q_set_last_op [2]", !q_last_op_is_write(4, 0, q, N)); mu_assert("FAIL: test_q_set_last_op [3]", q_last_op_is_read(4, 0, q, N)); q_destroy(q); return NULL; }
static char *test_q_set_tail_index() { packet *q = q_create(); q_set_tail_index(10, 0, 0, q, N); mu_assert("FAIL: test_q_set_tail_index [1]", q_get_tail_index(0, 0, q, N) == 10); q_set_tail_index(0, 0, 0, q, N); mu_assert("FAIL: test_q_set_tail_index [2]", q_get_tail_index(0, 0, q, N) == 0); mu_assert("FAIL: test_q_set_tail_index [3]", q_get_tail_index(1, 0, q, N) == 0); q_destroy(q); return NULL; }
static char *test_q_get_head_index() { packet *q = q_create(); packet i; mu_assert("FAIL: test_q_get_head_index [1]", q_get_head_index(0, 0, q, N) == 0); q_write(i, 0, q, N); q_read(&i, 0, q, N); mu_assert("FAIL: test_q_get_head_index [2]", q_get_head_index(0, 0, q, N) == 1); q_destroy(q); return NULL; }
/* * Cleanup function. * * The queue objects to being destroyed if it's got stuff in it. * Use scheduler_killall to make sure this is the case. During * ordinary shutdown, normally it should be. */ void scheduler_shutdown(void) { panic("not used."); scheduler_killall(); assert(curspl>0); q_destroy(runqueue); runqueue = NULL; }
void Disconnect(void) { // disable and delete the context. txDisableConnection(hContext); txReleaseObject(&g_hGlobalInteractorSnapshot); txShutdownContext(hContext, TX_CLEANUPTIMEOUT_DEFAULT, TX_FALSE); txReleaseContext(&hContext); q_destroy(); }
static char *test_q_is_empty() { packet *q = q_create(); packet p = pkt_create(ERROR, 0, 0, 0, 0); mu_assert("FAIL: test_q_is_empty [1]", q_is_empty(0, 0, q, N)); q_write(p, 0, q, N); mu_assert("FAIL: test_q_is_empty [2]", !q_is_empty(0, 0, q, N)); q_read(&p, 0, q, N); mu_assert("FAIL: test_q_is_empty [3]", q_is_empty(0, 0, q, N)); q_destroy(q); return NULL; }
char * test_two_insert_remove(void) { int v; mu_assert("init", q_init() == q_success); mu_assert("insert", q_insert(8) == q_success); mu_assert("insert", q_insert(91) == q_success); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 8); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 91); mu_assert("destroy", q_destroy() == q_success); return NULL; }
static char *test_q_read() { packet *q = q_create(); packet p = pkt_create(REFERENCE, 0, 0, 0, 0); packet p2 = pkt_create(ERROR, 0, 0, 0, 0); q_write(p, 0, q, N); q_read(&p2, 0, q, N); mu_assert("FAIL: test_q_read [1]", (p.x == p2.x) && (p.y == p2.y)); q_read(&p2, 0, q, N); mu_assert("FAIL: test_q_read [2]", !q_read(&p2, 0, q, N)); q_destroy(q); return NULL; }
static char *test_q_last_op_is_read() { packet *q = q_create(); q_set_last_op(READ, 0, 0, q, N); mu_assert("FAIL: test_q_last_op_is_read [1]", q_last_op_is_read(0, 0, q, N)); q_set_last_op(READ, 1, 0, q, N); mu_assert("FAIL: test_q_last_op_is_read [2]", q_last_op_is_read(1, 0, q, N)); q_set_last_op(READ, 2, 0, q, N); mu_assert("FAIL: test_q_last_op_is_read [3]", q_last_op_is_read(2, 0, q, N)); q_set_last_op(WRITE, 3, 0, q, N); mu_assert("FAIL: test_q_last_op_is_read [4]", !q_last_op_is_read(3, 0, q, N)); q_destroy(q); return NULL; }
static char *test_q_last_op_is_write() { packet *q = q_create(); q_set_last_op(WRITE, 0, 0, q, N); mu_assert("FAIL: test_q_last_op_is_write [1]", q_last_op_is_write(0, 0, q, N)); q_set_last_op(WRITE, 1, 0, q, N); mu_assert("FAIL: test_q_last_op_is_write [2]", q_last_op_is_write(1, 0, q, N)); q_set_last_op(WRITE, 2, 0, q, N); mu_assert("FAIL: test_q_last_op_is_write [3]", q_last_op_is_write(2, 0, q, N)); q_set_last_op(READ, 3, 0, q, N); mu_assert("FAIL: test_q_last_op_is_write [4]", !q_last_op_is_write(3, 0, q, N)); q_destroy(q); return NULL; }
static char *test_q_size() { packet *q = q_create(); packet p = pkt_create(ERROR, 0, 0, 0, 0); mu_assert("FAIL: test_q_size [1]", q_size(0, 0, q, N) == 0); for (int i = 0; i < 20; i++) { q_write(p, 0, q, N); } mu_assert("FAIL: test_q_size [2]", q_size(0, 0, q, N) == 16); q_read(&p, 0, q, N); mu_assert("FAIL: test_q_size [3]", q_size(0, 0, q, N) == 15); q_destroy(q); return NULL; }
static char *test_q_is_full() { packet *q = q_create(); packet p = pkt_create(ERROR, 0, 0, 0, 0); mu_assert("FAIL: test_q_is_full [1]", !q_is_full(0, 0, q, N)); for (int i = 0; i < 16; i++) { q_write(p, 0, q, N); } mu_assert("FAIL: test_q_is_full [2]", q_is_full(0, 0, q, N)); q_read(&p, 0, q, N); mu_assert("FAIL: test_q_is_full [3]", !q_is_full(0, 0, q, N)); q_destroy(q); return NULL; }
void scheduler_shutdown(void) { int i; scheduler_killall(); assert(curspl>0); for(i = 0; i < NUM_PRIORITIES; i++) { q_destroy(runqueue[i]); runqueue[i] = NULL; } }
void cv_destroy(struct cv *cv) { assert(cv != NULL); // add stuff here as needed kfree(cv->name); #if OPT_A1 q_destroy(cv->sleeping_list); #endif kfree(cv); }
static char *test_q_write() { packet *q = q_create(); packet p = pkt_create(DATA, 1, 2, 3, 4); q_write(p, 0, q, N); mu_assert("FAIL: test_q_write [1]", !q_is_empty(0, 0, q, N)); q_write(p, 0, q, N); mu_assert("FAIL: test_q_write [2]", q_size(0, 0, q, N) == 2); for (int i = 0; i < 14; i++) { q_write(p, 0, q, N); } mu_assert("FAIL: test_q_write [3]", !q_write(p, 0, q, N)); q_destroy(q); return NULL; }
char * test_indexed_insert_remove(void) { int v; mu_assert("init", q_init() == q_success); for(int i = 0; i < 30; i++) { mu_assert("insert", q_insert(i) == q_success); } for(int i = 0; i < 1000; i++) { mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == i); mu_assert("insert", q_insert(30 + i) == q_success); } mu_assert("destroy", q_destroy() == q_success); return NULL; }
static CVNode * cond_variable_destroy_rec(CVNode * n,cond_variable * cv){ if(n == NULL){ return NULL; } if(n->cv->id == cv->id){ CVNode * next = n->next; q_destroy(cv->q); free(cv); free(n); condvar_number --; return next; } n->next = cond_variable_destroy_rec(n->next,cv); return n; }
char * test_three_insert_remove(void) { int v; mu_assert("init", q_init() == q_success); mu_assert("insert", q_insert(7) == q_success); mu_assert("insert", q_insert(18) == q_success); mu_assert("insert", q_insert(30) == q_success); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 7); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 18); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 30); mu_assert("destroy", q_destroy() == q_success); return NULL; }
void cv_destroy(struct cv *cv) { assert(cv != NULL); //Like locks, before we destroy, we want to ensure there is no one waiting or in the queue. assert(cv->count == 0); // no resources left! assert(q_empty(cv->thread_queue)); //make sure the queue is empty //If those pass, we destroy the queue! q_destroy(cv->thread_queue); kfree(cv->name); kfree(cv); cv = NULL; //set the pointer to null just in case }
void test_q() { printf("\ntesting queue\n"); int capacity = 128; struct qnode* q = q_create(capacity); int num = 200; for (int i = 0; i < num; ++i) { q_enqueue(q, i); } while (!q_empty(q)) { printf("%d ", q_dequeue(q)); } q_destroy(q); }
char * test_multi_insert_remove(void) { int v; mu_assert("init", q_init() == q_success); mu_assert("insert", q_insert(8) == q_success); mu_assert("insert", q_insert(91) == q_success); for(int i = 0; i < 1000; i++) { mu_assert("insert", q_insert(8) == q_success); mu_assert("insert", q_insert(91) == q_success); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 8); mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 91); } mu_assert("remove", q_remove(&v) == q_success); mu_assert("value", v == 8); mu_assert("destroy", q_destroy() == q_success); return NULL; }
/* * Create an interpreter pool. * One worker will adaptively be available for each client. * The remainder are taken from the GDKnr_threads argument and * typically is equal to the number of cores * The workers are assembled in a local table to enable debugging. */ static int DFLOWinitialize(void) { int i, limit; int created = 0; MT_lock_set(&mal_contextLock, "DFLOWinitialize"); if (todo) { /* somebody else beat us to it */ MT_lock_unset(&mal_contextLock, "DFLOWinitialize"); return 0; } todo = q_create(2048, "todo"); if (todo == NULL) { MT_lock_unset(&mal_contextLock, "DFLOWinitialize"); return -1; } for (i = 0; i < THREADS; i++) MT_sema_init(&workers[i].s, 0, "DFLOWinitialize"); limit = GDKnr_threads ? GDKnr_threads - 1 : 0; #ifdef NEED_MT_LOCK_INIT ATOMIC_INIT(exitingLock, "exitingLock"); MT_lock_init(&dataflowLock, "dataflowLock"); #endif MT_lock_set(&dataflowLock, "DFLOWinitialize"); for (i = 0; i < limit; i++) { workers[i].flag = RUNNING; workers[i].cntxt = NULL; if (MT_create_thread(&workers[i].id, DFLOWworker, (void *) &workers[i], MT_THR_JOINABLE) < 0) workers[i].flag = IDLE; else created++; } MT_lock_unset(&dataflowLock, "DFLOWinitialize"); if (created == 0) { /* no threads created */ q_destroy(todo); todo = NULL; MT_lock_unset(&mal_contextLock, "DFLOWinitialize"); return -1; } MT_lock_unset(&mal_contextLock, "DFLOWinitialize"); return 0; }
int spectgen_close(spectgen_handle _handle) { struct spectgen_struct *handle = (struct spectgen_struct *)_handle; if(!handle) return -1; /* Will block till decoder is still active */ decoder_close(handle->session->d_handle); /* Will block if the session is still in working state */ spectgen_session_put(handle->session); q_destroy(&handle->queue); free(handle->leftover); free(handle->barkband_table); free(handle); return 0; }
void decoder_exit(decoder_handle _handle) { struct decoder_handle_struct *handle = (struct decoder_handle_struct *)_handle; void *par; if(!handle) return; handle->active = 0; /* So that the active flag is tested */ SIGNAL_SET(&handle->start_signal); pthread_join(handle->thread, &par); if(handle->backend_handle) decoder_backend_close(handle); handle->backend_handle = NULL; q_destroy(handle->queue); free(handle->queue); SIGNAL_DEINIT(&handle->start_signal); SIGNAL_DEINIT(&handle->finished_signal); free(handle); }
int queuetest(int nargs, char **args) { struct queue *q; (void)nargs; (void)args; q = q_create(8); assert(q != NULL); /* this doesn't require growing the queue */ testq(q, 6); /* this requires growing the queue */ testq(q, 27); q_destroy(q); return 0; }