1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 * A message box implementation.
\r
20 * - Do NOT use Arc_MBoxDestroy() call, it's there for testing purposes only.
23 //#define _TEST_MBOX_
\r
39 Arc_MBoxType* Arc_MBoxCreate( size_t size ) {
\r
42 mPtr = malloc(sizeof(Arc_MBoxType));
\r
43 mPtr->cirqPtr = CirqBuffDynCreate(size,sizeof(void *));
\r
49 void Arc_MBoxDestroy( Arc_MBoxType *mPtr ) {
\r
50 CirqBuffDynDestroy(mPtr->cirqPtr);
\r
55 * Post a message to a box, non-blocking.
\r
58 int Arc_MBoxPost( Arc_MBoxType *mPtr, void *msg ) {
\r
60 rv = CirqBuffPush(mPtr->cirqPtr,msg);
\r
71 int Arc_MBoxFetch(Arc_MBoxType *mPtr, void *msg)
\r
74 rv = CirqBuffPop(mPtr->cirqPtr,msg);
\r
83 Arc_MBoxType *myBoxes[10];
\r
88 myBoxes[0] = Arc_MBoxCreate(2);
\r
89 myBoxes[1] = Arc_MBoxCreate(4);
\r
91 dataPtr = malloc(10);
\r
93 Arc_MBoxPost(myBoxes[0],&dataPtr);
\r
95 dataPtr = malloc(20);
\r
97 Arc_MBoxPost(myBoxes[0],&dataPtr);
\r
99 Arc_MBoxFetch(myBoxes[0],&dataPtr);
\r
100 assert(dataPtr[0] == 1);
\r
103 Arc_MBoxFetch(myBoxes[0],&dataPtr);
\r
104 assert(dataPtr[0] == 2);
\r
107 Arc_MBoxDestroy(myBoxes[0]);
\r
108 Arc_MBoxDestroy(myBoxes[1]);
\r