: QHsm(Q_STATE_CAST(&Philo::initial)),
m_timeEvt(AO_Table, this, TIMEOUT_SIG, 0U)
static bool registered = false; // starts off with 0, per C-standard
(void)e; // suppress the compiler warning about unused parameter
if (!registered) {
registered = true;
QS_FUN_DICTIONARY(&Philo::initial);
QS_FUN_DICTIONARY(&Philo::thinking);
QS_FUN_DICTIONARY(&Philo::hungry);
QS_FUN_DICTIONARY(&Philo::eating);
}
QS_SIG_DICTIONARY(HUNGRY_SIG, me); // signal for each Philos
me->m_timeEvt.armX(think_time(), 0U);
(void)me->m_timeEvt.disarm();
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
pe->philo = me;
AO_Table->postLIFO(pe);
me->m_timeEvt.armX(eat_time(), 0U);
(void)me->m_timeEvt.disarm();
// asynchronously post event to the Container
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
pe->philo = me;
AO_Table->postLIFO(pe);
#include "qpcpp.h"
#include "dpp.h"
#include "bsp.h"
Q_DEFINE_THIS_FILE
namespace DPP {
// helper function to provide a randomized think time for Philos
inline QP::QTimeEvtCtr think_time() {
return static_cast<QP::QTimeEvtCtr>((BSP::random() % BSP::TICKS_PER_SEC)
+ (BSP::TICKS_PER_SEC/2U));
}
// helper function to provide a randomized eat time for Philos
inline QP::QTimeEvtCtr eat_time() {
return static_cast<QP::QTimeEvtCtr>((BSP::random() % BSP::TICKS_PER_SEC)
+ BSP::TICKS_PER_SEC);
}
} // namespace DPP
// Philo definition ----------------------------------------------------------
$define(Comp::Philo)