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]].
main.cpp
00001 ////////////////////////////////////////////////////////////////////////////// 00002 // Product: DPP example 00003 // Last Updated for Version: 4.5.02 00004 // Date of the Last Update: Aug 11, 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 program is open source software: you can redistribute it and/or 00013 // modify it under the terms of the GNU General Public License as published 00014 // by the Free Software Foundation, either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // Alternatively, this program may be distributed and modified under the 00018 // terms of Quantum Leaps commercial licenses, which expressly supersede 00019 // the GNU General Public License and are specifically designed for 00020 // licensees interested in retaining the proprietary status of their code. 00021 // 00022 // This program is distributed in the hope that it will be useful, 00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 // GNU General Public License for more details. 00026 // 00027 // You should have received a copy of the GNU General Public License 00028 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00029 // 00030 // Contact information: 00031 // Quantum Leaps Web sites: http://www.quantum-leaps.com 00032 // http://www.state-machine.com 00033 // e-mail: info@quantum-leaps.com 00034 ////////////////////////////////////////////////////////////////////////////// 00035 #include "qp_port.h" 00036 #include "dpp.h" 00037 #include "bsp.h" 00038 00039 namespace DPP { 00040 00041 //............................................................................ 00042 extern "C" int_t main(void) { 00043 static QP::QEvt const *tableQueueSto[N_PHILO]; 00044 static QP::QEvt const *philoQueueSto[N_PHILO][N_PHILO]; 00045 static QP::QSubscrList subscrSto[MAX_PUB_SIG]; 00046 static QF_MPOOL_EL(TableEvt) smlPoolSto[2U*N_PHILO]; // small pool 00047 00048 QP::QF::init(); // initialize the framework and the underlying RT kernel 00049 00050 BSP_init(); // initialize the BSP 00051 00052 // object dictionaries... 00053 QS_OBJ_DICTIONARY(smlPoolSto); 00054 QS_OBJ_DICTIONARY(tableQueueSto); 00055 QS_OBJ_DICTIONARY(philoQueueSto[0]); 00056 QS_OBJ_DICTIONARY(philoQueueSto[1]); 00057 QS_OBJ_DICTIONARY(philoQueueSto[2]); 00058 QS_OBJ_DICTIONARY(philoQueueSto[3]); 00059 QS_OBJ_DICTIONARY(philoQueueSto[4]); 00060 00061 QP::QF::psInit(&subscrSto[0], Q_DIM(subscrSto)); // init publish-subscribe 00062 00063 // initialize event pools... 00064 QP::QF::poolInit(&smlPoolSto[0], sizeof(smlPoolSto), 00065 sizeof(smlPoolSto[0])); 00066 00067 // start the active objects... 00068 for (uint8_t n = 0U; n < N_PHILO; ++n) { 00069 AO_Philo[n]->start(static_cast<uint8_t>(n + 1U), 00070 &philoQueueSto[n][0], Q_DIM(philoQueueSto[n]), 00071 static_cast<void *>(0), 0U); 00072 } 00073 AO_Table->start(static_cast<uint8_t>(N_PHILO + 1U), 00074 &tableQueueSto[0], Q_DIM(tableQueueSto), 00075 static_cast<void *>(0), 0U); 00076 00077 00078 return QP::QF::run(); // run the QF application 00079 } 00080 00081 } // namespace DPP
Generated on Sat Jul 23 2022 13:10:38 by 1.7.2