static struct pipe *pipe_alloc(void) { struct pipe *pipe; struct ring_buff *pipe_buff; void *storage; storage = sysmalloc(DEFAULT_PIPE_BUFFER_SIZE); if (!storage) { return NULL; } pipe = sysmalloc(sizeof(struct pipe)); if (!pipe) { sysfree(storage); return NULL; } pipe_buff = sysmalloc(sizeof(struct ring_buff)); if (!pipe_buff) { sysfree(storage); sysfree(pipe); return NULL; } pipe->buff = pipe_buff; pipe->buf_size = DEFAULT_PIPE_BUFFER_SIZE - 1; ring_buff_init(pipe_buff, 1, DEFAULT_PIPE_BUFFER_SIZE, storage); mutex_init(&pipe->mutex); return pipe; }
static int rx_thread_init(void) { for (size_t i = 0; i < PNET_PRIORITY_COUNT; i++) { event_init(&pack_storage[i].event, "pack_arrived"); ring_buff_init(&pack_storage[i].buff, sizeof(net_packet_t), RX_THRD_BUF_SIZE, (void *) pack_bufs[i]); pnet_rx_threads[i] = thread_create(0, pnet_rx_thread_hnd, &pack_storage[i]); if(err(pnet_rx_threads[i])) { return -1; } schedee_priority_set(&pnet_rx_threads[i]->schedee, SCHED_PRIORITY_NORMAL + 1 + i); } return 0; }