(file) Return to IDFactory.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/IDFactory.cpp between version 1.1.2.4 and 1.1.2.8

version 1.1.2.4, 2006/06/30 20:32:41 version 1.1.2.8, 2006/06/30 22:37:52
Line 35 
Line 35 
 #include <new> #include <new>
 #include "IDFactory.h" #include "IDFactory.h"
  
 #define PEGASUS_IDFACTORY_MAGIC 0x94E91236  
   
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 IDFactory::IDFactory()  IDFactory::IDFactory(Uint32 firstID) : _firstID(firstID), _nextID(_firstID)
 { {
     IDFactoryRep* rep = (IDFactoryRep*)_rep;  
     PEGASUS_ASSERT(rep->magic != PEGASUS_IDFACTORY_MAGIC);  
   
     new (rep) IDFactoryRep();  
     rep->magic = PEGASUS_IDFACTORY_MAGIC;  
     rep->next = 1;  
 } }
  
 IDFactory::~IDFactory() IDFactory::~IDFactory()
 { {
     IDFactoryRep* rep = (IDFactoryRep*)_rep;      PEGASUS_DEBUG_ASSERT(_magic);
     rep->magic = 0xDDDDDDDD;  
     // Note: never destructor mutex!  
 } }
  
 Uint32 IDFactory::getNext()  Uint32 IDFactory::getID() const
 { {
     IDFactoryRep* rep = (IDFactoryRep*)_rep;      PEGASUS_DEBUG_ASSERT(_magic);
   
       IDFactory* self = (IDFactory*)this;
  
     PEGASUS_ASSERT(rep->magic == PEGASUS_IDFACTORY_MAGIC);      Uint32 id;
  
     rep->mutex.lock();      self->_mutex.lock();
     Uint32 tmp = rep->next++;      {
     rep->mutex.unlock();          if (_pool.isEmpty())
           {
               if (self->_nextID < _firstID)
                   self->_nextID = _firstID;
  
     return tmp;              id = self->_nextID++;
           }
           else
           {
               id = _pool.top();
               self->_pool.pop();
           }
       }
       self->_mutex.unlock();
   
       return id;
   }
   
   void IDFactory::putID(Uint32 id)
   {
       PEGASUS_DEBUG_ASSERT(_magic);
       PEGASUS_DEBUG_ASSERT(id >= _firstID);
   
       if (id < _firstID)
           return;
   
       _mutex.lock();
       {
           _pool.push(id);
       }
       _mutex.unlock();
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.8

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2