mirror of
https://github.com/QuantumLeaps/qpcpp.git
synced 2025-01-14 05:42:57 +08:00
174 lines
4.7 KiB
C++
174 lines
4.7 KiB
C++
//$file${include::qmpool.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
//
|
|
// Model: qpcpp.qm
|
|
// File: ${include::qmpool.hpp}
|
|
//
|
|
// This code has been generated by QM 7.0.0 <www.state-machine.com/qm>.
|
|
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
|
//
|
|
// 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
|
|
//
|
|
// 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.
|
|
//
|
|
// Redistributions in source code must retain this top-level comment block.
|
|
// Plagiarizing this software to sidestep the license obligations is illegal.
|
|
//
|
|
// 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:
|
|
// <www.state-machine.com/licensing>
|
|
// <info@state-machine.com>
|
|
//
|
|
//$endhead${include::qmpool.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
#ifndef QMPOOL_HPP_
|
|
#define QMPOOL_HPP_
|
|
|
|
#ifndef QF_MPOOL_SIZ_SIZE
|
|
#define QF_MPOOL_SIZ_SIZE 2U
|
|
#endif
|
|
#ifndef QF_MPOOL_CTR_SIZE
|
|
#define QF_MPOOL_CTR_SIZE 2U
|
|
#endif
|
|
|
|
namespace QP {
|
|
|
|
#if (QF_MPOOL_SIZ_SIZE == 1U)
|
|
using QMPoolSize = std::uint8_t;
|
|
#elif (QF_MPOOL_SIZ_SIZE == 2U)
|
|
using QMPoolSize = std::uint16_t;
|
|
#elif (QF_MPOOL_SIZ_SIZE == 4U)
|
|
using QMPoolSize = std::uint32_t;
|
|
#else
|
|
#error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U"
|
|
#endif
|
|
|
|
#if (QF_MPOOL_CTR_SIZE == 1U)
|
|
using QMPoolCtr = std::uint8_t;
|
|
#elif (QF_MPOOL_CTR_SIZE == 2U)
|
|
using QMPoolCtr = std::uint16_t;
|
|
#elif (QF_MPOOL_CTR_SIZE == 4U)
|
|
using QMPoolCtr = std::uint32_t;
|
|
#else
|
|
#error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
|
|
#endif
|
|
|
|
} // namespace QP
|
|
|
|
#define QF_MPOOL_EL(evType_) struct { \
|
|
QP::QFreeBlock sto_[((sizeof(evType_) - 1U) / (2U * sizeof(void *))) + 1U]; \
|
|
}
|
|
|
|
//$declare${QF::QFreeBlock} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
namespace QP {
|
|
|
|
//${QF::QFreeBlock} ..........................................................
|
|
class QFreeBlock {
|
|
private:
|
|
QFreeBlock * m_next;
|
|
|
|
#ifndef Q_UNSAFE
|
|
std::uintptr_t m_next_dis;
|
|
#endif // ndef Q_UNSAFE
|
|
friend class QMPool;
|
|
}; // class QFreeBlock
|
|
|
|
} // namespace QP
|
|
//$enddecl${QF::QFreeBlock} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
//$declare${QF::QMPool} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
namespace QP {
|
|
|
|
//${QF::QMPool} ..............................................................
|
|
class QMPool {
|
|
private:
|
|
QFreeBlock * m_start;
|
|
QFreeBlock * m_end;
|
|
QFreeBlock * volatile m_free_head;
|
|
QMPoolSize m_blockSize;
|
|
QMPoolCtr m_nTot;
|
|
QMPoolCtr volatile m_nFree;
|
|
|
|
#ifndef Q_UNSAFE
|
|
QMPoolCtr m_nMin;
|
|
#endif // ndef Q_UNSAFE
|
|
|
|
#ifndef Q_UNSAFE
|
|
std::uintptr_t m_free_head_dis;
|
|
#endif // ndef Q_UNSAFE
|
|
|
|
#ifndef Q_UNSAFE
|
|
QMPoolCtr m_nFree_dis;
|
|
#endif // ndef Q_UNSAFE
|
|
|
|
public:
|
|
QMPool()
|
|
: m_start(nullptr),
|
|
m_end(nullptr),
|
|
m_free_head(nullptr),
|
|
m_blockSize(0U),
|
|
m_nTot(0U),
|
|
m_nFree(0U)
|
|
#ifndef Q_UNSAFE
|
|
,m_nMin(0U),
|
|
m_free_head_dis(static_cast<std::uintptr_t>(~0U)),
|
|
m_nFree_dis(static_cast<QEQueueCtr>(~0U))
|
|
#endif
|
|
{}
|
|
void init(
|
|
void * const poolSto,
|
|
std::uint_fast32_t const poolSize,
|
|
std::uint_fast16_t const blockSize) noexcept;
|
|
void * get(
|
|
std::uint_fast16_t const margin,
|
|
std::uint_fast8_t const qsId) noexcept;
|
|
void put(
|
|
void * const block,
|
|
std::uint_fast8_t const qsId) noexcept;
|
|
QMPoolSize getBlockSize() const noexcept;
|
|
QMPoolCtr getNMin() const noexcept {
|
|
#ifndef Q_UNSAFE
|
|
return m_nMin;
|
|
#else
|
|
return 0U;
|
|
#endif
|
|
}
|
|
QMPoolCtr getNFree() const noexcept {
|
|
return m_nFree;
|
|
}
|
|
|
|
private:
|
|
QMPool(QEQueue const & other) = delete;
|
|
QMPool & operator=(QMPool const & other) = delete;
|
|
|
|
public:
|
|
|
|
#ifdef QF_ISR_API
|
|
void * getFromISR(
|
|
std::uint_fast16_t const margin,
|
|
std::uint_fast8_t const qsId) noexcept;
|
|
#endif // def QF_ISR_API
|
|
|
|
#ifdef QF_ISR_API
|
|
void putFromISR(
|
|
void * const b,
|
|
std::uint_fast8_t const qsId) noexcept;
|
|
#endif // def QF_ISR_API
|
|
}; // class QMPool
|
|
|
|
} // namespace QP
|
|
//$enddecl${QF::QMPool} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
#endif // QMPOOL_HPP_
|