QP/C++  7.4.0-rc.1
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 6.1.1 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// This code is covered by the following QP license:
10// License # : LicenseRef-QL-dual
11// Issued to : Any user of the QP/C++ real-time embedded framework
12// Framework(s) : qpcpp
13// Support ends : 2024-12-31
14// License scope:
15//
16// Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
17//
18// Q u a n t u m L e a P s
19// ------------------------
20// Modern Embedded Software
21//
22// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
23//
24// This software is dual-licensed under the terms of the open source GNU
25// General Public License version 3 (or any later version), or alternatively,
26// under the terms of one of the closed source Quantum Leaps commercial
27// licenses.
28//
29// The terms of the open source GNU General Public License version 3
30// can be found at: <www.gnu.org/licenses/gpl-3.0>
31//
32// The terms of the closed source Quantum Leaps commercial licenses
33// can be found at: <www.state-machine.com/licensing>
34//
35// Redistributions in source code must retain this top-level comment block.
36// Plagiarizing this software to sidestep the license obligations is illegal.
37//
38// Contact information:
39// <www.state-machine.com/licensing>
40// <info@state-machine.com>
41//
42//$endhead${src::qf::qf_defer.cpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43#define QP_IMPL // this is QP implementation
44#include "qp_port.hpp" // QP port
45#include "qp_pkg.hpp" // QP package-scope interface
46#include "qsafe.h" // QP Functional Safety (FuSa) Subsystem
47#ifdef Q_SPY // QS software tracing enabled?
48 #include "qs_port.hpp" // QS port
49 #include "qs_pkg.hpp" // QS facilities for pre-defined trace records
50#else
51 #include "qs_dummy.hpp" // disable the QS software tracing
52#endif // Q_SPY
53
54// unnamed namespace for local definitions with internal linkage
55namespace {
56Q_DEFINE_THIS_MODULE("qf_defer")
57} // unnamed namespace
58
59//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
60// Check for the minimum required QP version
61#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
62#error qpcpp version 7.3.0 or higher required
63#endif
64//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
65
66//$define${QF::QActive::defer} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
67namespace QP {
68
69//${QF::QActive::defer} ......................................................
71 QEQueue * const eq,
72 QEvt const * const e) const noexcept
73{
74 bool const status = eq->post(e, 0U, m_prio);
75
78 QS_MEM_SYS();
79 QS_BEGIN_PRE_(QS_QF_ACTIVE_DEFER, m_prio)
80 QS_TIME_PRE_(); // time stamp
81 QS_OBJ_PRE_(this); // this active object
82 QS_OBJ_PRE_(eq); // the deferred queue
83 QS_SIG_PRE_(e->sig); // the signal of the event
84 QS_2U8_PRE_(e->getPoolNum_(), e->refCtr_); // poolNum & refCtr
85 QS_END_PRE_()
86 QS_MEM_APP();
88
89 return status;
90}
91
92} // namespace QP
93//$enddef${QF::QActive::defer} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94
95//$define${QF::QActive::recall} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
96namespace QP {
97
98//${QF::QActive::recall} .....................................................
99bool QActive::recall(QEQueue * const eq) noexcept {
100 QEvt const * const e = eq->get(m_prio); // get evt from deferred queue
102
103 bool recalled;
104 if (e != nullptr) { // event available?
105 postLIFO(e); // post it to the _front_ of the AO's queue
106
108 QF_MEM_SYS();
109
110 if (e->getPoolNum_() != 0U) { // is it a mutable event?
111
112 // after posting to the AO's queue the event must be referenced
113 // at least twice: once in the deferred event queue (eq->get()
114 // did NOT decrement the reference counter) and once in the
115 // AO's event queue.
116 Q_ASSERT_INCRIT(210, e->refCtr_ >= 2U);
117
118 // we need to decrement the reference counter once, to account
119 // for removing the event from the deferred event queue.
120 QEvt_refCtr_dec_(e); // decrement the reference counter
121 }
122
123 QS_BEGIN_PRE_(QS_QF_ACTIVE_RECALL, m_prio)
124 QS_TIME_PRE_(); // time stamp
125 QS_OBJ_PRE_(this); // this active object
126 QS_OBJ_PRE_(eq); // the deferred queue
127 QS_SIG_PRE_(e->sig); // the signal of the event
128 QS_2U8_PRE_(e->getPoolNum_(), e->refCtr_); // poolNum & refCtr
129 QS_END_PRE_()
130
131 QF_MEM_APP();
132 QF_CRIT_EXIT();
133
134 recalled = true;
135 }
136 else {
138 QS_MEM_SYS();
139
140 QS_BEGIN_PRE_(QS_QF_ACTIVE_RECALL_ATTEMPT, m_prio)
141 QS_TIME_PRE_(); // time stamp
142 QS_OBJ_PRE_(this); // this active object
143 QS_OBJ_PRE_(eq); // the deferred queue
144 QS_END_PRE_()
145
146 QS_MEM_APP();
147 QS_CRIT_EXIT();
148
149 recalled = false;
150 }
151 return recalled;
152}
153
154} // namespace QP
155//$enddef${QF::QActive::recall} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156
157//$define${QF::QActive::flushDeferred} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
158namespace QP {
159
160//${QF::QActive::flushDeferred} ..............................................
161std::uint_fast16_t QActive::flushDeferred(
162 QEQueue * const eq,
163 std::uint_fast16_t const num) const noexcept
164{
165 std::uint_fast16_t n = 0U;
166 while (n < num) {
167 QEvt const * const e = eq->get(m_prio);
168 if (e != nullptr) {
169 ++n; // count one more flushed event
170 #if (QF_MAX_EPOOL > 0U)
171 QF::gc(e); // garbage collect
172 #endif
173 }
174 else {
175 break;
176 }
177 }
178
179 return n;
180}
181
182} // namespace QP
183//$enddef${QF::QActive::flushDeferred} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bool defer(QEQueue *const eq, QEvt const *const e) const noexcept
Definition qf_defer.cpp:70
bool recall(QEQueue *const eq) noexcept
Definition qf_defer.cpp:99
std::uint_fast16_t flushDeferred(QEQueue *const eq, std::uint_fast16_t const num=0xFFFFU) const noexcept
Definition qf_defer.cpp:161
Native QP event queue.
Definition qequeue.hpp:70
Event class.
Definition qp.hpp:137
QSignal sig
Definition qp.hpp:139
std::uint8_t volatile refCtr_
Definition qp.hpp:140
std::uint_fast8_t getPoolNum_() const noexcept
Definition qp.hpp:165
void gc(QEvt const *const e) noexcept
Definition qf_dyn.cpp:222
QP/C++ framework.
Definition qequeue.hpp:50
void QEvt_refCtr_dec_(QEvt const *const e) noexcept
Decrement the refCtr of a const event (requires casting const away)
Definition qp_pkg.hpp:96
@ QS_QF_ACTIVE_RECALL
AO recalled an event.
Definition qs.hpp:86
@ QS_QF_ACTIVE_RECALL_ATTEMPT
AO attempted to recall an event.
Definition qs.hpp:93
@ QS_QF_ACTIVE_DEFER
AO deferred an event.
Definition qs.hpp:85
#define QF_MEM_APP()
Definition qp.hpp:1331
#define QF_MEM_SYS()
Definition qp.hpp:1326
Internal (package scope) QP/C++ interface.
Sample QP/C++ port.
#define QS_CRIT_STAT
Definition qs.hpp:590
#define QS_TIME_PRE_()
Definition qs.hpp:473
#define QS_MEM_APP()
Definition qs.hpp:610
#define QS_CRIT_EXIT()
Definition qs.hpp:600
#define QS_MEM_SYS()
Definition qs.hpp:605
#define QS_CRIT_ENTRY()
Definition qs.hpp:595
QS/C++ package-scope interface.
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