コード例 #1
0
ファイル: Channel.c プロジェクト: LinYushen/swoole
/**
 * 推入数据
 */
int swChannel_push(swChannel *object, void *in, int data_length)
{
	assert(object->flag & SW_CHAN_LOCK);
	object->lock.lock(&object->lock);
	int ret = swChannel_in(object, in, data_length);
	object->lock.unlock(&object->lock);
	return ret;
}
コード例 #2
0
ファイル: ThreadPool.c プロジェクト: restonexyz/swoole-src
int swThreadPool_dispatch(swThreadPool *pool, void *task, int task_len)
{
    int ret;

    pool->cond.lock(&pool->cond);
#ifdef SW_THREADPOOL_USE_CHANNEL
    ret = swChannel_in(pool->chan, task, task_len);
#else
    ret = swRingQueue_push(&pool->queue, task);
#endif
    pool->cond.unlock(&pool->cond);

    if (ret < 0)
    {
        SwooleG.error = EAGAIN;
        return SW_ERR;
    }

    sw_atomic_t *task_num = &pool->task_num;
    sw_atomic_fetch_add(task_num, 1);

    return pool->cond.notify(&pool->cond);
}