static void socket_test() { test_flag = 1; qsocket_t *socket; qactor_t *actor; qbuffer_init_freelist(); qsocket_init_free_list(); actor = qactor_new(1); socket = qsocket_new(1, actor); CTEST_TRUE(socket->in != NULL); CTEST_TRUE(socket->out != NULL); CTEST_TRUE(!qlist_empty(&(socket->entry))); qsocket_free(socket); CTEST_TRUE(qlist_empty(&(socket->entry))); CTEST_TRUE(socket->in == NULL); CTEST_TRUE(socket->out == NULL); qsocket_destroy_free_list(); qbuffer_destroy_freelist(); }
static void destroy_logs() { if (!qlist_empty(&(logger->free_list))) { qlog_free(&(logger->free_list)); qlist_entry_init(&(logger->free_list)); } qassert(qlist_empty(&logger->free_list)); }
static void freelist_test_fail() { int i; testdata_t *data; qfreelist_t data_freelist; alloc_num = free_num = 0; qfreelist_conf_t conf = QFREELIST_CONF("data free list", sizeof(testdata_t), DATA_FREE_NUM, data_init_fail, data_destroy, NULL); qfreelist_init(&data_freelist, &conf); CTEST_NUM_EQ(DATA_FREE_NUM, data_freelist.initnum); for (i = 0; i < DATA_FREE_NUM; ++i) { data = qfreelist_new(&data_freelist); CTEST_TRUE(data == NULL); } CTEST_NUM_EQ(DATA_FREE_NUM, alloc_num); /* after alloc DATA_FREE_NUM items fail, free list not empty */ CTEST_FALSE(qlist_empty(&(data_freelist.free))); qfreelist_destroy(&data_freelist); }
static void qlist_move_all(struct qlist_head *from, struct qlist_head *to) { if (unlikely(qlist_empty(from))) return; if (qlist_empty(to)) { *to = *from; qlist_init(from); return; } to->tail->next = from->head; to->tail = from->tail; to->bytes += from->bytes; qlist_init(from); }
static void qlist_put(struct qlist *q, void **qlink, size_t size) { if (unlikely(qlist_empty(q))) q->head = qlink; else *q->tail = qlink; q->tail = qlink; *qlink = NULL; q->bytes += size; }
static void qlist_put(struct qlist_head *q, struct qlist_node *qlink, size_t size) { if (unlikely(qlist_empty(q))) q->head = qlink; else q->tail->next = qlink; q->tail = qlink; qlink->next = NULL; q->bytes += size; }
static int queues_post(struct PINT_manager_s *manager, PINT_worker_inst *inst, PINT_queue_id id, PINT_operation_t *operation) { struct PINT_worker_queues_s *w; int ret; PINT_worker_id wid; struct PINT_queue_s *queue; PINT_queue_id queue_id; w = &inst->queues; gen_mutex_lock(&w->mutex); if(qlist_empty(&w->queues)) { gossip_err("%s: cannot post an operation without first adding queues " "to the queue worker\n", __func__); gen_mutex_unlock(&w->mutex); return -PVFS_EINVAL; } id_gen_fast_register(&wid, w); /* if the queue_id is zero, then assume that there's * only one queue maintained by this worker and use that */ if(id == 0) { /* a dirty hack to check that the list of queues only has one element */ if(w->queues.next->next != &w->queues) { gossip_err("%s: no queue id was specified and there's more than " "one queue being managed by this worker\n", __func__); gen_mutex_unlock(&w->mutex); return -PVFS_EINVAL; } /* there must be only one queue, so just use that */ queue = qlist_entry(w->queues.next, struct PINT_queue_s, link); queue_id = queue->id; } else {
static void qlist_move(struct qlist *from, void **last, struct qlist *to, size_t size) { if (unlikely(last == from->tail)) { qlist_move_all(from, to); return; } if (qlist_empty(to)) to->head = from->head; else *to->tail = from->head; to->tail = last; from->head = *last; *last = NULL; from->bytes -= size; to->bytes += size; }
static void qlist_move(struct qlist_head *from, struct qlist_node *last, struct qlist_head *to, size_t size) { if (unlikely(last == from->tail)) { qlist_move_all(from, to); return; } if (qlist_empty(to)) to->head = from->head; else to->tail->next = from->head; to->tail = last; from->head = last->next; last->next = NULL; from->bytes -= size; to->bytes += size; }
cfio_msg_t *cfio_recv_get_first() { cfio_msg_t *_msg = NULL, *msg; qlist_head_t *link; size_t size; debug(DEBUG_RECV, "client_get_index = %d", client_get_index); if(qlist_empty(&(msg_head[client_get_index].link))) { link = NULL; }else { link = msg_head[client_get_index].link.next; } if(NULL == link) { msg = NULL; }else { msg = qlist_entry(link, cfio_msg_t, link); cfio_recv_unpack_msg_size(msg, &size); if(msg->size == size) //only contain one single msg { qlist_del(link); _msg = msg; }else { msg->size -= size; _msg = cfio_msg_create(); _msg->addr = msg->addr; _msg->src = msg->src; _msg->dst = msg->dst; msg->addr += size; } client_get_index = (client_get_index + 1) % client_num; } if(_msg != NULL) { debug(DEBUG_RECV, "get msg size : %lu", _msg->size); } return _msg; }
static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache) { struct qlist_node *qlink; if (unlikely(qlist_empty(q))) return; qlink = q->head; while (qlink) { struct kmem_cache *obj_cache = cache ? cache : qlink_to_cache(qlink); struct qlist_node *next = qlink->next; qlink_free(qlink, obj_cache); qlink = next; } qlist_init(q); }
int prio_next( tw_stime * poffset, void * sched, void * rc_event_save, model_net_sched_rc * rc, tw_lp * lp){ // check each priority, first one that's non-empty gets the next mn_sched_prio *ss = sched; for (int i = 0; i < ss->params.num_prios; i++){ // TODO: this works for now while the other schedulers have the same // internal representation if (!qlist_empty(&ss->sub_scheds[i]->reqs)){ rc->prio = i; return ss->sub_sched_iface->next( poffset, ss->sub_scheds[i], rc_event_save, rc, lp); } } rc->prio = -1; return -1; // all sub schedulers had no work }
void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache) { unsigned long flags; struct qlist_head *q; struct qlist_head temp = QLIST_INIT; local_irq_save(flags); q = this_cpu_ptr(&cpu_quarantine); qlist_put(q, &info->quarantine_link, cache->size); if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) qlist_move_all(q, &temp); local_irq_restore(flags); if (unlikely(!qlist_empty(&temp))) { spin_lock_irqsave(&quarantine_lock, flags); qlist_move_all(&temp, &global_quarantine); spin_unlock_irqrestore(&quarantine_lock, flags); } }
static void qlist_move_cache(struct qlist_head *from, struct qlist_head *to, struct kmem_cache *cache) { struct qlist_node *curr; if (unlikely(qlist_empty(from))) return; curr = from->head; qlist_init(from); while (curr) { struct qlist_node *next = curr->next; struct kmem_cache *obj_cache = qlink_to_cache(curr); if (obj_cache == cache) qlist_put(to, curr, obj_cache->size); else qlist_put(from, curr, obj_cache->size); curr = next; } }
static void qlist_move_cache(struct qlist *from, struct qlist *to, struct kmem_cache *cache) { void ***prev; if (unlikely(qlist_empty(from))) return; prev = &from->head; while (*prev) { void **qlink = *prev; struct kmem_cache *obj_cache = qlink_to_cache(qlink); if (obj_cache == cache) { if (unlikely(from->tail == qlink)) from->tail = (void **) prev; *prev = (void **) *qlink; from->bytes -= cache->size; qlist_put(to, qlink, cache->size); } else prev = (void ***) *prev; } }
static void qdict_flatten_test(void) { QList *e_1 = qlist_new(); QList *e = qlist_new(); QDict *e_1_2 = qdict_new(); QDict *f = qdict_new(); QList *y = qlist_new(); QDict *z = qdict_new(); QDict *root = qdict_new(); /* * Test the flattening of * * { * "e": [ * 42, * [ * 23, * 66, * { * "a": 0, * "b": 1 * } * ] * ], * "f": { * "c": 2, * "d": 3, * }, * "g": 4, * "y": [{}], * "z": {"a": []} * } * * to * * { * "e.0": 42, * "e.1.0": 23, * "e.1.1": 66, * "e.1.2.a": 0, * "e.1.2.b": 1, * "f.c": 2, * "f.d": 3, * "g": 4, * "y.0": {}, * "z.a": [] * } */ qdict_put_int(e_1_2, "a", 0); qdict_put_int(e_1_2, "b", 1); qlist_append_int(e_1, 23); qlist_append_int(e_1, 66); qlist_append(e_1, e_1_2); qlist_append_int(e, 42); qlist_append(e, e_1); qdict_put_int(f, "c", 2); qdict_put_int(f, "d", 3); qlist_append(y, qdict_new()); qdict_put(z, "a", qlist_new()); qdict_put(root, "e", e); qdict_put(root, "f", f); qdict_put_int(root, "g", 4); qdict_put(root, "y", y); qdict_put(root, "z", z); qdict_flatten(root); g_assert(qdict_get_int(root, "e.0") == 42); g_assert(qdict_get_int(root, "e.1.0") == 23); g_assert(qdict_get_int(root, "e.1.1") == 66); g_assert(qdict_get_int(root, "e.1.2.a") == 0); g_assert(qdict_get_int(root, "e.1.2.b") == 1); g_assert(qdict_get_int(root, "f.c") == 2); g_assert(qdict_get_int(root, "f.d") == 3); g_assert(qdict_get_int(root, "g") == 4); g_assert(!qdict_size(qdict_get_qdict(root, "y.0"))); g_assert(qlist_empty(qdict_get_qlist(root, "z.a"))); g_assert(qdict_size(root) == 10); qobject_unref(root); }
/** * The dbpf open cache is used primarily to manage open * file descriptors to bstream files on IO servers. PVFS * currently uses a lazy style of creating the actual datafiles for * bstreams. Only on the first write to a bstream is the file * actually created (opened with O_CREAT). This means that if a * read of a bstream that hasn't been written should somehow occur, * an ENOENT error will be returned immediately, instead of allowing * a read to EOF (of a zero-byte file). For us, this is ok, since * the client gets the size of the bstream in the getattr before doing * any IO. All that being said, the open_cache_get call needs to * behave differently based on the desired operation: reads on * files that don't exist should return ENOENT, but writes on files * that don't exist should create and open the file. */ int dbpf_open_cache_get( TROVE_coll_id coll_id, TROVE_handle handle, enum open_cache_open_type type, struct open_cache_ref* out_ref) { struct qlist_head *tmp_link; struct open_cache_entry* tmp_entry = NULL; int found = 0; int ret = 0; gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, "dbpf_open_cache_get: called\n"); gen_mutex_lock(&cache_mutex); /* check already opened objects first, reuse ref if possible */ tmp_entry = dbpf_open_cache_find_entry( &used_list, "used list", coll_id, handle); if(!tmp_entry) { tmp_entry = dbpf_open_cache_find_entry( &unused_list, "unused list", coll_id, handle); } out_ref->fd = -1; if (tmp_entry) { if (tmp_entry->fd < 0) { ret = open_fd(&(tmp_entry->fd), coll_id, handle, type); if (ret < 0) { gen_mutex_unlock(&cache_mutex); return ret; } tmp_entry->type = type; } out_ref->fd = tmp_entry->fd; out_ref->type = type; out_ref->internal = tmp_entry; tmp_entry->ref_ct++; /* remove the entry and place it at the used head (assuming it * will be referenced again soon) */ gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, "dbpf_open_cache_get: " "moving to (or reordering in) used list.\n"); qlist_del(&tmp_entry->queue_link); qlist_add(&tmp_entry->queue_link, &used_list); gen_mutex_unlock(&cache_mutex); assert(out_ref->fd > 0); return 0; } /* if we fall through to this point, then the object was not found * in the cache. In order of priority we will now try: free list, * unused_list, and then bypass cache */ if (!qlist_empty(&free_list)) { tmp_link = free_list.next; tmp_entry = qlist_entry(tmp_link, struct open_cache_entry, queue_link); qlist_del(&tmp_entry->queue_link); found = 1; gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, "dbpf_open_cache_get: resetting entry from free list.\n"); }
int dbpf_op_queue_empty(dbpf_op_queue_p op_queue) { return qlist_empty(op_queue); }
static void qdict_array_split_test(void) { QDict *test_dict = qdict_new(); QDict *dict1, *dict2; QInt *int1; QList *test_list; /* * Test the split of * * { * "1.x": 0, * "4.y": 1, * "0.a": 42, * "o.o": 7, * "0.b": 23, * "2": 66 * } * * to * * [ * { * "a": 42, * "b": 23 * }, * { * "x": 0 * }, * 66 * ] * * and * * { * "4.y": 1, * "o.o": 7 * } * * (remaining in the old QDict) * * This example is given in the comment of qdict_array_split(). */ qdict_put(test_dict, "1.x", qint_from_int(0)); qdict_put(test_dict, "4.y", qint_from_int(1)); qdict_put(test_dict, "0.a", qint_from_int(42)); qdict_put(test_dict, "o.o", qint_from_int(7)); qdict_put(test_dict, "0.b", qint_from_int(23)); qdict_put(test_dict, "2", qint_from_int(66)); qdict_array_split(test_dict, &test_list); dict1 = qobject_to_qdict(qlist_pop(test_list)); dict2 = qobject_to_qdict(qlist_pop(test_list)); int1 = qobject_to_qint(qlist_pop(test_list)); g_assert(dict1); g_assert(dict2); g_assert(int1); g_assert(qlist_empty(test_list)); QDECREF(test_list); g_assert(qdict_get_int(dict1, "a") == 42); g_assert(qdict_get_int(dict1, "b") == 23); g_assert(qdict_size(dict1) == 2); QDECREF(dict1); g_assert(qdict_get_int(dict2, "x") == 0); g_assert(qdict_size(dict2) == 1); QDECREF(dict2); g_assert(qint_get_int(int1) == 66); QDECREF(int1); g_assert(qdict_get_int(test_dict, "4.y") == 1); g_assert(qdict_get_int(test_dict, "o.o") == 7); g_assert(qdict_size(test_dict) == 2); QDECREF(test_dict); /* * Test the split of * * { * "0": 42, * "1": 23, * "1.x": 84 * } * * to * * [ * 42 * ] * * and * * { * "1": 23, * "1.x": 84 * } * * That is, test whether splitting stops if there is both an entry with key * of "%u" and other entries with keys prefixed "%u." for the same index. */ test_dict = qdict_new(); qdict_put(test_dict, "0", qint_from_int(42)); qdict_put(test_dict, "1", qint_from_int(23)); qdict_put(test_dict, "1.x", qint_from_int(84)); qdict_array_split(test_dict, &test_list); int1 = qobject_to_qint(qlist_pop(test_list)); g_assert(int1); g_assert(qlist_empty(test_list)); QDECREF(test_list); g_assert(qint_get_int(int1) == 42); QDECREF(int1); g_assert(qdict_get_int(test_dict, "1") == 23); g_assert(qdict_get_int(test_dict, "1.x") == 84); g_assert(qdict_size(test_dict) == 2); QDECREF(test_dict); }
static void qdict_crumple_test_recursive(void) { QDict *src, *dst, *rule, *vnc, *acl, *listen; QDict *empty, *empty_dict, *empty_list_0; QList *rules, *empty_list, *empty_dict_a; src = qdict_new(); qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); qdict_put_str(src, "vnc.listen.port", "5901"); qdict_put_str(src, "vnc.acl.rules.0.match", "fred"); qdict_put_str(src, "vnc.acl.rules.0.policy", "allow"); qdict_put_str(src, "vnc.acl.rules.1.match", "bob"); qdict_put_str(src, "vnc.acl.rules.1.policy", "deny"); qdict_put_str(src, "vnc.acl.default", "deny"); qdict_put_str(src, "vnc.acl..name", "acl0"); qdict_put_str(src, "vnc.acl.rule..name", "acl0"); qdict_put(src, "empty.dict.a", qlist_new()); qdict_put(src, "empty.list.0", qdict_new()); dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); g_assert(dst); g_assert_cmpint(qdict_size(dst), ==, 2); vnc = qdict_get_qdict(dst, "vnc"); g_assert(vnc); g_assert_cmpint(qdict_size(vnc), ==, 3); listen = qdict_get_qdict(vnc, "listen"); g_assert(listen); g_assert_cmpint(qdict_size(listen), ==, 2); g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); acl = qdict_get_qdict(vnc, "acl"); g_assert(acl); g_assert_cmpint(qdict_size(acl), ==, 3); rules = qdict_get_qlist(acl, "rules"); g_assert(rules); g_assert_cmpint(qlist_size(rules), ==, 2); rule = qobject_to(QDict, qlist_pop(rules)); g_assert(rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy")); qobject_unref(rule); rule = qobject_to(QDict, qlist_pop(rules)); g_assert(rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy")); qobject_unref(rule); /* With recursive crumpling, we should see all names unescaped */ g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name")); empty = qdict_get_qdict(dst, "empty"); g_assert(empty); g_assert_cmpint(qdict_size(empty), ==, 2); empty_dict = qdict_get_qdict(empty, "dict"); g_assert(empty_dict); g_assert_cmpint(qdict_size(empty_dict), ==, 1); empty_dict_a = qdict_get_qlist(empty_dict, "a"); g_assert(empty_dict_a && qlist_empty(empty_dict_a)); empty_list = qdict_get_qlist(empty, "list"); g_assert(empty_list); g_assert_cmpint(qlist_size(empty_list), ==, 1); empty_list_0 = qobject_to(QDict, qlist_pop(empty_list)); g_assert(empty_list_0); g_assert_cmpint(qdict_size(empty_list_0), ==, 0); qobject_unref(src); qobject_unref(dst); }
static void freelist_test() { int i; testdata_t *data; qfreelist_t data_freelist; alloc_num = free_num = 0; qfreelist_conf_t conf = QFREELIST_CONF("data free list", sizeof(testdata_t), DATA_FREE_NUM, data_init, data_destroy, NULL); qfreelist_init(&data_freelist, &conf); CTEST_NUM_EQ(DATA_FREE_NUM, data_freelist.initnum); CTEST_TRUE(!qlist_empty(&(data_freelist.free))); CTEST_TRUE(qlist_empty(&(data_freelist.alloc))); CTEST_FALSE(qlist_empty(&(data_freelist.free))); CTEST_NUM_EQ(0, alloc_num); for (i = 0; i < DATA_FREE_NUM; ++i) { data = qfreelist_new(&data_freelist); CTEST_NUM_EQ(1, data->active); CTEST_NUM_EQ(1, data->flag); } CTEST_TRUE(qlist_empty(&(data_freelist.free))); CTEST_TRUE(!qlist_empty(&(data_freelist.alloc))); CTEST_NUM_EQ(DATA_FREE_NUM, alloc_num); /* after alloc DATA_FREE_NUM items, free list empty */ CTEST_TRUE(qlist_empty(&(data_freelist.free))); qfreelist_free(&data_freelist, data); CTEST_NUM_EQ(0, data->active); /* after free an item, free list is not empty */ CTEST_FALSE(qlist_empty(&(data_freelist.free))); CTEST_NUM_EQ(1, free_num); qfreelist_new(&data_freelist); /* after alloc an item, free list is empty */ CTEST_TRUE(qlist_empty(&(data_freelist.free))); CTEST_NUM_EQ(DATA_FREE_NUM + 1, alloc_num); /* * after alloc an item, freelist will prealloc more items, * free list is not empty */ qfreelist_new(&data_freelist); CTEST_FALSE(qlist_empty(&(data_freelist.free))); CTEST_NUM_EQ(DATA_FREE_NUM + 2, alloc_num); for (i = 1; i < DATA_FREE_NUM; ++i) { CTEST_FALSE(qlist_empty(&(data_freelist.free))); qfreelist_new(&data_freelist); } /* after alloc DATA_FREE_NUM - 1 items, free list empty */ CTEST_TRUE(qlist_empty(&(data_freelist.free))); CTEST_NUM_EQ(DATA_FREE_NUM + 2 + DATA_FREE_NUM - 1, alloc_num); qfreelist_destroy(&data_freelist); CTEST_TRUE(qlist_empty(&(data_freelist.free))); CTEST_TRUE(qlist_empty(&(data_freelist.alloc))); }