Example #1
0
//销毁整个looper.
AMInt32 _AMLooperDestory(struct AMLooper* looper)
{
    //AMLogForDebug("AMLooper", "_AMLooperDestory");
	if(NULL == looper)
		return AME_LOOPER_LOOPER_NULL;
	{
		AMInt32 err_code;
		struct AMHandler* temp_handler;
		err_code = AMThreadMutexLock(&looper->queue_mutex);

		//消息销毁
		_AMLooperRemoveAllMsg(looper);
		//Handler销毁
		for(temp_handler = (struct AMHandler*)front_List(&looper->handler_queue); temp_handler != NULL;
			temp_handler = (struct AMHandler*)front_List(&looper->handler_queue))
		{
			pop_front_List(&looper->handler_queue);
			free(temp_handler);
		}

		err_code =AMThreadMutexUnlock(&looper->queue_mutex);

		err_code = AMThreadMutexDestroy(&looper->queue_mutex);
		err_code = AMThreadCondDestroy(&looper->loop_cond);
		err_code = AMThreadMutexDestroy(&looper->loop_cond_mutex);

		destruct_List(&looper->handler_queue);
		destruct_List(&looper->message_queue);
		destruct_List(&looper->time_message_queue);
	}
	free(looper);
	looper = NULL;
	return AME_LOOPER_SCUESS;
}
Example #2
0
AMVoid	AIMAuthModule_destroy(AMHandle hAuthModule)
{
	AIMAuthModule *pAuthModule = (AIMAuthModule *)hAuthModule;

	AMAssert(pAuthModule);

	AMThreadMutexDestroy(&pAuthModule->mtxAuth);

	destruct(List, &pAuthModule->lstAuth);
	
	AMFree(pAuthModule);
}
Example #3
0
static AMVoid _AMTaskMgrUnint()
{
    if(gMutex == AMNULL)
        return;
    else
    {
        AMInt32 taskCount = 0;
        AMThreadMutexLock(&gMutex);
        taskCount = gTaskMgrCount;
        AMThreadMutexUnlock(&gMutex);
        if(taskCount == 0)
        {
            AMThreadMutexDestroy(&gMutex);
            gMutex = AMNULL;
        }
    }
}
Example #4
0
AMInt32   AMTaskMgrDestory(AMTaskMgr* taskMgr)
{   
    _AMTaskMgr* _taskMgr = (_AMTaskMgr*)taskMgr;
    if(_taskMgr == AMNULL)
        return -1;
    else
    {
        _AMTask* task = AMNULL;
        _AMTask* taskNext = AMNULL;
        AMInt32  index = 0;
        AMThreadMutexLock(&_taskMgr->mMutex);
        //Remove all finish and unstarded.
        task = _taskMgr->mTasks;
        while(task != AMNULL)
        {
            AMInt32 retCode = 0;
            taskNext = task->mNext;
            AMTaskMgrRemove((AMTaskMgr*)_taskMgr, (AMTask*)task);
            task = taskNext;
        }
        AMThreadMutexUnlock(&_taskMgr->mMutex);
        //WaitFor running thread.
        for(; index < _taskMgr->mConcurNum; index++)
        {
            if(_taskMgr->mThreads[index] != AMNULL)
            {
                AMThreadWait(_taskMgr->mThreads[index], AMNULL);
            }
        }
        //Remove Form  TaskManager.
        AMThreadMutexLock(&gMutex); 
		AMThreadMutexDestroy(&_taskMgr->mMutex);
        gTaskMgr[_taskMgr->mId] = AMNULL;
        gTaskMgrCount--;
        AMThreadMutexUnlock(&gMutex);
		_AMTaskMgrUnint();
        AMFree(_taskMgr);
        return 0;
    }
}