Xenomai  3.1
buffer.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_BUFFER_H
19 #define _XENOMAI_ALCHEMY_BUFFER_H
20 
21 #include <stdint.h>
22 #include <alchemy/timer.h>
23 
30 #define B_PRIO 0x1 /* Pend by task priority order. */
31 #define B_FIFO 0x0 /* Pend by FIFO order. */
32 
33 struct RT_BUFFER {
34  uintptr_t handle;
35 };
36 
37 typedef struct RT_BUFFER RT_BUFFER;
38 
51  int iwaiters;
56  int owaiters;
60  size_t totalmem;
64  size_t availmem;
68  char name[XNOBJECT_NAME_LEN];
69 };
70 
71 typedef struct RT_BUFFER_INFO RT_BUFFER_INFO;
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 int rt_buffer_create(RT_BUFFER *bf,
78  const char *name,
79  size_t bufsz,
80  int mode);
81 
82 int rt_buffer_delete(RT_BUFFER *bf);
83 
84 ssize_t rt_buffer_write_timed(RT_BUFFER *bf,
85  const void *ptr, size_t size,
86  const struct timespec *abs_timeout);
87 
88 static inline
89 ssize_t rt_buffer_write_until(RT_BUFFER *bf,
90  const void *ptr, size_t size,
91  RTIME timeout)
92 {
93  struct timespec ts;
94  return rt_buffer_write_timed(bf, ptr, size,
95  alchemy_abs_timeout(timeout, &ts));
96 }
97 
98 static inline
99 ssize_t rt_buffer_write(RT_BUFFER *bf,
100  const void *ptr, size_t size,
101  RTIME timeout)
102 {
103  struct timespec ts;
104  return rt_buffer_write_timed(bf, ptr, size,
105  alchemy_rel_timeout(timeout, &ts));
106 }
107 
108 ssize_t rt_buffer_read_timed(RT_BUFFER *bf,
109  void *ptr, size_t size,
110  const struct timespec *abs_timeout);
111 
112 static inline
113 ssize_t rt_buffer_read_until(RT_BUFFER *bf,
114  void *ptr, size_t size,
115  RTIME timeout)
116 {
117  struct timespec ts;
118  return rt_buffer_read_timed(bf, ptr, size,
119  alchemy_abs_timeout(timeout, &ts));
120 }
121 
122 static inline
123 ssize_t rt_buffer_read(RT_BUFFER *bf,
124  void *ptr, size_t size,
125  RTIME timeout)
126 {
127  struct timespec ts;
128  return rt_buffer_read_timed(bf, ptr, size,
129  alchemy_rel_timeout(timeout, &ts));
130 }
131 
132 int rt_buffer_clear(RT_BUFFER *bf);
133 
134 int rt_buffer_inquire(RT_BUFFER *bf,
135  RT_BUFFER_INFO *info);
136 
137 int rt_buffer_bind(RT_BUFFER *bf,
138  const char *name, RTIME timeout);
139 
140 int rt_buffer_unbind(RT_BUFFER *bf);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
148 #endif /* _XENOMAI_ALCHEMY_BUFFER_H */
int rt_buffer_create(RT_BUFFER *bf, const char *name, size_t bufsz, int mode)
Create an IPC buffer.
Definition: buffer.c:214
int rt_buffer_clear(RT_BUFFER *bf)
Clear an IPC buffer.
Definition: buffer.c:829
int rt_buffer_unbind(RT_BUFFER *bf)
Unbind from an IPC buffer.
Definition: buffer.c:967
size_t availmem
Amount of memory currently available for holding more data.
Definition: buffer.h:64
ssize_t rt_buffer_read_timed(RT_BUFFER *bf, void *ptr, size_t size, const struct timespec *abs_timeout)
Read from an IPC buffer.
Definition: buffer.c:462
int rt_buffer_delete(RT_BUFFER *bf)
Delete an IPC buffer.
Definition: buffer.c:309
int iwaiters
Number of tasks waiting on the read side of the buffer for input data.
Definition: buffer.h:51
static ssize_t rt_buffer_write_until(RT_BUFFER *bf, const void *ptr, size_t size, RTIME timeout)
Write to an IPC buffer (with absolute scalar timeout).
Definition: buffer.h:89
static ssize_t rt_buffer_read(RT_BUFFER *bf, void *ptr, size_t size, RTIME timeout)
Read from an IPC buffer (with relative scalar timeout).
Definition: buffer.h:123
ssize_t rt_buffer_write_timed(RT_BUFFER *bf, const void *ptr, size_t size, const struct timespec *abs_timeout)
Write to an IPC buffer.
Definition: buffer.c:688
int rt_buffer_bind(RT_BUFFER *bf, const char *name, RTIME timeout)
Bind to an IPC buffer.
Definition: buffer.c:944
size_t totalmem
Overall size of buffer (in bytes).
Definition: buffer.h:60
static ssize_t rt_buffer_read_until(RT_BUFFER *bf, void *ptr, size_t size, RTIME timeout)
Read from an IPC buffer (with absolute scalar timeout).
Definition: buffer.h:113
Buffer status descriptor.
Definition: buffer.h:46
int owaiters
Number of tasks waiting on the write side of the buffer for sending out data.
Definition: buffer.h:56
static ssize_t rt_buffer_write(RT_BUFFER *bf, const void *ptr, size_t size, RTIME timeout)
Write to an IPC buffer (with relative scalar timeout).
Definition: buffer.h:99
char name[XNOBJECT_NAME_LEN]
Name of the buffer.
Definition: buffer.h:68
int rt_buffer_inquire(RT_BUFFER *bf, RT_BUFFER_INFO *info)
Query buffer status.
Definition: buffer.c:874