QP/C  5.9.5
qf_defer.c
Go to the documentation of this file.
1 
40 #define QP_IMPL /* this is QP implementation */
41 #include "qf_port.h" /* QF port */
42 #include "qf_pkg.h" /* QF package-scope interface */
43 #include "qassert.h" /* QP embedded systems-friendly assertions */
44 #ifdef Q_SPY /* QS software tracing enabled? */
45  #include "qs_port.h" /* include QS port */
46 #else
47  #include "qs_dummy.h" /* disable the QS software tracing */
48 #endif /* Q_SPY */
49 
50 Q_DEFINE_THIS_MODULE("qf_defer")
51 
52 /****************************************************************************/
75 bool QActive_defer(QActive const * const me, QEQueue * const eq,
76  QEvt const * const e)
77 {
78  (void)me; /* avoid compiler warning about 'me' not used */
79 
80  return QEQueue_post(eq, e, (uint_fast16_t)1);
81 }
82 
83 /****************************************************************************/
103 bool QActive_recall(QActive * const me, QEQueue * const eq) {
104  QEvt const *e = QEQueue_get(eq); /* get an event from deferred queue */
105  bool recalled;
106 
107  /* event available? */
108  if (e != (QEvt const *)0) {
110 
111  QACTIVE_POST_LIFO(me, e); /* post it to the front of the AO's queue */
112 
113  QF_CRIT_ENTRY_();
114 
115  /* is it a dynamic event? */
116  if (e->poolId_ != (uint8_t)0) {
117 
118  /* after posting to the AO's queue the event must be referenced
119  * at least twice: once in the deferred event queue (eq->get()
120  * did NOT decrement the reference counter) and once in the
121  * AO's event queue.
122  */
123  Q_ASSERT_ID(210, e->refCtr_ > (uint8_t)1);
124 
125  /* we need to decrement the reference counter once, to account
126  * for removing the event from the deferred event queue.
127  */
128  QF_EVT_REF_CTR_DEC_(e); /* decrement the reference counter */
129  }
130 
131  QF_CRIT_EXIT_();
132  recalled = true;
133  }
134  else {
135  recalled = false;
136  }
137  return recalled;
138 }
139 
140 /****************************************************************************/
155  QEQueue * const eq)
156 {
158  QEvt const *e = QEQueue_get(eq);
159 
160  (void)me; /* avoid compiler warning about 'me' not used */
161 
162  for (; e != (QEvt const *)0; e = QEQueue_get(eq)) {
163  QF_gc(e); /* garbage collect */
164  ++n; /* count the flushed event */
165  }
166  return n;
167 }
bool QActive_defer(QActive const *const me, QEQueue *const eq, QEvt const *const e)
Defer an event e to a given event queue eq.
Definition: qf_defer.c:75
#define QF_CRIT_ENTRY_()
This is an internal macro for entering a critical section.
Definition: qf_pkg.h:69
uint_fast16_t QActive_flushDeferred(QActive const *const me, QEQueue *const eq)
Flush the specified deferred queue eq.
Definition: qf_defer.c:154
bool QEQueue_post(QEQueue *const me, QEvt const *const e, uint_fast16_t const margin)
Post an event to the "raw" thread-safe event queue (FIFO).
Definition: qf_qeq.c:118
#define QF_CRIT_STAT_
This is an internal macro for defining the critical section status type.
Definition: qf_pkg.h:57
#define Q_DEFINE_THIS_MODULE(name_)
Define the user-specified module name for assertions in this file.
Definition: qassert.h:101
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: stdint.h:28
Internal (package scope) QF/C interface.
void QF_gc(QEvt const *const e)
Recycle a dynamic event.
Definition: qf_dyn.c:217
Event structure.
Definition: qep.h:152
Native QF Event Queue.
Definition: qequeue.h:130
QEvt const * QEQueue_get(QEQueue *const me)
Obtain an event from the "raw" thread-safe queue.
Definition: qf_qeq.c:276
#define Q_ASSERT_ID(id_, test_)
General purpose assertion with user-specified assertion-id.
Definition: qassert.h:136
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: stdint.h:37
Customizable and memory-efficient assertions for embedded systems.
#define QF_EVT_REF_CTR_DEC_(e_)
decrement the refCtr of an event e_ casting const away
Definition: qf_pkg.h:111
int bool
standard Boolean data type
Definition: stdbool.h:16
bool QActive_recall(QActive *const me, QEQueue *const eq)
Recall a deferred event from a given event queue eq.
Definition: qf_defer.c:103
Active Object (based on QHsm implementation)
Definition: qf.h:110
uint8_t poolId_
pool ID (0 for static event)
Definition: qep.h:154
uint8_t volatile refCtr_
reference counter
Definition: qep.h:155
#define QACTIVE_POST_LIFO(me_, e_)
Polymorphically posts an event to an active object using the Last-In-First-Out (LIFO) policy...
Definition: qf.h:307
#define QF_CRIT_EXIT_()
This is an internal macro for exiting a critical section.
Definition: qf_pkg.h:81