int cevents_pop_fired(cevents *cevts, cevent_fired *fired) { cevent_fired *fevt; LOCK(&cevts->qlock); int *fd = (int*)clist_rpop(cevts->fired_fds); if(fd == NULL) { UNLOCK(&cevts->qlock); return 0; } fevt = (cevent_fired*)clist_rpop(cevts->events[*fd].fired_queue); jfree(fd); UNLOCK(&cevts->qlock); if(fevt == NULL) return 0; *fired = *fevt; jfree(fevt); return 1; }
int cevents_pop_fired(cevents *cevts, cevent_fired *fired) { cevent_fired *fevt; LOCK(&cevts->qlock); fevt = (cevent_fired*)clist_rpop(cevts->fired_queue); UNLOCK(&cevts->qlock); if(fevt == NULL) return 0; *fired = *fevt; jfree(fevt); return 1; }
void *print_test(void *d) { data *datap = (data*)d; while(1) { spinlock_lock(&datap->lock); clist_rpop(datap->cq); spinlock_unlock(&datap->lock); if(LIST_EMPTY(datap->cq)) break; } return NULL; }
static void test_clist_rpop(void) { list_node_t *list = &test_clist; test_clist_add_two(); clist_rpop(list); TEST_ASSERT_NOT_NULL(list->next); TEST_ASSERT(list->next->next == &tests_clist_buf[0]); }
void *cqueue_pop_mt(void *data) { size_t i = 0; while(1) { spinlock_lock(&lock); count++; fprintf(stdout, "%lu pop\n", (long)pthread_self()); clist_rpop(cl); spinlock_unlock(&lock); } return NULL; }
int main(int argc, char const *argv[]) { size_t i; lock = SL_UNLOCK; cl = clist_create(); count = 0; for(i = 0; i < 6; i++) clist_lpush(cl, NULL); clist_rpop(cl); clist_rpop(cl); clist_rpop(cl); clist_rpop(cl); clist_rpop(cl); clist_rpop(cl); for(i = 0; i < 6; i++) clist_lpush(cl, NULL); clist_destroy(cl); cl = clist_create(); for(i = 0; i < 1000; i++) clist_rpush(cl, NULL); for(i = 0; i < 1000; i++) clist_lpush(cl, NULL); for(i = 0; i < 1000; i++) clist_lpop(cl); for(i = 0; i < 1000; i++) clist_rpop(cl); clist_destroy(cl); printf("%llu\n", used_mem()); return 0; }