2012-08-14 18:07:04 -04:00
|
|
|
/*****************************************************************************
|
|
|
|
* Product: QF/C
|
2013-09-23 14:34:35 -04:00
|
|
|
* Last Updated for Version: 5.0.0
|
|
|
|
* Date of the Last Update: Sep 12, 2013
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
|
|
|
* Q u a n t u m L e a P s
|
|
|
|
* ---------------------------
|
|
|
|
* innovating embedded systems
|
|
|
|
*
|
2013-09-23 14:34:35 -04:00
|
|
|
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
|
|
|
* This program is open source software: you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Alternatively, this program may be distributed and modified under the
|
|
|
|
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
|
|
|
* the GNU General Public License and are specifically designed for
|
|
|
|
* licensees interested in retaining the proprietary status of their code.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Contact information:
|
|
|
|
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
|
|
|
* http://www.state-machine.com
|
|
|
|
* e-mail: info@quantum-leaps.com
|
|
|
|
*****************************************************************************/
|
|
|
|
#include "qf_pkg.h"
|
|
|
|
#include "qassert.h"
|
|
|
|
|
|
|
|
Q_DEFINE_THIS_MODULE("qa_defer")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \ingroup qf
|
|
|
|
* \brief QActive_defer() and QActive_recall() implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*..........................................................................*/
|
2013-09-23 14:34:35 -04:00
|
|
|
uint8_t QActive_defer(QActive * const me, QEQueue * const eq,
|
|
|
|
QEvt const * const e)
|
2012-08-14 18:07:04 -04:00
|
|
|
{
|
|
|
|
(void)me; /* avoid compiler warning about 'me' not used */
|
2013-09-23 14:34:35 -04:00
|
|
|
return QEQueue_post(eq, e, (uint16_t)1);
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
/*..........................................................................*/
|
|
|
|
uint8_t QActive_recall(QActive * const me, QEQueue * const eq) {
|
2013-09-23 14:34:35 -04:00
|
|
|
QEvt const *e = QEQueue_get(eq); /* get an event from deferred queue */
|
2012-08-14 18:07:04 -04:00
|
|
|
uint8_t recalled;
|
2013-09-23 14:34:35 -04:00
|
|
|
if (e != (QEvt const *)0) { /* event available? */
|
2012-08-14 18:07:04 -04:00
|
|
|
QF_CRIT_STAT_
|
|
|
|
|
2013-09-23 14:34:35 -04:00
|
|
|
QACTIVE_POST_LIFO(me, e); /* post it to the front of the AO's queue */
|
2012-08-14 18:07:04 -04:00
|
|
|
|
|
|
|
QF_CRIT_ENTRY_();
|
|
|
|
|
2013-09-23 14:34:35 -04:00
|
|
|
if (e->poolId_ != (uint8_t)0) { /* is it a dynamic event? */
|
2012-08-14 18:07:04 -04:00
|
|
|
|
|
|
|
/* after posting to the AO's queue the event must be referenced
|
|
|
|
* at least twice: once in the deferred event queue (eq->get()
|
|
|
|
* did NOT decrement the reference counter) and once in the
|
|
|
|
* AO's event queue.
|
|
|
|
*/
|
2013-09-23 14:34:35 -04:00
|
|
|
Q_ASSERT(e->refCtr_ > (uint8_t)1);
|
2012-08-14 18:07:04 -04:00
|
|
|
|
|
|
|
/* we need to decrement the reference counter once, to account
|
|
|
|
* for removing the event from the deferred event queue.
|
|
|
|
*/
|
|
|
|
QF_EVT_REF_CTR_DEC_(e); /* decrement the reference counter */
|
|
|
|
}
|
|
|
|
|
|
|
|
QF_CRIT_EXIT_();
|
|
|
|
recalled = (uint8_t)1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
recalled = (uint8_t)0;
|
|
|
|
}
|
|
|
|
return recalled;
|
|
|
|
}
|