]> rtime.felk.cvut.cz Git - arc.git/blob - include/cirq_buffer.h
EcuM_ConfigType to internal header file
[arc.git] / include / cirq_buffer.h
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16 #ifndef CIRQ_BUFFER_H_
17 #define CIRQ_BUFFER_H_
18
19 #include <stddef.h>
20
21 typedef struct {
22         /* The max number of elements in the list */
23         int maxCnt;
24         int currCnt;
25
26         /* Size of the elements in the list */
27         size_t dataSize;
28         /* List head and tail */
29         void *head;
30         void *tail;
31
32         /* Buffer start/stop */
33         void *bufStart;
34         void *bufEnd;
35 } CirqBufferType;
36
37 /* Dynamic implementation */
38 CirqBufferType *CirqBuffDynCreate( size_t size, size_t dataSize );
39 int CirqBuffDynDestroy(CirqBufferType *cPtr );
40
41 /* Static implementation */
42 CirqBufferType CirqBuffStatCreate(void *buffer, int maxCnt, size_t dataSize);
43
44 int CirqBuffPush( CirqBufferType *cPtr, void *dataPtr );
45 int CirqBuffPop(CirqBufferType *cPtr, void *dataPtr );
46 void *CirqBuff_PushLock( CirqBufferType *cPtr);
47 void *CirqBuff_PopLock(CirqBufferType *cPtr );
48 void CirqBuff_Init(CirqBufferType *cirqbuffer, void *buffer, int maxCnt, size_t dataSize);
49
50 static inline boolean CirqBuff_Empty(CirqBufferType *cPtr ) {
51         return (cPtr->currCnt == 0);
52 }
53 static inline void CirqBuff_PushRelease( CirqBufferType *cPtr) {
54         ++cPtr->currCnt;
55 }
56
57 static inline void CirqBuff_PopRelease( CirqBufferType *cPtr) {
58         --cPtr->currCnt;
59 }
60
61
62 #endif /* CIRQ_BUFFER_H_ */