void TMasterCmdFactory_FreeMasterCmd( TMasterCmdReq * mc ) { usedcmd--; //haeng it to the list of unsed master commands... os_thread_MutexLock(&unusedMasterCmdList.Mutex); ADDTAIL(&unusedMasterCmdList, &mc->Node); os_thread_MutexUnlock(&unusedMasterCmdList.Mutex); }
SHARED_FUNCTION TNode * TQueue_GetMsg (TQueue * queue) { TNode * node = NULL; //enter critical section: Get first element and remove it from list (not free it) os_thread_MutexLock( &queue->messageQueue.Mutex ); if (!ISLISTEMPTY(&queue->messageQueue)) { node = (TNode*)GETFIRST(&queue->messageQueue); REMOVE(node); } os_thread_MutexUnlock( &queue->messageQueue.Mutex ); return node; }
SHARED_FUNCTION void TQueue_AddMsg (TQueue * queue, TNode * node) { /* insert element in list only thread save... */ os_thread_MutexLock( &queue->messageQueue.Mutex ); ADDTAIL( &queue->messageQueue, node ); os_thread_MutexUnlock( &queue->messageQueue.Mutex ); //if an yasdi task want's to be signaled do it now if (queue->waitingTask) { TTask_Signal( queue->waitingTask ); } if (queue->waitingTimer) { TTimer_Signal(queue->waitingTimer); } }
TMasterCmdReq * TMasterCmdFactory_GetMasterCmd( TMasterCmdType cmd ) { TMasterCmdReq * mc= NULL; usedcmd++; os_thread_MutexLock(&unusedMasterCmdList.Mutex); if (!ISLISTEMPTY( &unusedMasterCmdList )) { //get it from list... mc = (TMasterCmdReq *)GETFIRST(&unusedMasterCmdList); REMOVE(&mc->Node); //reinit the command TMasterCmd_Init(mc, cmd); } os_thread_MutexUnlock(&unusedMasterCmdList.Mutex); if (mc) return mc; //nothing free, create an new one... return TMasterCmd_Constructor( cmd ); }