QP/C
qf_pspub.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Product: QF/C
00003 * Last Updated for Version: 4.4.00
00004 * Date of the Last Update:  Jan 14, 2012
00005 *
00006 *                    Q u a n t u m     L e a P s
00007 *                    ---------------------------
00008 *                    innovating embedded systems
00009 *
00010 * Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
00011 *
00012 * This software may be distributed and modified under the terms of the GNU
00013 * General Public License version 2 (GPL) as published by the Free Software
00014 * Foundation and appearing in the file GPL.TXT included in the packaging of
00015 * this file. Please note that GPL Section 2[b] requires that all works based
00016 * on this software must also be made publicly available under the terms of
00017 * the GPL ("Copyleft").
00018 *
00019 * Alternatively, this software may be distributed and modified under the
00020 * terms of Quantum Leaps commercial licenses, which expressly supersede
00021 * the GPL and are specifically designed for licensees interested in
00022 * retaining the proprietary status of their code.
00023 *
00024 * Contact information:
00025 * Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 * e-mail:                  info@quantum-leaps.com
00027 *****************************************************************************/
00028 #include "qf_pkg.h"
00029 #include "qassert.h"
00030 
00031 Q_DEFINE_THIS_MODULE("qf_pspub")
00032 
00033 
00039 /*..........................................................................*/
00040 #ifndef Q_SPY
00041 void QF_publish(QEvent const *e) {
00042 #else
00043 void QF_publish(QEvent const *e, void const *sender) {
00044 #endif
00045 
00046     QF_CRIT_STAT_
00047 
00048       /* make sure that the published signal is within the configured range */
00049     Q_REQUIRE(e->sig < QF_maxSignal_);
00050 
00051     QF_CRIT_ENTRY_();
00052 
00053     QS_BEGIN_NOCRIT_(QS_QF_PUBLISH, (void *)0, (void *)0)
00054         QS_TIME_();                                        /* the timestamp */
00055         QS_OBJ_(sender);                               /* the sender object */
00056         QS_SIG_(e->sig);                         /* the signal of the event */
00057         QS_U8_(QF_EVT_POOL_ID_(e));             /* the pool Id of the event */
00058         QS_U8_(QF_EVT_REF_CTR_(e));           /* the ref count of the event */
00059     QS_END_NOCRIT_()
00060 
00061     if (QF_EVT_POOL_ID_(e) != (uint8_t)0) {       /* is it a dynamic event? */
00062         QF_EVT_REF_CTR_INC_(e);      /* increment reference counter, NOTE01 */
00063     }
00064     QF_CRIT_EXIT_();
00065 
00066 #if (QF_MAX_ACTIVE <= 8)
00067     {
00068         uint8_t tmp = QF_subscrList_[e->sig].bits[0];
00069         while (tmp != (uint8_t)0) {
00070             uint8_t p = Q_ROM_BYTE(QF_log2Lkup[tmp]);
00071             tmp &= Q_ROM_BYTE(QF_invPwr2Lkup[p]);   /* clear subscriber bit */
00072             Q_ASSERT(QF_active_[p] != (QActive *)0);  /* must be registered */
00073 
00074                 /* QACTIVE_POST() asserts internally if the queue overflows */
00075             QACTIVE_POST(QF_active_[p], e, sender);
00076         }
00077     }
00078 #else
00079     {
00080         uint8_t i = (uint8_t)Q_DIM(QF_subscrList_[0].bits);
00081         do {               /* go through all bytes in the subscription list */
00082             uint8_t tmp;
00083             --i;
00084             tmp = QF_PTR_AT_(QF_subscrList_, e->sig).bits[i];
00085             while (tmp != (uint8_t)0) {
00086                 uint8_t p = Q_ROM_BYTE(QF_log2Lkup[tmp]);
00087                 tmp &= Q_ROM_BYTE(QF_invPwr2Lkup[p]);/*clear subscriber bit */
00088                 p = (uint8_t)(p + (uint8_t)(i << 3));/* adjust the priority */
00089                 Q_ASSERT(QF_active_[p] != (QActive *)0);/*must be registered*/
00090 
00091                 /* QACTIVE_POST() asserts internally if the queue overflows */
00092                 QACTIVE_POST(QF_active_[p], e, sender);
00093             }
00094         } while (i != (uint8_t)0);
00095     }
00096 #endif
00097 
00098     QF_gc(e);                      /* run the garbage collector, see NOTE01 */
00099 }
00100 
00101 /*****************************************************************************
00102 * NOTE01:
00103 * QF_publish() increments the reference counter to prevent premature
00104 * recycling of the event while the multicasting is still in progress.
00105 * At the end of the function, the garbage collector step decrements the
00106 * reference counter and recycles the event if the counter drops to zero.
00107 * This covers the case when the event was published without any subscribers.
00108 */