qmpool.h

Go to the documentation of this file.
00001 
00002 // Product: QF/C++
00003 // Last Updated for Version: 4.0.00
00004 // Date of the Last Update:  Apr 06, 2008
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2008 Quantum Leaps, LLC. All rights reserved.
00011 //
00012 // This software may be distributed and modified under the terms of the GNU
00013 // General Public License version 2 (GPL) as published by the Free Software
00014 // Foundation and appearing in the file GPL.TXT included in the packaging of
00015 // this file. Please note that GPL Section 2[b] requires that all works based
00016 // on this software must also be made publicly available under the terms of
00017 // the GPL ("Copyleft").
00018 //
00019 // Alternatively, this software may be distributed and modified under the
00020 // terms of Quantum Leaps commercial licenses, which expressly supersede
00021 // the GPL and are specifically designed for licensees interested in
00022 // retaining the proprietary status of their code.
00023 //
00024 // Contact information:
00025 // Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 // e-mail:                  info@quantum-leaps.com
00028 #ifndef qmpool_h
00029 #define qmpool_h
00030 
00037 
00038 
00040 #ifndef QF_MPOOL_SIZ_SIZE
00043     #define QF_MPOOL_SIZ_SIZE 2
00044 #endif
00045 #if (QF_MPOOL_SIZ_SIZE == 1)
00046 
00052     typedef uint8_t QMPoolSize;
00053 #elif (QF_MPOOL_SIZ_SIZE == 2)
00054 
00055     typedef uint16_t QMPoolSize;
00056 #elif (QF_MPOOL_SIZ_SIZE == 4)
00057     typedef uint32_t QMPoolSize;
00058 #else
00059     #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1, 2, or 4"
00060 #endif
00061 
00063 #ifndef QF_MPOOL_CTR_SIZE
00064 
00067     #define QF_MPOOL_CTR_SIZE 2
00068 #endif
00069 #if (QF_MPOOL_CTR_SIZE == 1)
00070 
00076     typedef uint8_t QMPoolCtr;
00077 #elif (QF_MPOOL_CTR_SIZE == 2)
00078     typedef uint16_t QMPoolCtr;
00079 #elif (QF_MPOOL_CTR_SIZE == 4)
00080     typedef uint32_t QMPoolCtr;
00081 #else
00082     #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1, 2, or 4"
00083 #endif
00084 
00098 class QMPool {
00099 private:
00100 
00102     void *m_start;
00103 
00105     void *m_end;
00106 
00108     void *m_free;
00109 
00111     QMPoolSize m_blockSize;
00112 
00114     QMPoolCtr m_nTot;
00115 
00117     QMPoolCtr m_nFree;
00118 
00124     QMPoolCtr m_nMin;
00125 
00126 public:
00127 
00145     void init(void *poolSto, uint32_t poolSize, QMPoolSize blockSize);
00146 
00165     void *get(void);
00166 
00181     void put(void *b);
00182 
00184     QMPoolSize getBlockSize(void) const {
00185         return m_blockSize;
00186     }
00187 
00188 private:
00189     friend class QF;
00190 };
00191 
00192 #endif                                                             // qmpool_h

Generated on Sat Dec 27 21:35:26 2008 for QP/C++ by  doxygen 1.5.4