QP/C++  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qf_defer.cpp
Go to the documentation of this file.
1//$file${src::qf::qf_defer.cpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpcpp.qm
4// File: ${src::qf::qf_defer.cpp}
5//
6// This code has been generated by QM 7.0.0 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
10//
11// Q u a n t u m L e a P s
12// ------------------------
13// Modern Embedded Software
14//
15// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
16//
17// The QP/C++ software is dual-licensed under the terms of the open-source
18// GNU General Public License (GPL) or under the terms of one of the closed-
19// source Quantum Leaps commercial licenses.
20//
21// Redistributions in source code must retain this top-level comment block.
22// Plagiarizing this software to sidestep the license obligations is illegal.
23//
24// NOTE:
25// The GPL does NOT permit the incorporation of this code into proprietary
26// programs. Please contact Quantum Leaps for commercial licensing options,
27// which expressly supersede the GPL and are designed explicitly for
28// closed-source distribution.
29//
30// Quantum Leaps contact information:
31// <www.state-machine.com/licensing>
32// <info@state-machine.com>
33//
34//$endhead${src::qf::qf_defer.cpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35#define QP_IMPL // this is QP implementation
36#include "qp_port.hpp" // QP port
37#include "qp_pkg.hpp" // QP package-scope interface
38#include "qsafe.h" // QP Functional Safety (FuSa) Subsystem
39#ifdef Q_SPY // QS software tracing enabled?
40 #include "qs_port.hpp" // QS port
41 #include "qs_pkg.hpp" // QS facilities for pre-defined trace records
42#else
43 #include "qs_dummy.hpp" // disable the QS software tracing
44#endif // Q_SPY
45
46// unnamed namespace for local definitions with internal linkage
47namespace {
48Q_DEFINE_THIS_MODULE("qf_defer")
49} // unnamed namespace
50
51//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
52// Check for the minimum required QP version
53#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
54#error qpcpp version 7.3.0 or higher required
55#endif
56//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57//$define${QF::QActive::defer} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
58namespace QP {
59
60//${QF::QActive::defer} ......................................................
62 QEQueue * const eq,
63 QEvt const * const e) const noexcept
64{
65 bool const status = eq->post(e, 0U, m_prio);
66
69 QS_MEM_SYS();
70 QS_BEGIN_PRE(QS_QF_ACTIVE_DEFER, m_prio)
71 QS_TIME_PRE(); // time stamp
72 QS_OBJ_PRE(this); // this active object
73 QS_OBJ_PRE(eq); // the deferred queue
74 QS_SIG_PRE(e->sig); // the signal of the event
75 QS_2U8_PRE(e->getPoolNum_(), e->refCtr_);
77 QS_MEM_APP();
79
80 return status;
81}
82
83} // namespace QP
84//$enddef${QF::QActive::defer} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85
86//$define${QF::QActive::recall} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
87namespace QP {
88
89//${QF::QActive::recall} .....................................................
90bool QActive::recall(QEQueue * const eq) noexcept {
91 QEvt const * const e = eq->get(m_prio); // get evt from deferred queue
93
94 bool recalled;
95 if (e != nullptr) { // event available?
96 postLIFO(e); // post it to the _front_ of the AO's queue
97
99 QF_MEM_SYS();
100
101 if (e->getPoolNum_() != 0U) { // is it a mutable event?
102
103 // after posting to the AO's queue the event must be referenced
104 // at least twice: once in the deferred event queue (eq->get()
105 // did NOT decrement the reference counter) and once in the
106 // AO's event queue.
107 Q_ASSERT_INCRIT(210, e->refCtr_ >= 2U);
108
109 // we need to decrement the reference counter once, to account
110 // for removing the event from the deferred event queue.
111 QEvt_refCtr_dec_(e); // decrement the reference counter
112 }
113
114 QS_BEGIN_PRE(QS_QF_ACTIVE_RECALL, m_prio)
115 QS_TIME_PRE(); // time stamp
116 QS_OBJ_PRE(this); // this active object
117 QS_OBJ_PRE(eq); // the deferred queue
118 QS_SIG_PRE(e->sig); // the signal of the event
120 QS_END_PRE()
121
122 QF_MEM_APP();
123 QF_CRIT_EXIT();
124
125 recalled = true;
126 }
127 else {
129 QS_MEM_SYS();
130
131 QS_BEGIN_PRE(QS_QF_ACTIVE_RECALL_ATTEMPT, m_prio)
132 QS_TIME_PRE(); // time stamp
133 QS_OBJ_PRE(this); // this active object
134 QS_OBJ_PRE(eq); // the deferred queue
135 QS_END_PRE()
136
137 QS_MEM_APP();
138 QS_CRIT_EXIT();
139
140 recalled = false;
141 }
142 return recalled;
143}
144
145} // namespace QP
146//$enddef${QF::QActive::recall} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147
148//$define${QF::QActive::flushDeferred} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
149namespace QP {
150
151//${QF::QActive::flushDeferred} ..............................................
152std::uint_fast16_t QActive::flushDeferred(
153 QEQueue * const eq,
154 std::uint_fast16_t const num) const noexcept
155{
156 std::uint_fast16_t n = 0U;
157 while (n < num) {
158 QEvt const * const e = eq->get(m_prio);
159 if (e != nullptr) {
160 ++n; // count one more flushed event
161 #if (QF_MAX_EPOOL > 0U)
162 QF::gc(e); // garbage collect
163 #endif
164 }
165 else {
166 break;
167 }
168 }
169
170 return n;
171}
172
173} // namespace QP
174//$enddef${QF::QActive::flushDeferred} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bool defer(QEQueue *const eq, QEvt const *const e) const noexcept
Definition qf_defer.cpp:61
bool recall(QEQueue *const eq) noexcept
Definition qf_defer.cpp:90
std::uint_fast16_t flushDeferred(QEQueue *const eq, std::uint_fast16_t const num=0xFFFFU) const noexcept
Definition qf_defer.cpp:152
Native QP event queue.
Definition qequeue.hpp:60
Event class.
Definition qp.hpp:131
QSignal sig
Signal of the event (see Event Signal)
Definition qp.hpp:133
std::uint8_t volatile refCtr_
Event reference counter.)
Definition qp.hpp:135
std::uint_fast8_t getPoolNum_() const noexcept
Internal function to get the event pool-number of the given event.
Definition qp.hpp:159
void gc(QEvt const *const e) noexcept
Recycle a mutable (mutable) event.
Definition qf_dyn.cpp:213
QP/C++ framework.
Definition qequeue.hpp:42
void QEvt_refCtr_dec_(QEvt const *const e) noexcept
Decrement the refCtr of a const event (requires casting const away)
Definition qp_pkg.hpp:89
#define QF_MEM_APP()
Definition qp.hpp:1322
#define QF_MEM_SYS()
Definition qp.hpp:1317
Internal (package scope) QP/C++ interface.
Sample QP/C++ port.
#define QS_OBJ_PRE(obj_)
Definition qs_dummy.hpp:158
#define QS_CRIT_STAT
Definition qs_dummy.hpp:165
#define QS_SIG_PRE(sig_)
Definition qs_dummy.hpp:156
#define QS_TIME_PRE()
Definition qs_dummy.hpp:155
#define QS_MEM_APP()
Definition qs_dummy.hpp:170
#define QS_2U8_PRE(data1_, data2_)
Definition qs_dummy.hpp:152
#define QS_CRIT_EXIT()
Definition qs_dummy.hpp:167
#define QS_MEM_SYS()
Definition qs_dummy.hpp:169
#define QS_END_PRE()
Definition qs_dummy.hpp:150
#define QS_CRIT_ENTRY()
Definition qs_dummy.hpp:166
#define QS_BEGIN_PRE(rec_, qsId_)
Definition qs_dummy.hpp:149
QS/C++ port to a 32-bit CPU, generic C++ compiler.
QP Functional Safety (FuSa) Subsystem.
#define QF_CRIT_ENTRY()
Definition qsafe.h:58
#define Q_ASSERT_INCRIT(id_, expr_)
Definition qsafe.h:72
#define QF_CRIT_EXIT()
Definition qsafe.h:62
#define QF_CRIT_STAT
Definition qsafe.h:54