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

 1 mike  1.2 
 2           //%2006////////////////////////////////////////////////////////////////////////
 3           //
 4           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 5           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 6           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
 7           // IBM Corp.; EMC Corporation, The Open Group.
 8           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
 9           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
10           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
11           // EMC Corporation; VERITAS Software Corporation; The Open Group.
12           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
13           // EMC Corporation; Symantec Corporation; The Open Group.
14           //
15           // Permission is hereby granted, free of charge, to any person obtaining a copy
16           // of this software and associated documentation files (the "Software"), to
17           // deal in the Software without restriction, including without limitation the
18           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19           // sell copies of the Software, and to permit persons to whom the Software is
20           // furnished to do so, subject to the following conditions:
21           // 
22 mike  1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
23           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
24           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
26           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30           //
31           //==============================================================================
32           //
33           //%/////////////////////////////////////////////////////////////////////////////
34           
35           #include <new>
36           #include "IDFactory.h"
37           
38           PEGASUS_NAMESPACE_BEGIN
39           
40           IDFactory::IDFactory(Uint32 firstID) : _firstID(firstID), _nextID(_firstID)
41           {
42           }
43 mike  1.2 
44           IDFactory::~IDFactory()
45           {
46               PEGASUS_DEBUG_ASSERT(_magic);
47           }
48           
49           Uint32 IDFactory::getID() const
50           {
51               PEGASUS_DEBUG_ASSERT(_magic);
52           
53               IDFactory* self = (IDFactory*)this;
54           
55               Uint32 id;
56           
57               self->_mutex.lock();
58               {
59 kumpf 1.3         if (_pool.isEmpty())
60                   {
61                       if (self->_nextID < _firstID)
62                           self->_nextID = _firstID;
63           
64                       id = self->_nextID++;
65                   }
66                   else
67                   {
68                       id = _pool.top();
69                       self->_pool.pop();
70                   }
71 mike  1.2     }
72               self->_mutex.unlock();
73           
74               return id;
75           }
76           
77           void IDFactory::putID(Uint32 id)
78           {
79               PEGASUS_DEBUG_ASSERT(_magic);
80               PEGASUS_DEBUG_ASSERT(id >= _firstID);
81           
82               if (id < _firstID)
83 kumpf 1.3         return;
84 mike  1.2 
85               _mutex.lock();
86               {
87 kumpf 1.3         _pool.push(id);
88 mike  1.2     }
89               _mutex.unlock();
90           }
91           
92           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2