Beispiel #1
0
//建立looper
AMInt32 AMLooperCreate(struct AMLooper** looper)
{
    //AMLogForDebug("AMLooper", "AMLooperCreate");
	*looper = (struct AMLooper*)malloc(sizeof(struct AMLooper));
	if(NULL == *looper)
		return AME_LOOPER_ALLOC_MEMORY_ERROR;

	memset(*looper, 0, sizeof(struct AMLooper));

	if(construct_List(&((*looper)->handler_queue), sizeof(struct AMHandler), NOFREE) != 0)
	{
		free(*looper);
		*looper = NULL;
		return AME_LOOPER_OTHER_ERROR;
	}
	
	//内存测试.
	//set_alloc_List(&((*looper)->handler_queue), AMMalloc);
	//set_dealloc_List(&((*looper)->handler_queue), AMFree);
	if(construct_List(&((*looper)->message_queue), sizeof(struct AMMessage), FREEOBJ) != 0)
	{
		destruct_List(&((*looper)->handler_queue));
		free(*looper);
		*looper = NULL;
		return AME_LOOPER_OTHER_ERROR;
	}
	//内存测试.
	//set_alloc_List(&((*looper)->message_queue), AMMalloc);
	//set_dealloc_List(&((*looper)->message_queue), AMFree);
	if(construct_List(&((*looper)->time_message_queue), sizeof(struct AMMessage), FREEOBJ) != 0)
	{
		destruct_List(&((*looper)->handler_queue));
		destruct_List(&((*looper)->message_queue));
		free(*looper);
		*looper = NULL;
		return AME_LOOPER_OTHER_ERROR;
	}
	set_compare_List(&((*looper)->time_message_queue),  _AMLooperMessageCmp);
	//set_print_List(&((*looper)->time_message_queue), _AMLooperMessagePrint);
	//内存测试.
	//set_alloc_List(&((*looper)->message_queue), s_malloc);
	//set_dealloc_List(&((*looper)->message_queue), s_free);
	{
		AMInt32 err_code;
		err_code = AMThreadMutexCreate(&((*looper)->queue_mutex));
		err_code = AMThreadMutexCreate(&((*looper)->loop_cond_mutex));
		err_code = AMThreadCondCreate(&((*looper)->loop_cond));
	}

	(*looper)->end_run_flag = LOOPER_END_FALSE;
	(*looper)->start_run_falg = LOOPER_RUNNING_FALSE;
	return AME_LOOPER_SCUESS;
}
Beispiel #2
0
AMTaskMgr* AMTaskMgrCreate(AMInt32 concurNum)
{
    AMInt32 index = 0;
    if(concurNum < 0)
        concurNum = AMASYNCTASK_DEFAULT_EXECUTE_COUNT;
    else if(concurNum > AMASYNCTASK_MAX_EXECUTE_COUNT)
        concurNum = AMASYNCTASK_MAX_EXECUTE_COUNT;

    _AMTaskMgrInit();
    AMThreadMutexLock(&gMutex);
    for(;index < AMASYNCTASK_SUPPORTED_MAXMGR; index++)
    {
        if(gTaskMgr[index] == AMNULL)
        {
            _AMTaskMgr* _taskMgr = (_AMTaskMgr*)AMMalloc(sizeof(_AMTaskMgr));
            if(_taskMgr == AMNULL)
            {
                AMThreadMutexUnlock(&gMutex);
                return AMNULL;
            }
			gTaskMgrCount++;
            AMMemset(_taskMgr, 0 , sizeof(_AMTaskMgr));
            _taskMgr->mId = index;
            _taskMgr->mConcurNum = concurNum;
            AMThreadMutexCreate(&_taskMgr->mMutex);
            AMThreadMutexUnlock(&gMutex);
            return (AMTaskMgr*)_taskMgr;
        }
    }
    AMThreadMutexUnlock(&gMutex);
    return AMNULL;
}
Beispiel #3
0
static AMVoid _AMTaskMgrInit()
{
    if(gMutex != AMNULL)
        return;
     AMThreadMutexCreate(&gMutex);
     gTaskMgrCount = 0;
     AMMemset(gTaskMgr, 0, sizeof(gTaskMgr));
}
Beispiel #4
0
AMInt32	AIMAuthModule_create(IAIM *pIM, AMHandle *phAuthModule)
{
	AIMAuthModule *pAuthModule = (AIMAuthModule *)AMMalloc(sizeof(AIMAuthModule));
	
	if(!pAuthModule)
		return eAIM_RESULT_MALLOC_ERROR;

	AMMemset(pAuthModule, 0, sizeof(AIMAuthModule));
	
	if(AMThreadMutexCreate(&pAuthModule->mtxAuth))
	{
		AMFree(pAuthModule);
		return eAIM_RESULT_MALLOC_ERROR;
	}

	pAuthModule->pIM = pIM;
	construct(List, &pAuthModule->lstAuth, sizeof(AIMAuth), FREEOBJ);
	set_dealloc(List, &pAuthModule->lstAuth, _AIMAuth_destroy);

	*phAuthModule = pAuthModule;

	return eAIM_RESULT_OK;
}