2022-08-11 15:36:19 -04:00
|
|
|
//$file${include::qequeue.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
|
|
//
|
|
|
|
// Model: qpcpp.qm
|
|
|
|
// File: ${include::qequeue.hpp}
|
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// This code has been generated by QM 7.0.0 <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.
|
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
|
2022-04-19 19:23:30 -04:00
|
|
|
//
|
2023-01-19 21:14:02 -05:00
|
|
|
// Q u a n t u m L e a P s
|
|
|
|
// ------------------------
|
|
|
|
// Modern Embedded Software
|
|
|
|
//
|
2022-04-19 19:23:30 -04:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
|
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// The QP/C++ software is dual-licensed under the terms of the open-source
|
|
|
|
// GNU General Public License (GPL) or under the terms of one of the closed-
|
|
|
|
// source Quantum Leaps commercial licenses.
|
2022-04-19 19:23:30 -04:00
|
|
|
//
|
|
|
|
// Redistributions in source code must retain this top-level comment block.
|
|
|
|
// Plagiarizing this software to sidestep the license obligations is illegal.
|
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// NOTE:
|
|
|
|
// The GPL does NOT permit the incorporation of this code into proprietary
|
|
|
|
// programs. Please contact Quantum Leaps for commercial licensing options,
|
|
|
|
// which expressly supersede the GPL and are designed explicitly for
|
|
|
|
// closed-source distribution.
|
|
|
|
//
|
|
|
|
// Quantum Leaps contact information:
|
2022-08-11 15:36:19 -04:00
|
|
|
// <www.state-machine.com/licensing>
|
2022-04-19 19:23:30 -04:00
|
|
|
// <info@state-machine.com>
|
2022-08-11 15:36:19 -04:00
|
|
|
//
|
|
|
|
//$endhead${include::qequeue.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-01-19 21:14:02 -05:00
|
|
|
#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;
|
2012-08-14 18:00:48 -04:00
|
|
|
#else
|
2024-10-15 13:15:28 -04:00
|
|
|
#error "QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U or 2U"
|
2012-08-14 18:00:48 -04:00
|
|
|
#endif
|
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
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;
|
2024-10-15 13:15:28 -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;
|
2024-10-15 13:15:28 -04:00
|
|
|
|
|
|
|
#ifndef Q_UNSAFE
|
|
|
|
std::uintptr_t m_frontEvt_dis;
|
|
|
|
#endif // ndef Q_UNSAFE
|
|
|
|
|
|
|
|
#ifndef Q_UNSAFE
|
|
|
|
QEQueueCtr m_head_dis;
|
|
|
|
#endif // ndef Q_UNSAFE
|
|
|
|
|
|
|
|
#ifndef Q_UNSAFE
|
|
|
|
QEQueueCtr m_tail_dis;
|
|
|
|
#endif // ndef Q_UNSAFE
|
|
|
|
|
|
|
|
#ifndef Q_UNSAFE
|
|
|
|
QEQueueCtr m_nFree_dis;
|
|
|
|
#endif // ndef Q_UNSAFE
|
2012-08-14 18:00:48 -04:00
|
|
|
QEQueueCtr m_nMin;
|
2023-01-19 21:14:02 -05:00
|
|
|
|
|
|
|
// 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:
|
2023-01-19 21:14:02 -05:00
|
|
|
QEQueue() noexcept
|
|
|
|
: m_frontEvt(nullptr),
|
|
|
|
m_ring(nullptr),
|
|
|
|
m_end(0U),
|
|
|
|
m_head(0U),
|
|
|
|
m_tail(0U),
|
|
|
|
m_nFree(0U),
|
2024-10-15 13:15:28 -04:00
|
|
|
#ifndef Q_UNSAFE
|
|
|
|
m_frontEvt_dis(static_cast<std::uintptr_t>(~0U)),
|
|
|
|
m_head_dis(static_cast<QEQueueCtr>(~0U)),
|
|
|
|
m_tail_dis(static_cast<QEQueueCtr>(~0U)),
|
|
|
|
m_nFree_dis(static_cast<QEQueueCtr>(~0U)),
|
|
|
|
#endif
|
2023-01-19 21:14:02 -05:00
|
|
|
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 {
|
2024-10-15 13:15:28 -04:00
|
|
|
#ifndef Q_UNSAFE
|
2017-08-21 18:21:15 -04:00
|
|
|
return m_nMin;
|
2024-10-15 13:15:28 -04:00
|
|
|
#else
|
|
|
|
return 0U;
|
|
|
|
#endif
|
2017-08-21 18:21:15 -04:00
|
|
|
}
|
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
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
#endif // QEQUEUE_HPP_
|