Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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 );
}