![](/media/cache/profiles/7cca4a9404acc5243f0b77c16ff4a477.50x50_q85.jpg)
Dining Philosophers Problem (DPP) example for the QP active object framework. Demonstrates: event-driven programming, hierarchical state machines in C++, modeling and graphical state machine design, code generation, preemptive multitasking, software tracing, power saving mode, direct event posting, publish-subscribe. More information available in the [[/users/QL/notebook|Quantum Leaps Notebook pages]]. See also [[http://www.state-machine.com|state-machine.com]].
Diff: philo.cpp
- Revision:
- 3:81ceb3127876
- Parent:
- 0:efb9ac8d1a88
- Child:
- 4:6189d844a1a2
diff -r 2e62e514f323 -r 81ceb3127876 philo.cpp --- a/philo.cpp Wed Feb 16 17:12:38 2011 +0000 +++ b/philo.cpp Mon Sep 26 02:21:01 2011 +0000 @@ -1,13 +1,13 @@ ////////////////////////////////////////////////////////////////////////////// // Product: DPP example -// Last Updated for Version: 4.0.00 -// Date of the Last Update: Apr 06, 2008 +// Last Updated for Version: 4.2.00 +// Date of the Last Update: Jul 15, 2011 // // Q u a n t u m L e a P s // --------------------------- // innovating embedded systems // -// Copyright (C) 2002-2008 Quantum Leaps, LLC. All rights reserved. +// Copyright (C) 2002-2011 Quantum Leaps, LLC. All rights reserved. // // This software may be distributed and modified under the terms of the GNU // General Public License version 2 (GPL) as published by the Free Software @@ -49,8 +49,9 @@ // Local objects ------------------------------------------------------------- static Philo l_philo[N_PHILO]; // storage for all Philos -#define THINK_TIME 23 -#define EAT_TIME 19 +#define THINK_TIME (BSP_TICKS_PER_SEC/2) +#define EAT_TIME (BSP_TICKS_PER_SEC/5) + // helper macro to provide the ID of Philo "me_" #define PHILO_ID(me_) ((uint8_t)((me_) - l_philo)) @@ -108,7 +109,6 @@ return Q_HANDLED(); } case TIMEOUT_SIG: { - BSP_busyDelay(); return Q_TRAN(&Philo::hungry); } case EAT_SIG: // intentionally fall-through @@ -126,12 +126,11 @@ case Q_ENTRY_SIG: { TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG); pe->philoNum = PHILO_ID(me); - AO_Table->postFIFO(pe); + AO_Table->POST(pe, me); return Q_HANDLED(); } case EAT_SIG: { if (((TableEvt *)e)->philoNum == PHILO_ID(me)) { - BSP_busyDelay(); return Q_TRAN(&Philo::eating); } break; @@ -154,11 +153,10 @@ case Q_EXIT_SIG: { TableEvt *pe = Q_NEW(TableEvt, DONE_SIG); pe->philoNum = PHILO_ID(me); - QF::publish(pe); + QF::PUBLISH(pe, me); return Q_HANDLED(); } case TIMEOUT_SIG: { - BSP_busyDelay(); return Q_TRAN(&Philo::thinking); } case EAT_SIG: // intentionally fall-through @@ -170,4 +168,3 @@ } return Q_SUPER(&QHsm::top); } -