(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.2 and 1.1.2.8

version 1.1.2.2, 2006/06/30 19:40:54 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::getID() const
   {
 Uint32 IDFactory::getNext()      PEGASUS_DEBUG_ASSERT(_magic);
 {  
     IDFactoryRep* rep = (IDFactoryRep*)_rep;      IDFactory* self = (IDFactory*)this;
   
     if (rep->magic != PEGASUS_IDFACTORY_MAGIC)      Uint32 id;
     {  
         fprintf(stderr,      self->_mutex.lock();
             "**************************************************************\n"      {
             "**************************************************************\n"          if (_pool.isEmpty())
             "**************************************************************\n"          {
             "**************************************************************\n"              if (self->_nextID < _firstID)
             "**************************************************************\n"                  self->_nextID = _firstID;
             "**************************************************************\n"  
             "**************************************************************\n"              id = self->_nextID++;
             "**************************************************************\n"          }
             "**************************************************************\n"          else
             "**************************************************************\n"          {
             "*** WARNING: IDFactory::getNext(): using destructed object ***\n"              id = _pool.top();
             "**************************************************************\n"              self->_pool.pop();
             "**************************************************************\n"          }
             "**************************************************************\n"      }
             "**************************************************************\n"      self->_mutex.unlock();
             "**************************************************************\n"  
             "**************************************************************\n"      return id;
             "**************************************************************\n"  }
             "**************************************************************\n"  
             "**************************************************************\n"  
             "**************************************************************\n");  
     }  
   
     rep->mutex.lock();  
     Uint32 tmp = rep->next++;  
     rep->mutex.unlock();  
  
     return tmp;  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.2  
changed lines
  Added in v.1.1.2.8

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2