コード例 #1
0
ファイル: FactoryProcess.c プロジェクト: Angel-fund/swoole
int swFactoryProcess_start(swFactory *factory)
{
	if (swFactory_check_callback(factory) < 0)
	{
		swWarn("swFactory_check_callback fail");
		return SW_ERR;
	}

	swServer *serv = factory->ptr;
	swFactoryProcess *object = factory->object;
	object->workers_status = SwooleG.memory_pool->alloc(SwooleG.memory_pool, sizeof(char)*serv->worker_num);

	//worler idle or busy
	if(object->workers_status == NULL)
	{
		swWarn("alloc for worker_status fail");
		return SW_ERR;
	}

	//必须先启动manager进程组,否则会带线程fork
	if (swFactoryProcess_manager_start(factory) < 0)
	{
		swWarn("swFactoryProcess_manager_start fail");
		return SW_ERR;
	}
	//主进程需要设置为直写模式
	factory->finish = swFactory_finish;
	return SW_OK;
}
コード例 #2
0
ファイル: FactoryProcess.c プロジェクト: huyyeegz/swoole-src
int swFactoryProcess_start(swFactory *factory)
{
	if (swFactory_check_callback(factory) < 0)
	{
		swWarn("swFactory_check_callback fail");
		return SW_ERR;
	}

	swServer *serv = factory->ptr;
	swFactoryProcess *object = factory->object;
	object->workers_status = SwooleG.memory_pool->alloc(SwooleG.memory_pool, sizeof(char)*serv->worker_num);

	//worler idle or busy
	if (object->workers_status == NULL)
	{
		swWarn("alloc for worker_status fail");
		return SW_ERR;
	}

	//保存下指针,需要和reactor做绑定
	serv->workers = object->workers;

	int i;
	swWorker *worker;

	for(i = 0; i < serv->worker_num; i++)
	{
		 worker = swServer_get_worker(serv, i);
		 if (swWorker_create(worker) < 0)
		 {
			 return SW_ERR;
		 }
	}

	//必须先启动manager进程组,否则会带线程fork
	if (swFactoryProcess_manager_start(factory) < 0)
	{
		swWarn("swFactoryProcess_manager_start fail");
		return SW_ERR;
	}

	if (serv->ipc_mode == SW_IPC_MSGQUEUE)
	{
		//tcp & message queue require writer pthread
		if (serv->have_tcp_sock == 1)
		{
			int ret = swFactoryProcess_writer_start(factory);
			if (ret < 0)
			{
				return SW_ERR;
			}
		}
	}

	//主进程需要设置为直写模式
	factory->finish = swFactory_finish;
	return SW_OK;
}
コード例 #3
0
ファイル: FactoryThread.c プロジェクト: 190235047/swoole-src
static int swFactoryThread_start(swFactory *factory)
{
    swFactoryThread *object = factory->object;
    if (swFactory_check_callback(factory) < 0)
    {
        return SW_ERR;
    }
    swThreadPool_run(&object->workers);
    return SW_OK;
}
コード例 #4
0
ファイル: FactoryProcess.c プロジェクト: wanhuo/swoole-src
int swFactoryProcess_start(swFactory *factory)
{
    if (swFactory_check_callback(factory) < 0)
    {
        swWarn("swFactory_check_callback failed");
        return SW_ERR;
    }

    int i;
    swServer *serv = factory->ptr;
    swWorker *worker;

    for (i = 0; i < serv->worker_num; i++)
    {
        worker = swServer_get_worker(serv, i);
        if (swWorker_create(worker) < 0)
        {
            return SW_ERR;
        }
    }

    serv->reactor_pipe_num = serv->worker_num / serv->reactor_num;

    //必须先启动manager进程组,否则会带线程fork
    if (swFactoryProcess_manager_start(factory) < 0)
    {
        swWarn("swFactoryProcess_manager_start failed.");
        return SW_ERR;
    }

    if (serv->ipc_mode == SW_IPC_MSGQUEUE)
    {
        swQueueMsg_set_blocking(&serv->read_queue, 1);
        //tcp & message queue require writer pthread
        if (serv->have_tcp_sock == 1)
        {
            int ret = swFactoryProcess_writer_start(factory);
            if (ret < 0)
            {
                return SW_ERR;
            }
        }
    }

    //主进程需要设置为直写模式
    factory->finish = swFactory_finish;
    return SW_OK;
}
コード例 #5
0
ファイル: FactoryThread.c プロジェクト: kedyyan/swoole
int swFactoryThread_start(swFactory *factory)
{
	swFactoryThread *this = factory->object;
	swThreadParam *param;
	int i;
	int ret;
	pthread_t pidt;

	ret = swFactory_check_callback(factory);
	if (ret < 0)
	{
		return SW_ERR;
	}
	for (i = 0; i < this->writer_num; i++)
	{
#ifdef HAVE_EVENTFD
		ret = swPipeEventfd_create(&this->writers[i].evfd, 1, 1);
#else
		ret = swPipeBase_create(&this->writers[i].evfd, 1);
#endif
		if (ret < 0)
		{
			swTrace("create eventfd fail\n");
			return SW_ERR;
		}
		param = sw_malloc(sizeof(swThreadParam));
		if (param == NULL)
		{
			return SW_ERR;
		}
		param->object = factory;
		param->pti = i;
		if (pthread_create(&pidt, NULL, (void * (*)(void *)) swFactoryThread_writer_loop, (void *) param) < 0)
		{
			swTrace("pthread_create fail\n");
			return SW_ERR;
		}
		if (swRingQueue_init(&this->queues[i], SW_RINGQUEUE_LEN) < 0)
		{
			swTrace("create ring queue fail\n");
			return SW_ERR;
		}
		this->writers[i].ptid = pidt;
		//SW_START_SLEEP;
	}
	return SW_OK;
}
コード例 #6
0
ファイル: FactoryProcess.c プロジェクト: caoxingxing/swoole
int swFactoryProcess_start(swFactory *factory)
{
	if (swFactory_check_callback(factory) < 0)
	{
		swWarn("swFactory_check_callback fail");
		return SW_ERR;
	}
	//必须先启动manager进程组,否则会带线程fork
	if (swFactoryProcess_manager_start(factory) < 0)
	{
		swWarn("swFactoryProcess_manager_start fail");
		return SW_ERR;
	}
	//主进程需要设置为直写模式
	factory->finish = swFactory_finish;
	return SW_OK;
}
コード例 #7
0
ファイル: FactoryProcess.c プロジェクト: amphisbe/swoole
int swFactoryProcess_start(swFactory *factory)
{
	if (swFactory_check_callback(factory) < 0)
	{
		swWarn("swFactory_check_callback fail");
		return SW_ERR;
	}

	swServer *serv = factory->ptr;
	swFactoryProcess *object = factory->object;
	object->workers_status = SwooleG.memory_pool->alloc(SwooleG.memory_pool, sizeof(char)*serv->worker_num);

	//worler idle or busy
	if(object->workers_status == NULL)
	{
		swWarn("alloc for worker_status fail");
		return SW_ERR;
	}

	//必须先启动manager进程组,否则会带线程fork
	if (swFactoryProcess_manager_start(factory) < 0)
	{
		swWarn("swFactoryProcess_manager_start fail");
		return SW_ERR;
	}

	//保存下指针,需要和reactor做绑定
	serv->workers = object->workers;

#if SW_WORKER_IPC_MODE == 2
	//tcp & message queue require writer pthread
	if (serv->have_tcp_sock == 1)
	{

		int ret = swFactoryProcess_writer_start(factory);
		if (ret < 0)
		{
			return SW_ERR;
		}
	}
#endif

	//主进程需要设置为直写模式
	factory->finish = swFactory_finish;
	return SW_OK;
}
コード例 #8
0
int swFactoryProcess_start(swFactory *factory)
{
	int ret, step = 0;
	ret = swFactory_check_callback(factory);
	if (ret < 0)
	{
		return --step;
	}
	ret = swFactoryProcess_writer_start(factory);
	if (ret < 0)
	{
		return --step;
	}
	ret = swFactoryProcess_worker_start(factory);
	if (ret < 0)
	{
		return --step;
	}
	return SW_OK;
}
コード例 #9
0
ファイル: FactoryThread.c プロジェクト: 29n/php_swoole
int swFactoryThread_start(swFactory *factory)
{
	swFactoryThread *this = factory->object;
	swThreadParam *param;
	int i, evfd;
	int ret, step = 0;
	pthread_t pidt;

	ret = swFactory_check_callback(factory);
	if (ret < 0)
	{
		return --step;
	}
	for (i = 0; i < this->writer_num; i++)
	{
		evfd = eventfd(0, 0);
		if (evfd < 0)
		{
			swTrace("create eventfd fail\n");
			return SW_ERR;
		}
		param = sw_malloc(sizeof(swThreadParam));
		if (param == NULL)
		{
			return SW_ERR;
		}
		param->object = factory;
		param->pti = i;
		if (pthread_create(&pidt, NULL, (void * (*)(void *)) swFactoryThread_writer_loop, (void *) param) < 0)
		{
			swTrace("pthread_create fail\n");
			return --step;
		}
		swRingBuffer_init(&(this->buffers[i]));
		this->writers[i].ptid = pidt;
		this->writers[i].evfd = evfd;
		SW_START_SLEEP;
	}
	return SW_OK;
}
コード例 #10
0
ファイル: FactoryProcess.c プロジェクト: amumu/php_swoole
int swFactoryProcess_start(swFactory *factory)
{
	int ret, step = 0;
	ret = swFactory_check_callback(factory);
	if (ret < 0)
	{
		return --step;
	}
	ret = swFactoryProcess_writer_start(factory);
	if (ret < 0)
	{
		return --step;
	}
	ret = swFactoryProcess_worker_start(factory);
	if (ret < 0)
	{
		return --step;
	}
	//主进程需要设置为直写模式
	factory->finish = swFactory_finish;
	return SW_OK;
}