Пример #1
0
//-------------------------------------------------------------------------------------		
bool ServerApp::initialize()
{
	if(!initThreadPool())
		return false;

	if(!installSignals())
		return false;
	
	if(!loadConfig())
		return false;
	
	if(!initializeBegin())
		return false;
	
	if(!inInitialize())
		return false;

	bool ret = initializeEnd();

#ifdef ENABLE_WATCHERS
	return ret && initializeWatcher();
#else
	return ret;
#endif
}
Пример #2
0
//-------------------------------------------------------------------------------------		
bool ServerApp::initialize()
{
	if(!initThreadPool())
		return false;

	if(!installSingnals())
		return false;
	
	if(!loadConfig())
		return false;
	
	if(!initializeBegin())
		return false;
	
	if(!inInitialize())
		return false;
	
	// 广播自己的地址给网上上的所有kbemachine
	// 并且从kbemachine获取basappmgr和cellappmgr以及dbmgr地址
	Componentbridge::getSingleton().getComponents().pHandler(this);
	this->getMainDispatcher().addFrequentTask(&Componentbridge::getSingleton());

	bool ret = initializeEnd();

#ifdef ENABLE_WATCHERS
	return ret && initializeWatcher();
#else
	return ret;
#endif
}
Пример #3
0
int main (int argc, char **argv) {
	//初始化线程池
	initThreadPool(3);
	int t[10] = {0};
	int i = 0;
	for (i = 0; i < 10; ++i)
	{
		t[i] = i;
		addTaskToPool(doTask, &t[i]);
	}
	sleep(10);//测试,等待子线程结束
	destroyPool();
	return 0;

	//加入任务
	//退出 释放互斥量 清理内存
}
Пример #4
0
int main(void)
{
	pthread_mutex_init(&mutex, NULL);
//	foo10Secs(NULL);
	int err = initThreadPool(10);
	if(err != INIT_SUCCESS)
	{
		printf("an even bigger fail; error = %d\n", err);
		return 1;
	}
	/*
	for(int i = 0; i < 10; i++)
	{
		err = startJob(fooCounter, NULL);
		if(err != START_JOB_SUCCESS)
		{
			printf("couldn't start a job, error = %d\n", err);
		}
	}
	sleep(15);*/
	for(int i = 0; i < 15; i++)
	{
		err = startJob(fooCounter, NULL);
		if(err != START_JOB_SUCCESS)
		{
			printf("couldn't start a job, error = %d\n", err);
		}
	}
	sleep(40);
	for(int i = 0; i < 6; i++)
	{
		err = startJob(fooCounter, NULL);
		if(err != START_JOB_SUCCESS)
		{
			printf("couldn't start a job, error = %d\n", err);
		}
	}
	sleep(100);
	err = 0;
	if((err = destroyThreadPool()) != DESTROY_SUCCESS)
		printf("destroy failed..: %d\n",err );
	return 0;
}
Пример #5
0
/**
 * This function will initialize cache model.
 *
 * @param cache the cache pointer
 * @param name the cache name
 * @param maxThreadNum the cache use max threads number in thread pool
 * @param threadStackSize the thread stack size in thread pool
 *
 * @return error code
 */
CacheErrCode initCache(pCache const cache, const char* name, uint8_t maxThreadNum,
        uint32_t threadStackSize) {
    CacheErrCode errorCode = CACHE_NO_ERR;

    if ((name == NULL) || (strlen(name) > CACHE_NAME_MAX)) {
        log_i("the name of %s can not be create for list", name);
        errorCode = CACHE_NAME_ERROR;
    } else {
        strcpy(cache->name, name);
    }
    cache->has = hasData;
    cache->add = addData;
    cache->del = delData;
    cache->get = getValue;
    cache->set = setValue;
    cache->getSize = getSize;
    cache->dataHead = NULL;
    cache->dataTail = NULL;
    /* initialize the thread pool */
    cache->pool = (pThreadPool) malloc(sizeof(ThreadPool));
    assert(cache->pool != NULL);
    initThreadPool(cache->pool, "cache", maxThreadNum, threadStackSize);
    return errorCode;
}