Xenomai API  2.6.5
queue.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_QUEUE_H
23 #define _XENO_QUEUE_H
24 
25 #include <nucleus/synch.h>
26 #include <nucleus/heap.h>
27 #include <native/types.h>
28 
29 /* Creation flags. */
30 #define Q_PRIO XNSYNCH_PRIO /* Pend by task priority order. */
31 #define Q_FIFO XNSYNCH_FIFO /* Pend by FIFO order. */
32 #define Q_DMA 0x100 /* Use memory suitable for DMA. */
33 #define Q_SHARED 0x200 /* Use mappable shared memory. */
34 
35 #define Q_UNLIMITED 0 /* No size limit. */
36 
37 /* Operation flags. */
38 #define Q_NORMAL 0x0
39 #define Q_URGENT 0x1
40 #define Q_BROADCAST 0x2
41 
42 typedef struct rt_queue_info {
43 
44  int nwaiters; /* !< Number of pending tasks. */
45 
46  int nmessages; /* !< Number of queued messages. */
47 
48  int mode; /* !< Creation mode. */
49 
50  size_t qlimit; /* !< Queue limit. */
51 
52  size_t poolsize; /* !< Size of pool memory (in bytes). */
53 
54  size_t usedmem; /* !< Amount of pool memory used (in bytes). */
55 
56  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
57 
58 } RT_QUEUE_INFO;
59 
60 typedef struct rt_queue_placeholder {
61  xnhandle_t opaque;
62  void *opaque2;
63  caddr_t mapbase;
64  size_t mapsize;
65  unsigned long area;
66 } RT_QUEUE_PLACEHOLDER;
67 
68 #if defined(__KERNEL__) || defined(__XENO_SIM__)
69 
70 #include <native/ppd.h>
71 
72 #define XENO_QUEUE_MAGIC 0x55550707
73 
74 typedef struct rt_queue {
75 
76  unsigned magic; /* !< Magic code - must be first */
77 
78  xnsynch_t synch_base; /* !< Base synchronization object. */
79 
80  xnqueue_t pendq; /* !< Pending message queue. */
81 
82  xnheap_t bufpool; /* !< Message buffer pool. */
83 
84  int mode; /* !< Creation mode. */
85 
86  xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */
87 
88  int qlimit; /* !< Maximum queued elements. */
89 
90  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
91 
92 #ifdef CONFIG_XENO_OPT_PERVASIVE
93  pid_t cpid; /* !< Creator's pid. */
94 #endif /* CONFIG_XENO_OPT_PERVASIVE */
95 
96  xnholder_t rlink; /* !< Link in resource queue. */
97 
98 #define rlink2queue(ln) container_of(ln, RT_QUEUE, rlink)
99 
100  xnqueue_t *rqueue; /* !< Backpointer to resource queue. */
101 
102 } RT_QUEUE;
103 
104 typedef struct rt_queue_msg {
105 
106  size_t size;
107 
108  volatile unsigned refcount;
109 
110  xnholder_t link;
111 
112 #define link2rtmsg(ln) container_of(ln, rt_queue_msg_t, link)
113 
114 } rt_queue_msg_t;
115 
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 
120 #ifdef CONFIG_XENO_OPT_NATIVE_QUEUE
121 
122 int __native_queue_pkg_init(void);
123 
124 void __native_queue_pkg_cleanup(void);
125 
126 static inline void __native_queue_flush_rq(xnqueue_t *rq)
127 {
128  xeno_flush_rq_norelease(RT_QUEUE, rq, queue);
129 }
130 
131 ssize_t rt_queue_receive_inner(RT_QUEUE *q, void **bufp,
132  xntmode_t timeout_mode, RTIME timeout);
133 
134 int rt_queue_delete_inner(RT_QUEUE *q,
135  void __user *mapaddr);
136 
137 #else /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
138 
139 #define __native_queue_pkg_init() ({ 0; })
140 #define __native_queue_pkg_cleanup() do { } while(0)
141 #define __native_queue_flush_rq(rq) do { } while(0)
142 
143 #endif /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #else /* !(__KERNEL__ || __XENO_SIM__) */
150 
151 typedef RT_QUEUE_PLACEHOLDER RT_QUEUE;
152 
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156 
157 int rt_queue_bind(RT_QUEUE *q,
158  const char *name,
159  RTIME timeout);
160 
161 int rt_queue_unbind(RT_QUEUE *q);
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif /* __KERNEL__ || __XENO_SIM__ */
168 
169 #ifdef __cplusplus
170 extern "C" {
171 #endif
172 
173 /* Public interface. */
174 
175 int rt_queue_create(RT_QUEUE *q,
176  const char *name,
177  size_t poolsize,
178  size_t qlimit,
179  int mode);
180 
181 int rt_queue_delete(RT_QUEUE *q);
182 
183 void *rt_queue_alloc(RT_QUEUE *q,
184  size_t size);
185 
186 int rt_queue_free(RT_QUEUE *q,
187  void *buf);
188 
189 int rt_queue_send(RT_QUEUE *q,
190  void *buf,
191  size_t size,
192  int mode);
193 
194 int rt_queue_write(RT_QUEUE *q,
195  const void *buf,
196  size_t size,
197  int mode);
198 
199 ssize_t rt_queue_receive(RT_QUEUE *q,
200  void **bufp,
201  RTIME timeout);
202 
203 ssize_t rt_queue_receive_until(RT_QUEUE *q,
204  void **bufp,
205  RTIME timeout);
206 
207 ssize_t rt_queue_read(RT_QUEUE *q,
208  void *bufp,
209  size_t size,
210  RTIME timeout);
211 
212 ssize_t rt_queue_read_until(RT_QUEUE *q,
213  void *bufp,
214  size_t size,
215  RTIME timeout);
216 
217 int rt_queue_flush(RT_QUEUE *q);
218 
219 int rt_queue_inquire(RT_QUEUE *q,
220  RT_QUEUE_INFO *info);
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* !_XENO_QUEUE_H */
int rt_queue_bind(RT_QUEUE *q, const char *name, RTIME timeout)
Bind to a shared message queue.
Definition: queue.c:71
int rt_queue_free(RT_QUEUE *q, void *buf)
Free a message queue buffer.
Definition: queue.c:120
int rt_queue_flush(RT_QUEUE *q)
Flush a message queue.
Definition: queue.c:219
int rt_queue_unbind(RT_QUEUE *q)
Unbind from a shared message queue.
Definition: queue.c:82
ssize_t rt_queue_read_until(RT_QUEUE *q, void *bufp, size_t size, RTIME timeout)
Read a message from a queue (with absolute timeout date).
Definition: queue.c:198
void * rt_queue_alloc(RT_QUEUE *q, size_t size)
Allocate a message queue buffer.
Definition: queue.c:111
ssize_t rt_queue_receive(RT_QUEUE *q, void **bufp, RTIME timeout)
Receive a message from a queue.
Definition: queue.c:153
int rt_queue_send(RT_QUEUE *q, void *buf, size_t size, int mode)
Send a message to a queue.
Definition: queue.c:125
This file is part of the Xenomai project.
int rt_queue_create(RT_QUEUE *q, const char *name, size_t poolsize, size_t qlimit, int mode)
Create a message queue.
Definition: queue.c:49
ssize_t rt_queue_receive_until(RT_QUEUE *q, void **bufp, RTIME timeout)
Receive a message from a queue (with absolute timeout date).
Definition: queue.c:168
ssize_t rt_queue_read(RT_QUEUE *q, void *bufp, size_t size, RTIME timeout)
Read a message from a queue.
Definition: queue.c:183
int rt_queue_inquire(RT_QUEUE *q, RT_QUEUE_INFO *info)
Inquire about a message queue.
Definition: queue.c:213
int rt_queue_delete(RT_QUEUE *q)
Delete a message queue.
Definition: queue.c:96
This file is part of the Xenomai project.
int rt_queue_write(RT_QUEUE *q, const void *buf, size_t size, int mode)
Write a message to a queue.
Definition: queue.c:139