ch_task_pool_t * ch_task_pool_create(ch_context_t *context){ ch_task_t *tsk; apr_pool_t *mp = context->mp; ch_task_pool_t *tpool = (ch_task_pool_t*)apr_palloc(mp,sizeof(ch_task_pool_t)); tpool->context = context; tpool->rx_tsks = apr_array_make(context->mp,16,sizeof(ch_task_t*)); tpool->as_tsks = apr_array_make(context->mp,16,sizeof(ch_task_t*)); /* create all rx tasks */ if(_rx_tasks_create(tpool) == CH_ERROR){ return NULL; } if(_as_tasks_create(tpool) == CH_ERROR){ return NULL; } /*ok!*/ ch_log(CH_LOG_INFO,"create recieve tasks[%u] and assemble tasks[%u] in task pool ok!", tpool->rx_tsks->nelts,tpool->as_tsks->nelts); return tpool; }
static int _rx_tasks_create(ch_task_pool_t *tpool){ if(tpool->context->ppool == NULL) return CH_OK; ch_task_t *tsk = ch_rxtask_create(tpool->context); if(tsk == NULL){ ch_log(CH_LOG_ERR,"create recieve task failed!"); return CH_ERROR; } _task_put(tpool->rx_tsks,tsk); return CH_OK; }
/* * Allocate a new channel. The refcount is set to 1. * The channel isn't actually used until it is opened. * Returns NULL if out of memory. */ channel_T * add_channel(void) { int which; channel_T *channel = (channel_T *)alloc_clear((int)sizeof(channel_T)); if (channel == NULL) return NULL; channel->ch_id = next_ch_id++; ch_log(channel, "Opening channel\n"); #ifdef CHANNEL_PIPES for (which = CHAN_SOCK; which <= CHAN_IN; ++which) #else which = CHAN_SOCK; #endif { channel->ch_pfd[which].ch_fd = (sock_T)-1; #ifdef FEAT_GUI_X11 channel->ch_pfd[which].ch_inputHandler = (XtInputId)NULL; #endif #ifdef FEAT_GUI_GTK channel->ch_pfd[which].ch_inputHandler = 0; #endif #ifdef FEAT_GUI_W32 channel->ch_pfd[which].ch_inputHandler = -1; #endif #ifdef FEAT_GUI_MACVIM channel->ch_pfd[which].ch_inputHandler = 0; #endif } channel->ch_timeout = 2000; if (first_channel != NULL) { first_channel->ch_prev = channel; channel->ch_next = first_channel; } first_channel = channel; channel->ch_refcount = 1; return channel; }
static int _as_tasks_create(ch_task_pool_t *tpool){ ch_task_t *tsk; int i; for(i = 0; i<tpool->context->n_assemble_tasks; i++){ tsk = ch_assemble_task_create(tpool->context,i+1); if(tsk == NULL){ ch_log(CH_LOG_ERR,"Create assemble task[%d] failed!",i+1); return CH_ERROR; } _task_put(tpool->as_tsks,tsk); } return CH_OK; }