static void test_list_lpop() { // Setup list_t *list = list_new(); list_node_t *a = list_rpush(list, list_node_new("a")); list_node_t *b = list_rpush(list, list_node_new("b")); list_node_t *c = list_rpush(list, list_node_new("c")); // Assertions assert(3 == list->len); assert(a == list_lpop(list)); assert(2 == list->len); assert(b == list->head); assert(NULL == list->head->prev && "new head node prev is not NULL"); assert(NULL == a->prev && "detached node prev is not NULL"); assert(NULL == a->next && "detached node next is not NULL"); assert(b == list_lpop(list)); assert(1 == list->len); assert(c == list_lpop(list)); assert(0 == list->len); assert(NULL == list->head); assert(NULL == list->tail); assert(NULL == list_lpop(list)); assert(0 == list->len); }
/****************************************************************************** **函数名称: rtrd_rsvr_wiov_add **功 能: 追加发送数据(无数据拷贝) **输入参数: ** ctx: 全局对象 ** rsvr: 接收服务 **输出参数: NONE **返 回: 0:成功 !0:失败 **实现描述: 将发送链表中的数据指针放到iov中. **注意事项: 数据发送完毕之后, 必须释放内存空间! **作 者: # Qifeng.zou # 2015.12.26 # ******************************************************************************/ static int rtrd_rsvr_wiov_add(rtrd_rsvr_t *rsvr, rtrd_sck_t *sck) { int len; rtmq_header_t *head; wiov_t *send = &sck->send; /* > 从消息链表取数据 */ while (!wiov_is_full(send)) { /* 1 是否有数据 */ head = (rtmq_header_t *)list_lpop(sck->mesg_list);; if (NULL == head) { break; /* 无数据 */ } else if (RTMQ_CHECK_SUM != head->checksum) { /* 合法性校验 */ assert(0); } len = sizeof(rtmq_header_t) + head->length; /* 当前消息总长度 */ /* 3 设置头部数据 */ head->type = htons(head->type); head->nodeid = htonl(head->nodeid); head->flag = head->flag; head->length = htonl(head->length); head->checksum = htonl(head->checksum); /* 4 设置发送信息 */ wiov_item_add(send, (char *)head, len, NULL, mem_dealloc); } return RTMQ_OK; }
void syscall_prc_getNextMessage(void){ krn_getIdleProcess()->sync_lock = TRUE; Process * prc = prc_getCurrentProcess(); list_node_t * node = list_lpop(prc->list_msgs); //PrcMessage * msg = (PrcMessage*)node->val; unsigned int msg = (unsigned int)node->val; prc->context->gregs[0] = msg;//(unsigned int)node->val; //if (node) // free(node); krn_getIdleProcess()->sync_lock = FALSE; }
json_value_t * json_array_shift (json_array_t *self) { if (0 == self->list->len) { return NULL; } list_node_t *node = list_lpop(self->list); if (NULL == node) { return NULL; } self->length = self->list->len; return (json_value_t *) node->val; }
void case_list_lpop() { struct list *list = list(); char *s1 = "s1", *s2 = "s2", *s3 = "s3"; assert(list_rpush(list, s1) == LIST_OK); assert(list_rpush(list, s2) == LIST_OK); assert(list_rpush(list, s3) == LIST_OK); assert(list_len(list) == 3); assert(list->head->data == s1); assert(list_lpop(list) == s1); assert(list_len(list) == 2); assert(list->head->data == s2); assert(list_lpop(list) == s2); assert(list_len(list) == 1); assert(list->head->data == s3); assert(list_lpop(list) == s3); assert(list_len(list) == 0); assert(list->head == NULL); list_free(list); }
/*! * Turn cpu into sleep. Wakes up only for processes switching. */ void prc_startScheduler(void){ hw_clk_setTimerCback(KRN_TIMER, clkKrnCback); hw_clk_setTimerCback(KRN_APP_RESERVED_TIMER, clkAppCback); hw_clk_setCountdownTimer(KRN_TIMER, PRC_CTXSWITCH_RATE_MS, true, true); while (TRUE){ // is there messages to the kernel? Process * prc = prc_getCurrentProcess(); while (prc->list_msgs->len > 0){ krn_getIdleProcess()->sync_lock = TRUE; list_node_t * node = list_lpop(prc->list_msgs); //PrcMessage * msg = (PrcMessage * )node->val; // TODO: process it. do not just destroy //free(node); // TODO: Heap corruption =( krn_getIdleProcess()->sync_lock = FALSE; } // wait for interruptions // save the energy! krn_halt(); } }