/** * Creates a new double ring of size <code>windowSize</code>. * * @param windowSize Size of the window. * @return returns the created ring. */ DRING dring_new(int windowSize) { _DRING *dring = malloc(sizeof(*dring)); dring->s = squeue_new(); dring->l = squeue_new(); dring->windowSize = windowSize; dring->maxFirstRing = -1; return (DRING)dring; }
/*! allocate and initialize queues, etc \param[in, out] context \returns 1 on success, 0 on failure */ int dispatcher_init(struct thread_context *context) { assert(context); struct dispatcher_data *data = context->data; context->msg_q = squeue_new(data->msg_q_capacity, data->msg_q_elem_size); if (!context->msg_q) return 0; return 1; }
/*! allocate and initialize queues, etc \param[in, out] context \returns 1 on success, 0 on failure */ int worker_init(struct thread_context *context) { assert(context); int rv; struct worker_data *data = context->data; rv = ip4_module_init(&data->ip4_module, &context->shared->ip4_module, data->pcbmap_capacity); if (rv < 1) return 0; rv = tcp_module_init(&data->tcp_module, &context->shared->tcp_module, data->tcp_pcb_capacity); if (rv < 1) return 0; rv = udp_module_init(&data->udp_module, &context->shared->udp_module, data->udp_pcb_capacity); if (rv < 1) return 0; context->msg_q = squeue_new(data->msg_q_capacity, data->msg_q_elem_size); if (!context->msg_q) return 0; context->pkt_xmit_q = tqueue_new(data->xmit_q_transactions, data->xmit_q_actions_per_transaction); if (!context->pkt_xmit_q) { squeue_delete(&context->msg_q); return 0; } data->xmit_transaction = NULL; context->pkt_recv_q = tqueue_new(data->recv_q_transactions, data->recv_q_actions_per_transaction); if (!context->pkt_recv_q) { squeue_delete(&context->msg_q); tqueue_delete(&context->pkt_xmit_q); return 0; } rv = pktbuff_allocator_init(&data->pktbuff_allocator, data->pktbuff_allocator_capacity, FCL_ALLOCATOR_OOM_POLICY_NONE, 0, packet_buffer_init); if (rv < 0) { squeue_delete(&context->msg_q); tqueue_delete(&context->pkt_xmit_q); tqueue_delete(&context->pkt_recv_q); return 0; } return 1; }
int main() { squeue *q; int rc = 0; int i; int *p; size_t n; int d; q = squeue_new(1024, 4); if (!q) { printf("squeue_new failed\n"); exit(EXIT_FAILURE); } uint32_t data[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; rc = squeue_enter(q, 1); if (rc) { for (p = squeue_get_next_push_slot(q), i=0; p; p = squeue_get_next_push_slot(q), i=(i+1)%10) { *p = data[i]; } squeue_exit(q); } rc = squeue_enter(q, 1); if (rc) { for (p = squeue_get_next_pop_slot(q); p; p = squeue_get_next_pop_slot(q)) { printf("%u ", *p); } squeue_exit(q); } printf("\n********************\n"); do { n = squeue_push_many(q, data, 1, 10); } while (n == 10); for (n = squeue_pop(q, &d, 1); n > 0; n = squeue_pop(q, &d, 0)) { printf("%u ", d); } printf("\n********************\n"); exit(EXIT_SUCCESS); }
/*! allocate and initialize queues, etc \param[in, out] context \returns 1 on success, 0 on failure */ int arpd_init(struct thread_context *context) { struct arpd_data *data; int rv; assert(context); data = context->data; context->msg_q = squeue_new(data->msg_q_capacity, data->msg_q_elem_size); if (!context->msg_q) return 0; context->pkt_xmit_q = cqueue_spsc_new(data->xmit_q_capacity, data->xmit_q_elem_size); if (!context->pkt_xmit_q) { squeue_delete(&context->msg_q); return 0; } rv = xmit_queue_init(context->pkt_xmit_q, &context->shared->inet_info->addr, &context->shared->if_info->mac); if (!rv) { squeue_delete(&context->msg_q); return 0; } context->pkt_recv_q = tqueue_new(data->recv_q_transactions, data->recv_q_actions_per_transaction); if (!context->pkt_recv_q) { squeue_delete(&context->msg_q); cqueue_spsc_delete(&context->pkt_xmit_q); return 0; } data->arp_cache = arp_cache_new(context); if (!data->arp_cache) { squeue_delete(&context->msg_q); cqueue_spsc_delete(&context->pkt_xmit_q); tqueue_delete(&context->pkt_recv_q); return 0; } return 1; }