qpcpp/include/qequeue.hpp

112 lines
3.1 KiB
C++
Raw Normal View History

2025-01-18 18:33:40 -05:00
//============================================================================
// QP/C++ Real-Time Embedded Framework (RTEF)
// Version 8.0.2
2022-08-11 15:36:19 -04:00
//
2024-10-15 13:15:28 -04:00
// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
//
// 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
//
2025-01-18 18:33:40 -05:00
// This 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-
2024-10-15 13:15:28 -04:00
// source Quantum Leaps commercial licenses.
//
// 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>
// <info@state-machine.com>
2025-01-18 18:33:40 -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
2025-01-18 18:33:40 -05:00
#error QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U or 2U
2012-08-14 18:00:48 -04:00
#endif
class QEvt; // forward declaration
2022-08-11 15:36:19 -04:00
} // namespace QP
2025-01-18 18:33:40 -05:00
//============================================================================
2022-08-11 15:36:19 -04:00
namespace QP {
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;
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(
2025-01-18 18:33:40 -05:00
QEvt const * * const qSto,
2022-08-11 15:36:19 -04:00
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;
2025-01-18 18:33:40 -05:00
void postFIFO_(
QEvt const * const e,
void const * const sender);
2022-08-11 15:36:19 -04:00
}; // class QEQueue
2012-08-14 18:00:48 -04:00
2014-04-13 21:35:34 -04:00
} // namespace QP
2012-08-14 18:00:48 -04:00
#endif // QEQUEUE_HPP_