QP/C++
qmpool.h
Go to the documentation of this file.
00001 
00002 // Product: QF/C++
00003 // Last Updated for Version: 4.2.00
00004 // Date of the Last Update:  Jul 05, 2011
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2011 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 #ifdef Q_USE_NAMESPACE
00039 namespace QP {
00040 #endif
00041 
00043 #ifndef QF_MPOOL_SIZ_SIZE
00044 
00045 
00046     #define QF_MPOOL_SIZ_SIZE 2
00047 #endif
00048 #if (QF_MPOOL_SIZ_SIZE == 1)
00049 
00055     typedef uint8_t QMPoolSize;
00056 #elif (QF_MPOOL_SIZ_SIZE == 2)
00057 
00058     typedef uint16_t QMPoolSize;
00059 #elif (QF_MPOOL_SIZ_SIZE == 4)
00060     typedef uint32_t QMPoolSize;
00061 #else
00062     #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1, 2, or 4"
00063 #endif
00064 
00066 #ifndef QF_MPOOL_CTR_SIZE
00067 
00070     #define QF_MPOOL_CTR_SIZE 2
00071 #endif
00072 #if (QF_MPOOL_CTR_SIZE == 1)
00073 
00079     typedef uint8_t QMPoolCtr;
00080 #elif (QF_MPOOL_CTR_SIZE == 2)
00081     typedef uint16_t QMPoolCtr;
00082 #elif (QF_MPOOL_CTR_SIZE == 4)
00083     typedef uint32_t QMPoolCtr;
00084 #else
00085     #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1, 2, or 4"
00086 #endif
00087 
00101 class QMPool {
00102 private:
00103 
00105     void *m_start;
00106 
00108     void *m_end;
00109 
00111     void *m_free;
00112 
00114     QMPoolSize m_blockSize;
00115 
00117     QMPoolCtr m_nTot;
00118 
00120     QMPoolCtr m_nFree;
00121 
00127     QMPoolCtr m_nMin;
00128 
00129 public:
00130 
00148     void init(void *poolSto, uint32_t poolSize, QMPoolSize blockSize);
00149 
00168     void *get(void);
00169 
00184     void put(void *b);
00185 
00187     QMPoolSize getBlockSize(void) const {
00188         return m_blockSize;
00189     }
00190 
00191 private:
00192     friend class QF;
00193 };
00194 
00195 #ifdef Q_USE_NAMESPACE
00196 }                                                              // namespace QP
00197 #endif
00198 
00199 #endif                                                             // qmpool_h