void * consume_from_render_queue(void *q) { RenderQueue *render_queue = (RenderQueue *)q; while (true) { pthread_mutex_lock(&render_queue->mut); while (render_queue->empty) { log(L_RenderQueue, "consumer: queue EMPTY."); pthread_cond_wait(&render_queue->not_empty, &render_queue->mut); } RenderQueueData render_data; queue_del(render_queue, &render_data); pthread_mutex_unlock(&render_queue->mut); pthread_cond_signal(&render_queue->not_full); consume_render_operations(render_data.frame_buffer, render_data.render_operations, render_data.clip_region); log(L_RenderQueue, "consumer: recieved."); } return 0; }
int coap_recv_queue_pop_node(coap_endpoint_t * p_endpoint, char * buffer, size_t len) { coap_pkt_t * p_pkt = NULL; int ret = 0; assert(p_endpoint); assert(buffer); assert(len > 0); if (queue_is_empty(&p_endpoint->m_recv_queue)) { return 0; } p_pkt = queue_entry(p_endpoint->m_recv_queue.next, coap_pkt_t, node); if (p_pkt->packet_length > len) { coap_log_debug_string("output buffer is too small to store the packet!\r\n"); return COAP_RET_BUFFER_TOO_SMALL; } memcpy(buffer, &p_pkt->hdr, p_pkt->packet_length); ret = p_pkt->packet_length; queue_del(&p_pkt->node); free(p_pkt); p_endpoint->m_recv_queue_pkt_num--; return ret; }
int lifo_out(link *head){ if (queue_empty(head)) return -1; elem *mem=queue_bottom(head,elem,suiv); int val=mem->val; queue_del(mem,suiv); mem_free(mem,sizeof(elem)); return val; }
int coap_free_endpoint(coap_endpoint_mgr_t * p_endpoint_mgr, int i) { int ret = 0; coap_pkt_t * p_pkt = NULL; coap_endpoint_t * p_endpoint = coap_get_endpoint(p_endpoint_mgr, i); if (NULL == p_endpoint) { return COAP_RET_INVALID_PARAMETERS; } while (!queue_is_empty(&p_endpoint->m_send_queue)) { p_pkt = queue_entry(p_endpoint->m_send_queue.next, coap_pkt_t, node); queue_del(&p_pkt->node); free(p_pkt); } while (!queue_is_empty(&p_endpoint->m_recv_queue)) { p_pkt = queue_entry(p_endpoint->m_recv_queue.next, coap_pkt_t, node); queue_del(&p_pkt->node); free(p_pkt); } mutex_uninit(&p_endpoint->m_send_mutex); mutex_uninit(&p_endpoint->m_recv_mutex); free(p_endpoint); ret = coap_set_endpoint(p_endpoint_mgr, i, NULL); if (ret < 0) { return ret; } return 0; }
static struct netqueue *queue_get_slot(struct priv_net *pn) { struct netqueue *q = pn->pn_queue_free.q_next; if (q != &pn->pn_queue_free) { queue_del(q); return q; } if (pn->pn_queue_len++ > QUEUE_MAX) return NULL; return malloc(sizeof(*q)); }
static int queue_get(struct priv_net *pn, void *buf, int len) { struct netqueue *head = &pn->pn_queue; struct netqueue *q = head->q_next; if (q == head) return 0; assert(q->q_len <= len); memcpy(buf, q->q_buf, q->q_len); queue_del(q); queue_add(&pn->pn_queue_free, q); return q->q_len; }
int main() { bt_node *tmp; queue *q = queue_init(); binary_tree *bt = malloc(sizeof(bt_node)); bt->Element = 0; bt->left = malloc(sizeof(bt_node)); bt->left->Element = 1; bt->right = malloc(sizeof(bt_node)); bt->right->Element = 2; tmp = bt->left; tmp->left = malloc(sizeof(bt_node)); tmp->left->Element = 3; tmp->right = malloc(sizeof(bt_node)); tmp->right->Element = 4; tmp = tmp->left; tmp->left = nil; tmp->right = malloc(sizeof(bt_node)); tmp->right->Element = 6; tmp = tmp->right; tmp->left = nil; tmp->right = nil; tmp = bt->left->right; tmp->left = nil; tmp->right = nil; tmp = bt->right; tmp->left = malloc(sizeof(bt_node)); tmp->left->Element = 5; tmp->right = nil; tmp = tmp->left; tmp->left = nil; tmp->right = nil; queue_add(bt, q); while (!setjmp(buf)) { tmp = queue_del(q); printf("visited node index: %d\n", tmp->Element); if (tmp->left != nil) { queue_add(tmp->left, q); } if (tmp->right != nil) { queue_add(tmp->right, q); } } return 0; }
int coap_send_queue_del_node(coap_endpoint_t * p_endpoint, uint16 message_id) { coap_pkt_t * p_pkt = NULL; queue_hdr_t * p = NULL; queue_hdr_t * next = NULL; assert(p_endpoint); for (p = p_endpoint->m_send_queue.next; p != &p_endpoint->m_send_queue; p = next) { p_pkt = queue_entry(p, coap_pkt_t, node); next = p->next; if (p_pkt->hdr.message_id == message_id) { queue_del(&p_pkt->node); free(p_pkt); p_endpoint->m_send_queue_pkt_num--; return 0; } } return -1; }
static void Queue__del(void **queue, void **player){ struct command com; queue_t * q = queue_new(); player_t * pl[1]; pl[0] = player_new('w', 's', 'd', 'a', 'f'); char index = 'w'; char * moves; moves = player_get_moves(pl[0]); for (int a = 0; a < 100; a++){ for (int i = 0; i < 5; i++){ if (moves[i] == index) { i++; com.command = i; com.players = pl[i]; queue_add(q, com); } } } queue_del(q); assert_int_equal(queue_size(q),99); queue_remove(&q); player_remove(&pl); }
int main() { int i = 0; char c; queue_t* firstQueue = queue_create(); queue_t* secondQueue = queue_create(); while (1) { scanf("%c", &c); if (c == '+') { scanf("%c", &c); if (c == '1') { firstQueue = queue_add(firstQueue); } if (c == '2') { secondQueue = queue_add(secondQueue); } } if (c == '-') { scanf("%c", &c); if (c == '1') { firstQueue = queue_del(firstQueue); } if (c == '2') { secondQueue = queue_del(secondQueue); } } if (c == 'c') { firstQueue = queue_concat(firstQueue, secondQueue); /** WARNING: ???? * Возможно тут имелось ввиду освобождение памяти? */ secondQueue = NULL; secondQueue = queue_create(); } if (c == 's') { scanf("%c", &c); if (c == '1') { firstQueue = queue_sort(firstQueue); } if (c == '2') { secondQueue = queue_sort(secondQueue); } } if (c == 'q') { printf("Bye\n"); break; } if (c == 'p') { scanf("%c", &c); if (c == '1') queue_print(firstQueue); if (c == '2') queue_print(secondQueue); } } return 0; }