@@ -96,19 +96,19 @@ bool QActive_post_(QActive * const me,
9696 Q_REQUIRE_INCRIT (100 , e != (QEvt * )0 );
9797
9898 // the number of free slots available in the FreeRTOS queue
99- uint_fast16_t const nFree =
100- (uint_fast16_t )FREERTOS_QUEUE_GET_FREE (me );
101-
102- // should we try to post the event?
103- bool status = ((margin == QF_NO_MARGIN ) || (nFree > (QEQueueCtr )margin ));
99+ QEQueueCtr const nFree =
100+ (QEQueueCtr )FREERTOS_QUEUE_GET_FREE (me );
104101
102+ bool status = ((margin == QF_NO_MARGIN )
103+ || (nFree > (QEQueueCtr )margin ));
105104 if (status ) { // should try to post the event?
106105#if (QF_MAX_EPOOL > 0U )
107106 if (e -> poolNum_ != 0U ) { // is it a mutable event?
108107 QEvt_refCtr_inc_ (e ); // increment the reference counter
109108 }
110109#endif // (QF_MAX_EPOOL > 0U)
111110
111+ // assume that event posting will be successful, see NOTE3
112112 QS_BEGIN_PRE (QS_QF_ACTIVE_POST , me -> prio )
113113 QS_TIME_PRE (); // timestamp
114114 QS_OBJ_PRE (sender ); // the sender object
@@ -121,14 +121,17 @@ bool QActive_post_(QActive * const me,
121121
122122 QF_CRIT_EXIT (); // exit crit.sect. before calling RTOS API
123123
124- // post the event to the FreeRTOS event queue, see NOTE3
124+ // post the following evtPtr to the RTOS event queue, see NOTE3
125+ QEvtPtr const evtPtr = {
126+ e
127+ };
125128 status = (xQueueSendToBack (
126- me -> eQueue , (void const * )& e , (TickType_t )0 ) == pdPASS );
129+ me -> eQueue , (void const * )& evtPtr , 0U ) == pdPASS );
130+
131+ QF_CRIT_ENTRY (); // re-enter crit.sec.
127132 }
128133
129134 if (!status ) { // event NOT posted?
130- QF_CRIT_ENTRY ();
131-
132135 // posting is allowed to fail only when margin != QF_NO_MARGIN
133136 Q_ASSERT_INCRIT (130 , margin != QF_NO_MARGIN );
134137
@@ -138,7 +141,7 @@ bool QActive_post_(QActive * const me,
138141 QS_SIG_PRE (e -> sig ); // the signal of the event
139142 QS_OBJ_PRE (me ); // this active object (recipient)
140143 QS_2U8_PRE (e -> poolNum_ , e -> refCtr_ ); // pool-Num & ref-Count
141- QS_EQC_PRE (nFree ); // # free entries available
144+ QS_EQC_PRE (nFree ); // # free entries
142145 QS_EQC_PRE (margin ); // margin requested
143146 QS_END_PRE ()
144147
@@ -148,6 +151,9 @@ bool QActive_post_(QActive * const me,
148151 QF_gc (e ); // recycle the event to avoid a leak
149152#endif
150153 }
154+ else {
155+ QF_CRIT_EXIT ();
156+ }
151157
152158 return status ;
153159}
@@ -171,14 +177,18 @@ void QActive_postLIFO_(QActive * const me, QEvt const * const e) {
171177 QS_SIG_PRE (e -> sig ); // the signal of this event
172178 QS_OBJ_PRE (me ); // this active object
173179 QS_2U8_PRE (e -> poolNum_ , e -> refCtr_ ); // pool-Num & ref-Count
174- QS_EQC_PRE (FREERTOS_QUEUE_GET_FREE (me )); // # free entries available
180+ QS_EQC_PRE (FREERTOS_QUEUE_GET_FREE (me )); // # free entries
175181 QS_EQC_PRE (0U ); // min # free entries (unknown)
176182 QS_END_PRE ()
177183
178184 QF_CRIT_EXIT (); // exit crit.sect. before calling RTOS API
179185
186+ // post the following evtPtr to the RTOS event queue, see NOTE3
187+ QEvtPtr const evtPtr = {
188+ e
189+ };
180190 BaseType_t const err =
181- xQueueSendToFront (me -> eQueue , (void const * )& e , ( TickType_t ) 0 );
191+ xQueueSendToFront (me -> eQueue , (void const * )& evtPtr , 0U );
182192
183193#ifndef Q_UNSAFE
184194 QF_CRIT_ENTRY ();
@@ -193,8 +203,9 @@ void QActive_postLIFO_(QActive * const me, QEvt const * const e) {
193203//! @private @memberof QActive
194204QEvt const * QActive_get_ (QActive * const me ) {
195205 // wait for an event (forever)
196- QEvtPtr e ;
197- BaseType_t const err = xQueueReceive (me -> eQueue , (void * )& e , portMAX_DELAY );
206+ QEvtPtr evtPtr ;
207+ BaseType_t const err = xQueueReceive (me -> eQueue ,
208+ (void * )& evtPtr , portMAX_DELAY );
198209
199210 QF_CRIT_STAT
200211 QF_CRIT_ENTRY ();
@@ -207,15 +218,15 @@ QEvt const *QActive_get_(QActive * const me) {
207218
208219 QS_BEGIN_PRE (QS_QF_ACTIVE_GET , me -> prio )
209220 QS_TIME_PRE (); // timestamp
210- QS_SIG_PRE (e -> sig ); // the signal of this event
221+ QS_SIG_PRE (evtPtr . e -> sig ); // the signal of this event
211222 QS_OBJ_PRE (me ); // this active object
212- QS_2U8_PRE (e -> poolNum_ , e -> refCtr_ ); // pool-Num & ref-Count
223+ QS_2U8_PRE (evtPtr . e -> poolNum_ , evtPtr . e -> refCtr_ );
213224 QS_EQC_PRE (FREERTOS_QUEUE_GET_FREE (me )); // # free entries available
214225 QS_END_PRE ()
215226
216227 QF_CRIT_EXIT ();
217228
218- return e ;
229+ return evtPtr . e ;
219230}
220231//............................................................................
221232//! @static @public @memberof QActive
@@ -343,12 +354,12 @@ bool QActive_postFromISR_(QActive * const me,
343354 Q_REQUIRE_INCRIT (600 , e != (QEvt * )0 );
344355
345356 // the number of free slots available in the FreeRTOS queue
346- uint_fast16_t const nFree =
347- (uint_fast16_t )FREERTOS_QUEUE_GET_FREE (me );
357+ QEQueueCtr const nFree =
358+ (QEQueueCtr )FREERTOS_QUEUE_GET_FREE (me );
348359
349360 // should we try to post the event?
350- bool status = ((margin == QF_NO_MARGIN ) || ( nFree > ( QEQueueCtr ) margin ));
351-
361+ bool status = ((margin == QF_NO_MARGIN )
362+ || ( nFree > ( QEQueueCtr ) margin ));
352363 if (status ) { // should try to post the event?
353364#if (QF_MAX_EPOOL > 0U )
354365 if (e -> poolNum_ != 0U ) { // is it a mutable event?
@@ -369,14 +380,17 @@ bool QActive_postFromISR_(QActive * const me,
369380 // exit crit.sect. before calling RTOS API
370381 portCLEAR_INTERRUPT_MASK_FROM_ISR (uxSavedInterruptStatus );
371382
372- // post the event to the FreeRTOS event queue, see NOTE3
383+ // post the following evtPtr to the RTOS event queue, see NOTE3
384+ QEvtPtr const evtPtr = {
385+ e
386+ };
373387 status = (xQueueSendToBackFromISR (me -> eQueue ,
374- (void const * )& e , pxHigherPriorityTaskWoken ) == pdPASS );
375- }
388+ (void const * )& evtPtr , pxHigherPriorityTaskWoken ) == pdPASS );
376389
377- if (!status ) { // event NOT posted?
378390 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR ();
391+ }
379392
393+ if (!status ) { // event NOT posted?
380394 // posting is allowed to fail only when margin != QF_NO_MARGIN
381395 Q_ASSERT_INCRIT (630 , margin != QF_NO_MARGIN );
382396
@@ -396,6 +410,9 @@ bool QActive_postFromISR_(QActive * const me,
396410 QF_gcFromISR (e ); // recycle the event to avoid a leak
397411#endif
398412 }
413+ else {
414+ portCLEAR_INTERRUPT_MASK_FROM_ISR (uxSavedInterruptStatus );
415+ }
399416
400417 return status ;
401418}
0 commit comments