QP/C  7.4.0-rc.3
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qf_defer.c
Go to the documentation of this file.
1//$file${src::qf::qf_defer.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpc.qm
4// File: ${src::qf::qf_defer.c}
5//
6// This code has been generated by QM 6.2.0 <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) : qpc
13// Support ends : 2025-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.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43#define QP_IMPL // this is QP implementation
44#include "qp_port.h" // QP port
45#include "qp_pkg.h" // 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.h" // QS port
49 #include "qs_pkg.h" // QS facilities for pre-defined trace records
50#else
51 #include "qs_dummy.h" // disable the QS software tracing
52#endif // Q_SPY
53
54Q_DEFINE_THIS_MODULE("qf_defer")
55
56//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
57// Check for the minimum required QP version
58#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
59#error qpc version 7.3.0 or higher required
60#endif
61//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62//$define${QF::QActive::defer} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
63
64//${QF::QActive::defer} ......................................................
65//! @protected @memberof QActive
66bool QActive_defer(QActive const * const me,
67 struct QEQueue * const eq,
68 QEvt const * const e)
69{
70 bool const status = QEQueue_post(eq, e, 0U, me->prio);
71
74 QS_MEM_SYS();
75 QS_BEGIN_PRE_(QS_QF_ACTIVE_DEFER, me->prio)
76 QS_TIME_PRE_(); // time stamp
77 QS_OBJ_PRE_(me); // this active object
78 QS_OBJ_PRE_(eq); // the deferred queue
79 QS_SIG_PRE_(e->sig); // the signal of the event
80 QS_2U8_PRE_(QEvt_getPoolNum_(e), e->refCtr_); // poolNum & refCtr
81 QS_END_PRE_()
82 QS_MEM_APP();
84
85 return status;
86}
87//$enddef${QF::QActive::defer} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88//$define${QF::QActive::recall} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
89
90//${QF::QActive::recall} .....................................................
91//! @protected @memberof QActive
92bool QActive_recall(QActive * const me,
93 struct QEQueue * const eq)
94{
95 QEvt const * const e = QEQueue_get(eq, me->prio);
97
98 bool recalled;
99 if (e != (QEvt *)0) { // event available?
100 QACTIVE_POST_LIFO(me, e); // post it to the front of the AO's queue
101
103 QF_MEM_SYS();
104
105 if (QEvt_getPoolNum_(e) != 0U) { // is it a mutable event?
106
107 // after posting to the AO's queue the event must be referenced
108 // at least twice: once in the deferred event queue (eq->get()
109 // did NOT decrement the reference counter) and once in the
110 // AO's event queue.
111 Q_ASSERT_INCRIT(210, e->refCtr_ >= 2U);
112
113 // we need to decrement the reference counter once, to account
114 // for removing the event from the deferred event queue.
115 QEvt_refCtr_dec_(e); // decrement the reference counter
116 }
117
118 QS_BEGIN_PRE_(QS_QF_ACTIVE_RECALL, me->prio)
119 QS_TIME_PRE_(); // time stamp
120 QS_OBJ_PRE_(me); // this active object
121 QS_OBJ_PRE_(eq); // the deferred queue
122 QS_SIG_PRE_(e->sig); // the signal of the event
123 QS_2U8_PRE_(QEvt_getPoolNum_(e), e->refCtr_); // poolNum & refCtr
124 QS_END_PRE_()
125
126 QF_MEM_APP();
127 QF_CRIT_EXIT();
128
129 recalled = true;
130 }
131 else {
133 QS_MEM_SYS();
134
135 QS_BEGIN_PRE_(QS_QF_ACTIVE_RECALL_ATTEMPT, me->prio)
136 QS_TIME_PRE_(); // time stamp
137 QS_OBJ_PRE_(me); // this active object
138 QS_OBJ_PRE_(eq); // the deferred queue
139 QS_END_PRE_()
140
141 QS_MEM_APP();
142 QS_CRIT_EXIT();
143
144 recalled = false;
145 }
146 return recalled;
147}
148//$enddef${QF::QActive::recall} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149//$define${QF::QActive::flushDeferred} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
150
151//${QF::QActive::flushDeferred} ..............................................
152//! @protected @memberof QActive
153uint_fast16_t QActive_flushDeferred(QActive const * const me,
154 struct QEQueue * const eq,
155 uint_fast16_t const num)
156{
157 uint_fast16_t n = 0U;
158 while (n < num) {
159 QEvt const * const e = QEQueue_get(eq, me->prio);
160 if (e != (QEvt *)0) {
161 ++n; // count one more flushed event
162 #if (QF_MAX_EPOOL > 0U)
163 QF_gc(e); // garbage collect
164 #endif
165 }
166 else {
167 break;
168 }
169 }
170
171 return n;
172}
173//$enddef${QF::QActive::flushDeferred} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#define QACTIVE_POST_LIFO(me_, e_)
Post an event to an active object using the Last-In-First-Out (LIFO) policy.
Definition qp.h:1230
#define QF_MEM_APP()
Definition qp.h:1288
#define QF_MEM_SYS()
Definition qp.h:1283
Internal (package scope) QP/C interface.
Sample QP/C port.
@ QS_QF_ACTIVE_RECALL
AO recalled an event.
Definition qs.h:94
#define QS_CRIT_STAT
Definition qs.h:568
#define QS_TIME_PRE_()
Definition qs.h:450
@ QS_QF_ACTIVE_RECALL_ATTEMPT
AO attempted to recall an event.
Definition qs.h:101
#define QS_MEM_APP()
Definition qs.h:588
@ QS_QF_ACTIVE_DEFER
AO deferred an event.
Definition qs.h:93
#define QS_CRIT_EXIT()
Definition qs.h:578
#define QS_MEM_SYS()
Definition qs.h:583
#define QS_CRIT_ENTRY()
Definition qs.h:573
QS/C package-scope interface.
Sample QS/C port.
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
Active object class (based on the QHsm implementation strategy)
Definition qp.h:804
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:809
Native QF Event Queue.
Definition qequeue.h:66
Event class.
Definition qp.h:145