qpcpp/include/qequeue.hpp

126 lines
3.6 KiB
C++
Raw Normal View History

2022-08-11 15:36:19 -04:00
//$file${include::qequeue.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: qpcpp.qm
// File: ${include::qequeue.hpp}
//
2024-01-17 07:50:09 -05:00
// This code has been generated by QM 6.1.1 <www.state-machine.com/qm>.
2022-08-11 15:36:19 -04:00
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
//
// This code is covered by the following QP license:
// License # : LicenseRef-QL-dual
// Issued to : Any user of the QP/C++ real-time embedded framework
// Framework(s) : qpcpp
// Support ends : 2024-12-31
2022-08-11 15:36:19 -04:00
// License scope:
//
// Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
//
// Q u a n t u m L e a P s
// ------------------------
// Modern Embedded Software
//
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
//
// This software is dual-licensed under the terms of the open source GNU
// General Public License version 3 (or any later version), or alternatively,
// under the terms of one of the closed source Quantum Leaps commercial
// licenses.
//
// The terms of the open source GNU General Public License version 3
// can be found at: <www.gnu.org/licenses/gpl-3.0>
//
// The terms of the closed source Quantum Leaps commercial licenses
// can be found at: <www.state-machine.com/licensing>
//
// Redistributions in source code must retain this top-level comment block.
// Plagiarizing this software to sidestep the license obligations is illegal.
//
// Contact information:
2022-08-11 15:36:19 -04:00
// <www.state-machine.com/licensing>
// <info@state-machine.com>
2022-08-11 15:36:19 -04:00
//
//$endhead${include::qequeue.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#ifndef QEQUEUE_HPP_
#define QEQUEUE_HPP_
2022-08-11 15:36:19 -04:00
2012-08-14 18:00:48 -04:00
#ifndef QF_EQUEUE_CTR_SIZE
2020-03-17 21:33:58 -04:00
#define QF_EQUEUE_CTR_SIZE 1U
2012-08-14 18:00:48 -04:00
#endif
2013-10-10 20:01:51 -04:00
namespace QP {
2012-08-14 18:00:48 -04:00
2020-03-17 21:33:58 -04:00
#if (QF_EQUEUE_CTR_SIZE == 1U)
using QEQueueCtr = std::uint8_t;
#elif (QF_EQUEUE_CTR_SIZE == 2U)
using QEQueueCtr = std::uint16_t;
#elif (QF_EQUEUE_CTR_SIZE == 4U)
using QEQueueCtr = std::uint32_t;
2012-08-14 18:00:48 -04:00
#else
2020-03-17 21:33:58 -04:00
#error "QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
2012-08-14 18:00:48 -04:00
#endif
class QEvt; // forward declaration
2022-08-11 15:36:19 -04:00
} // namespace QP
//$declare${QF::QEQueue} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
namespace QP {
//${QF::QEQueue} .............................................................
2012-08-14 18:00:48 -04:00
class QEQueue {
private:
2013-10-10 20:01:51 -04:00
QEvt const * volatile m_frontEvt;
2022-08-11 15:36:19 -04:00
QEvt const ** m_ring;
2012-08-14 18:00:48 -04:00
QEQueueCtr m_end;
2013-10-10 20:01:51 -04:00
QEQueueCtr volatile m_head;
QEQueueCtr volatile m_tail;
QEQueueCtr volatile m_nFree;
2012-08-14 18:00:48 -04:00
QEQueueCtr m_nMin;
// friends...
2022-08-11 15:36:19 -04:00
friend class QActive;
friend class QTicker;
2022-08-28 22:12:27 -04:00
friend class QXMutex;
2022-08-11 15:36:19 -04:00
friend class QXThread;
2012-08-14 18:00:48 -04:00
public:
QEQueue() noexcept
: m_frontEvt(nullptr),
m_ring(nullptr),
m_end(0U),
m_head(0U),
m_tail(0U),
m_nFree(0U),
m_nMin(0U)
{}
2022-08-11 15:36:19 -04:00
void init(
QEvt const * qSto[],
std::uint_fast16_t const qLen) noexcept;
bool post(
QEvt const * const e,
std::uint_fast16_t const margin,
2024-01-17 07:50:09 -05:00
std::uint_fast8_t const qsId) noexcept;
2022-08-11 15:36:19 -04:00
void postLIFO(
QEvt const * const e,
2024-01-17 07:50:09 -05:00
std::uint_fast8_t const qsId) noexcept;
QEvt const * get(std::uint_fast8_t const qsId) noexcept;
2022-08-11 15:36:19 -04:00
QEQueueCtr getNFree() const noexcept {
2012-08-14 18:00:48 -04:00
return m_nFree;
}
2022-08-11 15:36:19 -04:00
QEQueueCtr getNMin() const noexcept {
2017-08-21 18:21:15 -04:00
return m_nMin;
}
2022-08-11 15:36:19 -04:00
bool isEmpty() const noexcept {
2020-03-17 21:33:58 -04:00
return m_frontEvt == nullptr;
2012-12-10 16:01:54 -05:00
}
2012-08-14 18:00:48 -04:00
private:
2022-08-11 15:36:19 -04:00
QEQueue(QEQueue const & other) = delete;
QEQueue & operator=(QEQueue const & other) = delete;
}; // class QEQueue
2012-08-14 18:00:48 -04:00
2014-04-13 21:35:34 -04:00
} // namespace QP
2022-08-11 15:36:19 -04:00
//$enddecl${QF::QEQueue} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2012-08-14 18:00:48 -04:00
#endif // QEQUEUE_HPP_