Esempio n. 1
0
void TMemPool_Free(TMemPool * me)
{
   //used to find out if element is one of the pre allocated elements
   //which are not freed at once...
   size_t lowptr  = (size_t)me->preAllocElems;
   size_t highptr = (size_t)(me->preAllocElems + (me->mincount * me->elementsize));
   
   
   //Free all memory from list of unsed elements...
   TMinNode * n = (TMinNode*)GETFIRST(&me->poolList );
   while( ISELEMENTVALID ( n = (TMinNode*)GETFIRST(&me->poolList ) ) )
   {
      //remove from list
      REMOVE(n);
            
      //is it part of the pre allocated elements? if not delete it...
      if ((size_t)n <  lowptr || (size_t)n >= highptr)
      {
         //free element...
         os_free(n);
      }        
   }
   
   //Free the bloc of pre allocated elements...
   os_free( me->preAllocElems );
}
Esempio n. 2
0
void * TMemPool_AllocElem( TMemPool * me, BYTE flags )
{
   void * e;
   //too much elements in use?
   if (me->currcount >= me->maxcount)
      return NULL;
   me->currcount++;

   //something in unsed elements list?
   e = GETFIRST(&me->poolList);
   if (ISELEMENTVALID(e) )
   {
      REMOVE((TMinNode*)e);
      
      if (flags == MP_CLEAR)
         memset(e, me->elementsize, 0);
   }
   else
   {
      //alloc an new element...
      e = os_malloc(me->elementsize);
      assert(e);
   }
   return e;
}
Esempio n. 3
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;
}
Esempio n. 4
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 );
}