QP/C++
qequeue.h
Go to the documentation of this file.
00001 
00002 // Product: QP/C++
00003 // Last Updated for Version: 4.5.04
00004 // Date of the Last Update:  Jan 16, 2013
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2013 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 qequeue_h
00036 #define qequeue_h
00037 
00047 
00048 #ifndef QF_EQUEUE_CTR_SIZE
00049 
00057     #define QF_EQUEUE_CTR_SIZE 1
00058 #endif
00059 
00060 QP_BEGIN_
00061 
00062 #if (QF_EQUEUE_CTR_SIZE == 1)
00063 
00064 
00065 
00066 
00067 
00068     typedef uint8_t QEQueueCtr;
00069 #elif (QF_EQUEUE_CTR_SIZE == 2)
00070     typedef uint16_t QEQueueCtr;
00071 #elif (QF_EQUEUE_CTR_SIZE == 4)
00072     typedef uint32_t QEQueueCtr;
00073 #else
00074     #error "QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1, 2, or 4"
00075 #endif
00076 
00077 
00119 class QEQueue {
00120 private:
00121 
00132     QEvt const *m_frontEvt;
00133 
00135     QEvt const **m_ring;
00136 
00139     QEQueueCtr m_end;
00140 
00142     QEQueueCtr m_head;
00143 
00145     QEQueueCtr m_tail;
00146 
00148     QEQueueCtr m_nFree;
00149 
00155     QEQueueCtr m_nMin;
00156 
00157 public:
00158 
00167     void init(QEvt const *qSto[], QEQueueCtr const qLen);
00168 
00178     void postFIFO(QEvt const * const e);
00179 
00189     void postLIFO(QEvt const * const e);
00190 
00202     QEvt const *get(void);
00203 
00214     QEQueueCtr getNFree(void) const {
00215         return m_nFree;
00216     }
00217 
00228     bool isEmpty(void) const {
00229         return m_frontEvt == static_cast<QEvt const *>(0);
00230     }
00231 
00232 private:
00233     friend class QF;
00234     friend class QActive;
00235 };
00236 
00237 QP_END_
00238 
00239 #endif                                                            // qequeue_h
00240