|
QP/C++
|
00001 00002 // Product: QP/C++ 00003 // Last Updated for Version: 4.5.02 00004 // Date of the Last Update: Jul 02, 2012 00005 // 00006 // Q u a n t u m L e a P s 00007 // --------------------------- 00008 // innovating embedded systems 00009 // 00010 // Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved. 00011 // 00012 // This program is open source software: you can redistribute it and/or 00013 // modify it under the terms of the GNU General Public License as published 00014 // by the Free Software Foundation, either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // Alternatively, this program may be distributed and modified under the 00018 // terms of Quantum Leaps commercial licenses, which expressly supersede 00019 // the GNU General Public License and are specifically designed for 00020 // licensees interested in retaining the proprietary status of their code. 00021 // 00022 // This program is distributed in the hope that it will be useful, 00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 // GNU General Public License for more details. 00026 // 00027 // You should have received a copy of the GNU General Public License 00028 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00029 // 00030 // Contact information: 00031 // Quantum Leaps Web sites: http://www.quantum-leaps.com 00032 // http://www.state-machine.com 00033 // e-mail: info@quantum-leaps.com 00035 #ifndef qmpool_h 00036 #define qmpool_h 00037 00044 00045 #ifndef QF_MPOOL_SIZ_SIZE 00046 00047 00048 #define QF_MPOOL_SIZ_SIZE 2 00049 #endif 00050 00051 #ifndef QF_MPOOL_CTR_SIZE 00052 00055 #define QF_MPOOL_CTR_SIZE 2 00056 #endif 00057 00059 QP_BEGIN_ 00060 00061 #if (QF_MPOOL_SIZ_SIZE == 1) 00062 00063 00064 00065 00066 00067 typedef uint8_t QMPoolSize; 00068 #elif (QF_MPOOL_SIZ_SIZE == 2) 00069 00070 typedef uint16_t QMPoolSize; 00071 #elif (QF_MPOOL_SIZ_SIZE == 4) 00072 typedef uint32_t QMPoolSize; 00073 #else 00074 #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1, 2, or 4" 00075 #endif 00076 00077 #if (QF_MPOOL_CTR_SIZE == 1) 00078 00079 00080 00081 00082 00083 typedef uint8_t QMPoolCtr; 00084 #elif (QF_MPOOL_CTR_SIZE == 2) 00085 typedef uint16_t QMPoolCtr; 00086 #elif (QF_MPOOL_CTR_SIZE == 4) 00087 typedef uint32_t QMPoolCtr; 00088 #else 00089 #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1, 2, or 4" 00090 #endif 00091 00105 class QMPool { 00106 private: 00107 00109 void *m_start; 00110 00112 void *m_end; 00113 00115 void *m_free; 00116 00118 QMPoolSize m_blockSize; 00119 00121 QMPoolCtr m_nTot; 00122 00124 QMPoolCtr m_nFree; 00125 00131 QMPoolCtr m_nMin; 00132 00133 public: 00134 00152 void init(void * const poolSto, uint32_t const poolSize, 00153 QMPoolSize const blockSize); 00154 00173 void *get(void); 00174 00189 void put(void * const b); 00190 00192 QMPoolSize getBlockSize(void) const { 00193 return m_blockSize; 00194 } 00195 00196 private: 00197 friend class QF; 00198 }; 00199 00200 QP_END_ 00201 00205 #define QF_MPOOL_EL(type_) \ 00206 struct { void *sto_[((sizeof(type_) - 1U)/sizeof(void*)) + 1U]; } 00207 00208 #endif // qmpool_h
1.7.6.1