QP/C  5.8.2
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 
45 Q_DEFINE_THIS_MODULE("qf_defer")
46 
47 /****************************************************************************/
70 bool QActive_defer(QActive const * const me, QEQueue * const eq,
71  QEvt const * const e)
72 {
73  (void)me; /* avoid compiler warning about 'me' not used */
74 
75  return QEQueue_post(eq, e, (uint_fast16_t)1);
76 }
77 
78 /****************************************************************************/
98 bool QActive_recall(QActive * const me, QEQueue * const eq) {
99  QEvt const *e = QEQueue_get(eq); /* get an event from deferred queue */
100  bool recalled;
101 
102  /* event available? */
103  if (e != (QEvt const *)0) {
105 
106  QACTIVE_POST_LIFO(me, e); /* post it to the front of the AO's queue */
107 
108  QF_CRIT_ENTRY_();
109 
110  /* is it a dynamic event? */
111  if (e->poolId_ != (uint8_t)0) {
112 
113  /* after posting to the AO's queue the event must be referenced
114  * at least twice: once in the deferred event queue (eq->get()
115  * did NOT decrement the reference counter) and once in the
116  * AO's event queue.
117  */
118  Q_ASSERT_ID(210, e->refCtr_ > (uint8_t)1);
119 
120  /* we need to decrement the reference counter once, to account
121  * for removing the event from the deferred event queue.
122  */
123  QF_EVT_REF_CTR_DEC_(e); /* decrement the reference counter */
124  }
125 
126  QF_CRIT_EXIT_();
127  recalled = true;
128  }
129  else {
130  recalled = false;
131  }
132  return recalled;
133 }
134 
135 /****************************************************************************/
150  QEQueue * const eq)
151 {
153  QEvt const *e = QEQueue_get(eq);
154 
155  (void)me; /* avoid compiler warning about 'me' not used */
156 
157  for (; e != (QEvt const *)0; e = QEQueue_get(eq)) {
158  QF_gc(e); /* garbage collect */
159  ++n; /* count the flushed event */
160  }
161  return n;
162 }
163 
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:70
#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:149
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:95
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:211
Event structure.
Definition: qep.h:153
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:274
#define Q_ASSERT_ID(id_, test_)
General purpose assertion with user-specified assertion-id.
Definition: qassert.h:130
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:98
Active Object (based on QHsm implementation)
Definition: qf.h:110
uint8_t poolId_
pool ID (0 for static event)
Definition: qep.h:155
uint8_t volatile refCtr_
reference counter
Definition: qep.h:156
#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:306
#define QF_CRIT_EXIT_()
This is an internal macro for exiting a critical section.
Definition: qf_pkg.h:81