idPool.h

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQBASE_IDPOOL_H
00019 #define EQBASE_IDPOOL_H
00020 
00021 #include <eq/base/base.h>
00022 #include <eq/base/nonCopyable.h>
00023 #include <eq/base/thread.h>
00024 
00025 #include <list>
00026 
00027 namespace eq
00028 {
00029 namespace base
00030 {
00031 #   define EQ_ID_NONE    0xfffffffdu 
00032 #   define EQ_ID_INVALID 0xfffffffeu 
00033 #   define EQ_ID_ANY     0xffffffffu 
00034 
00035 
00042     class IDPool : public NonCopyable
00043     {
00044     public:
00045         enum MaxCapacity
00046         {
00047             MAX_CAPACITY =  0xfffffff0u
00048         };
00049 
00057         IDPool( const uint32_t initialCapacity );
00058 
00060         ~IDPool();
00061         
00070         uint32_t genIDs( const uint32_t range );
00071 
00078         void freeIDs( const uint32_t start, const uint32_t range );
00079 
00080 
00081     private:
00082         struct Block
00083         {
00084             uint32_t start;
00085             uint32_t range;
00086         };
00087 
00088         std::list<Block*> _freeIDs;
00089         std::list<Block*> _blockCache;
00090 
00091         Lock _lock;
00092 
00093         uint32_t _genIDs( const uint32_t range );
00094         uint32_t _compressCounter;
00095         void _compressIDs();
00096     };
00097 }
00098 
00099 }
00100 #endif //EQBASE_IDPOOL_H
Generated on Mon Aug 10 18:58:39 2009 for Equalizer 0.9 by  doxygen 1.5.8