Xenomai  3.0.8
queue.h
1 /*
2  * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _XENOMAI_ALCHEMY_QUEUE_H
19 #define _XENOMAI_ALCHEMY_QUEUE_H
20 
21 #include <stdint.h>
22 #include <alchemy/timer.h>
23 
30 #define Q_PRIO 0x1 /* Pend by task priority order. */
31 #define Q_FIFO 0x0 /* Pend by FIFO order. */
32 
33 #define Q_UNLIMITED 0 /* No size limit. */
34 
35 /*
36  * Operation flags.
37  */
38 #define Q_NORMAL 0x0
39 #define Q_URGENT 0x1
40 #define Q_BROADCAST 0x2
41 
42 struct RT_QUEUE {
43  uintptr_t handle;
44 };
45 
46 typedef struct RT_QUEUE RT_QUEUE;
47 
55 struct RT_QUEUE_INFO {
60  int nwaiters;
64  int nmessages;
68  int mode;
72  size_t qlimit;
76  size_t poolsize;
80  size_t usedmem;
84  char name[XNOBJECT_NAME_LEN];
85 };
86 
87 typedef struct RT_QUEUE_INFO RT_QUEUE_INFO;
88 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 
93 int rt_queue_create(RT_QUEUE *queue,
94  const char *name,
95  size_t poolsize, size_t qlimit, int mode);
96 
97 int rt_queue_delete(RT_QUEUE *queue);
98 
99 void *rt_queue_alloc(RT_QUEUE *queue,
100  size_t size);
101 
102 int rt_queue_free(RT_QUEUE *queue,
103  void *buf);
104 
105 int rt_queue_send(RT_QUEUE *queue,
106  const void *buf, size_t size, int mode);
107 
108 int rt_queue_write(RT_QUEUE *queue,
109  const void *buf, size_t size, int mode);
110 
111 ssize_t rt_queue_receive_timed(RT_QUEUE *queue,
112  void **bufp,
113  const struct timespec *abs_timeout);
114 
115 static inline
116 ssize_t rt_queue_receive_until(RT_QUEUE *queue,
117  void **bufp, RTIME timeout)
118 {
119  struct timespec ts;
120  return rt_queue_receive_timed(queue, bufp,
121  alchemy_abs_timeout(timeout, &ts));
122 }
123 
124 static inline
125 ssize_t rt_queue_receive(RT_QUEUE *queue,
126  void **bufp, RTIME timeout)
127 {
128  struct timespec ts;
129  return rt_queue_receive_timed(queue, bufp,
130  alchemy_rel_timeout(timeout, &ts));
131 }
132 
133 ssize_t rt_queue_read_timed(RT_QUEUE *queue,
134  void *buf, size_t size,
135  const struct timespec *abs_timeout);
136 
137 static inline
138 ssize_t rt_queue_read_until(RT_QUEUE *queue,
139  void *buf, size_t size, RTIME timeout)
140 {
141  struct timespec ts;
142  return rt_queue_read_timed(queue, buf, size,
143  alchemy_abs_timeout(timeout, &ts));
144 }
145 
146 static inline
147 ssize_t rt_queue_read(RT_QUEUE *queue,
148  void *buf, size_t size, RTIME timeout)
149 {
150  struct timespec ts;
151  return rt_queue_read_timed(queue, buf, size,
152  alchemy_rel_timeout(timeout, &ts));
153 }
154 
155 int rt_queue_flush(RT_QUEUE *queue);
156 
157 int rt_queue_inquire(RT_QUEUE *queue,
158  RT_QUEUE_INFO *info);
159 
160 int rt_queue_bind(RT_QUEUE *queue,
161  const char *name,
162  RTIME timeout);
163 
164 int rt_queue_unbind(RT_QUEUE *queue);
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
172 #endif /* _XENOMAI_ALCHEMY_QUEUE_H */
size_t poolsize
Size of memory pool for holding message buffers (in bytes).
Definition: queue.h:76
size_t qlimit
Maximum number of messages in queue, zero if unlimited.
Definition: queue.h:72
Queue status descriptor.
Definition: queue.h:55
static ssize_t rt_queue_receive_until(RT_QUEUE *queue, void **bufp, RTIME timeout)
Receive from a queue (with absolute scalar timeout).
Definition: queue.h:116
int rt_queue_bind(RT_QUEUE *queue, const char *name, RTIME timeout)
Bind to a message queue.
Definition: queue.c:1178
int rt_queue_unbind(RT_QUEUE *queue)
Unbind from a message queue.
Definition: queue.c:1200
int rt_queue_create(RT_QUEUE *queue, const char *name, size_t poolsize, size_t qlimit, int mode)
Create a message queue.
Definition: queue.c:204
int mode
Queue mode bits, as given to rt_queue_create().
Definition: queue.h:68
int nwaiters
Number of tasks currently waiting on the queue for messages.
Definition: queue.h:60
size_t usedmem
Amount of memory consumed from the buffer pool.
Definition: queue.h:80
void * rt_queue_alloc(RT_QUEUE *queue, size_t size)
Allocate a message buffer.
Definition: queue.c:353
int rt_queue_delete(RT_QUEUE *queue)
Delete a message queue.
Definition: queue.c:308
int rt_queue_inquire(RT_QUEUE *queue, RT_QUEUE_INFO *info)
Query queue status.
Definition: queue.c:1107
ssize_t rt_queue_receive_timed(RT_QUEUE *queue, void **bufp, const struct timespec *abs_timeout)
Receive a message from a queue (with absolute timeout date).
Definition: queue.c:804
ssize_t rt_queue_read_timed(RT_QUEUE *queue, void *buf, size_t size, const struct timespec *abs_timeout)
Read from a queue.
Definition: queue.c:968
char name[XNOBJECT_NAME_LEN]
Name of message queue.
Definition: queue.h:84
int rt_queue_send(RT_QUEUE *queue, const void *buf, size_t size, int mode)
Send a message to a queue.
Definition: queue.c:501
int rt_queue_flush(RT_QUEUE *queue)
Flush pending messages from a queue.
Definition: queue.c:1051
int nmessages
Number of messages pending in queue.
Definition: queue.h:64
static ssize_t rt_queue_read_until(RT_QUEUE *queue, void *buf, size_t size, RTIME timeout)
Read from a queue (with absolute scalar timeout).
Definition: queue.h:138
int rt_queue_free(RT_QUEUE *queue, void *buf)
Free a message buffer.
Definition: queue.c:407
static ssize_t rt_queue_receive(RT_QUEUE *queue, void **bufp, RTIME timeout)
Receive from a queue (with relative scalar timeout).
Definition: queue.h:125
static ssize_t rt_queue_read(RT_QUEUE *queue, void *buf, size_t size, RTIME timeout)
Read from a queue (with relative scalar timeout).
Definition: queue.h:147