RKH
rkhqueue.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH site: http://vortexmakes.com/que-es/
28  * RKH GitHub: https://github.com/vortexmakes/RKH
29  * RKH Sourceforge: https://sourceforge.net/projects/rkh-reactivesys/
30  * e-mail: lf@vortexmakes.com
31  * ---------------------------------------------------------------------------
32  */
33 
47 /* -------------------------- Development history -------------------------- */
48 /*
49  * 2017.17.05 LeFr v2.4.05 Initial version
50  */
51 
52 /* -------------------------------- Authors -------------------------------- */
53 /*
54  * LeFr Leandro Francucci lf@vortexmakes.com
55  */
56 
57 /* --------------------------------- Notes --------------------------------- */
58 /* --------------------------------- Module -------------------------------- */
59 #ifndef __RKHQUEUE_H__
60 #define __RKHQUEUE_H__
61 
62 /* ----------------------------- Include files ----------------------------- */
63 #include "rkhcfg.h"
64 #include "rkhtype.h"
65 
66 /* ---------------------- External C language linkage ---------------------- */
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 /* --------------------------------- Macros -------------------------------- */
83 #define RKH_QUEUE_IS_EMPTY(q) \
84  (rbool_t)(rkh_queue_get_num((RKH_QUEUE_T *)(q)) == 0)
85 
86 /* -------------------------------- Constants ------------------------------ */
87 /* ------------------------------- Data types ------------------------------ */
96 #if RKH_CFG_QUE_SIZEOF_NELEM == 8
97 typedef rui8_t RKH_QUENE_T;
98 #elif RKH_CFG_QUE_SIZEOF_NELEM == 16
99 typedef rui16_t RKH_QUENE_T;
100 #elif RKH_CFG_QUE_SIZEOF_NELEM == 32
101 typedef rui32_t RKH_QUENE_T;
102 #else
103 typedef rui8_t RKH_QUENE_T;
104 #endif
105 
110 typedef enum
111 {
112  RKH_QUE_OK, RKH_QUE_EMPTY, RKH_QUE_FULL
113 } RKH_QUECODE_T;
114 
126 typedef struct RKH_QINFO_T
127 {
128  rui16_t nputs; /* # of put requests */
129  rui16_t ngets; /* # of get requests */
130  rui16_t nreads; /* # of queue read requests */
131  rui16_t nempty; /* # of queue empty retrieves */
132  rui16_t nfull; /* # of queue full retrieves */
133 } RKH_QUEI_T;
134 
169 typedef struct RKH_QUEUE_T
170 {
176 
182 
187  void **pout;
188 
193  void **pin;
194 
199  const void **pstart;
200 
205  void **pend;
206 
215  const struct RKH_SMA_T *sma;
216 
223 #if RKH_CFG_QUE_GET_LWMARK_EN == RKH_ENABLED
225 #endif
226 
232 #if RKH_CFG_QUE_GET_INFO_EN == RKH_ENABLED
234 #endif
235 } RKH_QUEUE_T;
236 
237 /* -------------------------- External variables --------------------------- */
238 /* -------------------------- Function prototypes -------------------------- */
265 void rkh_queue_init(RKH_QUEUE_T *q, const void * *sstart, RKH_QUENE_T ssize,
266  void *sma);
267 
284 
298 
318 
329 
347 void rkh_queue_put_fifo(RKH_QUEUE_T *q, const void *pe);
348 
369 void rkh_queue_put_lifo(RKH_QUEUE_T *q, const void *pe);
370 
393 
413 ruint rkh_queue_read(RKH_QUEUE_T *q, void *pe);
414 
439 
453 
454 /* -------------------- External C language linkage end -------------------- */
455 #ifdef __cplusplus
456 }
457 #endif
458 
459 /* ------------------------------ Module end ------------------------------- */
460 #endif
461 
462 /* ------------------------------ End of file ------------------------------ */
RKH_QUENE_T rkh_queue_get_lwm(RKH_QUEUE_T *q)
This function returns the lowest number of free elements ever present in the pool....
void rkh_queue_put_lifo(RKH_QUEUE_T *q, const void *pe)
Puts an element on a queue in a LIFO manner. The element is queued by reference, not by copy.
ruint rkh_queue_read(RKH_QUEUE_T *q, void *pe)
Read an element from a queue without remove it.
void rkh_queue_deplete(RKH_QUEUE_T *q)
Depletes a queue. Empties the contents of the queue and eliminates all stored elements.
void rkh_queue_init(RKH_QUEUE_T *q, const void **sstart, RKH_QUENE_T ssize, void *sma)
Initializes the previously allocated queue data structure RKH_QUEUE_T.
rbool_t rkh_queue_is_full(RKH_QUEUE_T *q)
This function query the queue.
void rkh_queue_put_fifo(RKH_QUEUE_T *q, const void *pe)
Puts an element on a queue in a FIFO manner. The element is queued by reference, not by copy.
void * rkh_queue_get(RKH_QUEUE_T *q)
Get and remove an element from a queue.
RKH_QUENE_T rkh_queue_get_num(RKH_QUEUE_T *q)
Returns the number of elements currently in the queue.
void rkh_queue_clear_info(RKH_QUEUE_T *q)
Clear performance information for a particular queue.
void rkh_queue_get_info(RKH_QUEUE_T *q, RKH_QUEI_T *pqi)
Retrieves performance information for a particular queue.
RKH user configurations.
RKH_QUECODE_T
Return codes from queue operations.
Definition: rkhqueue.h:111
rui8_t RKH_QUENE_T
This data type defines the maximum number of elements that any queue can contain.
Definition: rkhqueue.h:97
Defines the data types that uses RKH.
Defines the data structure into which the performance information for queues is stored.
Definition: rkhqueue.h:127
Defines the data structure used to maintain information about the queue.
Definition: rkhqueue.h:170
RKH_QUENE_T nelems
Number of elements.
Definition: rkhqueue.h:175
void ** pend
Points to the end of the queue storage area.
Definition: rkhqueue.h:205
RKH_QUENE_T nmin
Minimum number of free elements ever in this queue. The nmin low-watermark provides valuable empirica...
Definition: rkhqueue.h:224
void ** pout
Points to the free next place in the storage area.
Definition: rkhqueue.h:187
const struct RKH_SMA_T * sma
Points to the associated SMA (a.k.a Active Object) that receives the enqueued events.
Definition: rkhqueue.h:215
const void ** pstart
Points to beginning of the queue storage area.
Definition: rkhqueue.h:199
RKH_QUEI_T rqi
Performance information. This member is optional, thus it could be eliminated in compile-time with RK...
Definition: rkhqueue.h:233
void ** pin
Points to the next place of queued item.
Definition: rkhqueue.h:193
RKH_QUENE_T qty
Number of elements currently in the queue.
Definition: rkhqueue.h:181
Describes the SMA (active object in UML).
Definition: rkhsma.h:772