int put_event(engine_t e,st_io *io) { assert(e); assert(io); /* mutex_lock(e->mtx); struct block_queue *EventQ = LIST_POP(struct block_queue*,e->block_thread_queue); if(!EventQ) { //没有等待的线程,先缓冲事件 LIST_PUSH_BACK(e->buffering_event_queue,io); io = 0; } mutex_unlock(e->mtx); if(io) BLOCK_QUEUE_PUSH(EventQ,io); */ //printf("putevent\n"); mutex_lock(e->mtx); MsgQueue_t msgQ = LIST_POP(MsgQueue_t,e->block_thread_queue); if(!msgQ) { //没有等待的线程,先缓冲事件 LIST_PUSH_BACK(e->buffering_event_queue,io); io = 0; } mutex_unlock(e->mtx); if(io) PutMsg(msgQ,&io,sizeof(io)); return 0; }
void wpacket_destroy(wpacket_t *w) { buffer_release(&(*w)->buf); buffer_release(&(*w)->writebuf); LIST_PUSH_BACK(g_wpacket_pool,*w); //free(*w); *w = 0; }
//初始化封包池 void init_wpacket_pool(uint32_t pool_size) { uint32_t i = 0; wpacket_t w;// = calloc(1,sizeof(*w)); g_wpacket_pool = LIST_CREATE();//创建包链表 for( ; i < pool_size; ++i) { w = calloc(1,sizeof(*w)); LIST_PUSH_BACK(g_wpacket_pool,w); } }
s32int main() { list_t list; STATIC_TYPE_LIST_INIT(list, u32int); //Test variables u32int test = 100, mid = 200, end = 300; u32int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; //Test variables LIST_INSERT_ARRAY(list, 0, arr + 1, 4); LIST_PUSH_BACK(list, test); LIST_PUSH_BACK(list, mid); LIST_PUSH_BACK(list, end); LIST_PUSH_FRONT(list, end); LIST_PUSH_FRONT(list, end); LIST_PUSH_FRONT(list, end); LIST_POP_BACK(list); LIST_INSERT(list, 1, mid); u32int foreachTmp; size_t sizer; LIST_FRONT(list, foreachTmp); printf("FRONT %d\n", foreachTmp); LIST_BACK_WITH_SIZE(list, foreachTmp, sizer); printf("BACK %d size %zu\n\n", foreachTmp, sizer); LIST_ERASE(list, 0); LIST_FOREACH(foreachTmp, list) { printf("Test %d\n", foreachTmp); }
/** * Parses an input stream and returns a list of nodes. * * \param parser The parser * \param ctx Mango context containing necessary items. * \param error Error to be set if any. * * \return A Node instance. */ MangoNode *mango_parser_parse(MangoParser *parser, MangoContext *ctx, MangoError **error) { MangoLinkedList * nodeList = NULL; MangoNode * firstNode = NULL; MangoNode * nextNode = mango_parser_parse_node(parser, ctx, error); int nodeCount = 0; while (nextNode != NULL) { if (firstNode == NULL) { firstNode = nextNode; } else { if (nodeList == NULL) { nodeList = mango_linkedlist_new(); LIST_PUSH_BACK(nodeList, firstNode); } LIST_PUSH_BACK(nodeList, nextNode); } nodeCount++; nextNode = mango_parser_parse_node(parser, ctx, error); } // just an optimisation to directly return a node if // there is only one item instead of a node list if (nodeCount <= 1) { return firstNode; } else { return (MangoNode *)mango_nodelist_new(nodeList); } }
int WSASend(HANDLE sock,st_io *io,int notify) { assert(io); socket_t s = GetSocketByHandle(sock); if(!s) return -1; int active_send_count = -1; int ret = 0; mutex_lock(s->send_mtx); //为保证执行顺序与请求的顺序一致,先将请求插入队列尾部,再弹出队列首元素 LIST_PUSH_BACK(s->pending_send,io); io = 0; if(s->writeable) { io = LIST_POP(st_io*,s->pending_send); active_send_count = s->active_write_count; }