QP/C  8.0.0
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 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 GNU
18// 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.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35#define QP_IMPL // this is QP implementation
36#include "qp_port.h" // QP port
37#include "qp_pkg.h" // 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.h" // QS port
41 #include "qs_pkg.h" // QS facilities for pre-defined trace records
42#else
43 #include "qs_dummy.h" // disable the QS software tracing
44#endif // Q_SPY
45
46Q_DEFINE_THIS_MODULE("qf_defer")
47
48//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
49// Check for the minimum required QP version
50#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
51#error qpc version 7.3.0 or higher required
52#endif
53//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54//$define${QF::QActive::defer} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
55
56//${QF::QActive::defer} ......................................................
57//! @protected @memberof QActive
58bool QActive_defer(QActive const * const me,
59 struct QEQueue * const eq,
60 QEvt const * const e)
61{
62 bool const status = QEQueue_post(eq, e, 0U, me->prio);
63
66 QS_MEM_SYS();
67 QS_BEGIN_PRE(QS_QF_ACTIVE_DEFER, me->prio)
68 QS_TIME_PRE(); // time stamp
69 QS_OBJ_PRE(me); // this active object
70 QS_OBJ_PRE(eq); // the deferred queue
71 QS_SIG_PRE(e->sig); // the signal of the event
72 QS_2U8_PRE(QEvt_getPoolNum_(e), e->refCtr_);
74 QS_MEM_APP();
76
77 return status;
78}
79//$enddef${QF::QActive::defer} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80//$define${QF::QActive::recall} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
81
82//${QF::QActive::recall} .....................................................
83//! @protected @memberof QActive
84bool QActive_recall(QActive * const me,
85 struct QEQueue * const eq)
86{
87 QEvt const * const e = QEQueue_get(eq, me->prio);
89
90 bool recalled;
91 if (e != (QEvt *)0) { // event available?
92 QACTIVE_POST_LIFO(me, e); // post it to the front of the AO's queue
93
95 QF_MEM_SYS();
96
97 if (QEvt_getPoolNum_(e) != 0U) { // is it a mutable event?
98
99 // after posting to the AO's queue the event must be referenced
100 // at least twice: once in the deferred event queue (eq->get()
101 // did NOT decrement the reference counter) and once in the
102 // AO's event queue.
103 Q_ASSERT_INCRIT(210, e->refCtr_ >= 2U);
104
105 // we need to decrement the reference counter once, to account
106 // for removing the event from the deferred event queue.
107 QEvt_refCtr_dec_(e); // decrement the reference counter
108 }
109
110 QS_BEGIN_PRE(QS_QF_ACTIVE_RECALL, me->prio)
111 QS_TIME_PRE(); // time stamp
112 QS_OBJ_PRE(me); // this active object
113 QS_OBJ_PRE(eq); // the deferred queue
114 QS_SIG_PRE(e->sig); // the signal of the event
115 QS_2U8_PRE(QEvt_getPoolNum_(e), e->refCtr_);
116 QS_END_PRE()
117
118 QF_MEM_APP();
119 QF_CRIT_EXIT();
120
121 recalled = true;
122 }
123 else {
125 QS_MEM_SYS();
126
127 QS_BEGIN_PRE(QS_QF_ACTIVE_RECALL_ATTEMPT, me->prio)
128 QS_TIME_PRE(); // time stamp
129 QS_OBJ_PRE(me); // this active object
130 QS_OBJ_PRE(eq); // the deferred queue
131 QS_END_PRE()
132
133 QS_MEM_APP();
134 QS_CRIT_EXIT();
135
136 recalled = false;
137 }
138 return recalled;
139}
140//$enddef${QF::QActive::recall} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141//$define${QF::QActive::flushDeferred} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
142
143//${QF::QActive::flushDeferred} ..............................................
144//! @protected @memberof QActive
145uint_fast16_t QActive_flushDeferred(QActive const * const me,
146 struct QEQueue * const eq,
147 uint_fast16_t const num)
148{
149 uint_fast16_t n = 0U;
150 while (n < num) {
151 QEvt const * const e = QEQueue_get(eq, me->prio);
152 if (e != (QEvt *)0) {
153 ++n; // count one more flushed event
154 #if (QF_MAX_EPOOL > 0U)
155 QF_gc(e); // garbage collect
156 #endif
157 }
158 else {
159 break;
160 }
161 }
162
163 return n;
164}
165//$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:1218
#define QF_MEM_APP()
Definition qp.h:1276
#define QF_MEM_SYS()
Definition qp.h:1271
Internal (package scope) QP/C interface.
Sample QP/C port.
#define QS_OBJ_PRE(obj_)
Definition qs_dummy.h:150
#define QS_CRIT_STAT
Definition qs_dummy.h:157
#define QS_SIG_PRE(sig_)
Definition qs_dummy.h:148
#define QS_TIME_PRE()
Definition qs_dummy.h:147
#define QS_MEM_APP()
Definition qs_dummy.h:162
#define QS_2U8_PRE(data1_, data2_)
Definition qs_dummy.h:144
#define QS_CRIT_EXIT()
Definition qs_dummy.h:159
#define QS_MEM_SYS()
Definition qs_dummy.h:161
#define QS_END_PRE()
Definition qs_dummy.h:142
#define QS_CRIT_ENTRY()
Definition qs_dummy.h:158
#define QS_BEGIN_PRE(rec_, qsId_)
Definition qs_dummy.h:141
Sample QS/C port.
QP Functional Safety (FuSa) Subsystem.
#define QF_CRIT_ENTRY()
Definition qsafe.h:50
#define Q_ASSERT_INCRIT(id_, expr_)
Definition qsafe.h:64
#define QF_CRIT_EXIT()
Definition qsafe.h:54
#define QF_CRIT_STAT
Definition qsafe.h:46
Active object class (based on the QHsm implementation strategy)
Definition qp.h:775
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:780
Native QF Event Queue.
Definition qequeue.h:56
Event class.
Definition qp.h:131