//添加一个消息 AMInt32 AMLooperAddMessage(struct AMLooper* looper, struct AMMessage* message) { // AMInt32 ret_code = AME_LOOPER_SCUESS; //AMLogForDebug("AMLooper", "AMLooperAddMessage"); if(NULL == looper) return AME_LOOPER_LOOPER_NULL; if( NULL == message) return AME_LOOPER_MESSAGE_NULL; if(LOOPER_END_TRUE == looper->end_run_flag) return AME_LOOPER_LOOPER_INVALID; if(looper->start_run_falg != LOOPER_RUNNING_TRUE) return AME_LOOPER_LOOPER_NOT_STARTED; //添加到消息队列尾部, 注意要保持列表线程安全. { AMInt32 err_code; err_code = AMThreadMutexLock(&looper->queue_mutex); err_code = push_back_List(&looper->message_queue, message, sizeof(struct AMMessage), STATIC); err_code = AMThreadMutexUnlock(&looper->queue_mutex); //添加了一个消息, 条件变量通知 AMThreadMutexLock(&looper->loop_cond_mutex); looper->isHasRecord = 1; AMThreadMutexUnlock(&looper->loop_cond_mutex); AMThreadCondSignal(&looper->loop_cond); } return AME_LOOPER_SCUESS; }
//添加一个Handler AMInt32 AMLooperAddHandler(struct AMLooper* looper, struct AMHandler* handler) { //AMLogForDebug("AMLooper", "AMLooperAddHandler"); if(NULL == looper) return AME_LOOPER_LOOPER_NULL; if( NULL == handler) return AME_LOOPER_HANDLE_NULL; if(LOOPER_END_TRUE == looper->end_run_flag) return AME_LOOPER_LOOPER_INVALID; if(HANDLE_END_TRUE == handler->end_run_flag) return AME_LOOPER_HANDLE_INVALID; /* if(looper->start_run_falg != LOOPER_RUNNING_TRUE) return AME_LOOPER_LOOPER_NOT_STARTED; */ //添加到队列尾部, 注意要保持列表线程安全. { AMInt32 err_code; err_code = AMThreadMutexLock(&looper->queue_mutex); err_code = push_back_List(&looper->handler_queue, handler, sizeof(struct AMHandler), DYNAMIC); err_code = AMThreadMutexUnlock(&looper->queue_mutex); } return AME_LOOPER_SCUESS; }
static AMInt32 _AIMAuthModule_addAuth(AMHandle hAuthModule, const AMChar *szSession, const AMChar *szRawPacket, AMInt32 iPacketLen, AMInt32 *piId) { AIMAuthModule *pAuthModule = (AIMAuthModule *)hAuthModule; AIMAuth *pTmpAuth = AMNULL; AMAssert(piId); pTmpAuth = _AIMAuth_create(szSession, szRawPacket, iPacketLen); if(pTmpAuth) { AMThreadMutexLock(&pAuthModule->mtxAuth); *piId = pTmpAuth->iAuth = ++pAuthModule->iLastId; push_back_List(&pAuthModule->lstAuth, pTmpAuth, sizeof(AIMAuth), DYNAMIC); AMThreadMutexUnlock(&pAuthModule->mtxAuth); return eAIM_RESULT_OK; } return eAIM_RESULT_MALLOC_ERROR; }