00001
00022 #ifndef _XENO_BUFFER_H
00023 #define _XENO_BUFFER_H
00024
00025 #include <native/types.h>
00026
00027
00028 #define B_PRIO XNSYNCH_PRIO
00029 #define B_FIFO XNSYNCH_FIFO
00030
00031 typedef struct rt_buffer_info {
00032
00033 int iwaiters;
00034 int owaiters;
00035 size_t totalmem;
00036 size_t availmem;
00037 char name[XNOBJECT_NAME_LEN];
00038
00039 } RT_BUFFER_INFO;
00040
00041 typedef struct rt_buffer_placeholder {
00042 xnhandle_t opaque;
00043 } RT_BUFFER_PLACEHOLDER;
00044
00045 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP)
00046
00047 #include <nucleus/synch.h>
00048 #include <nucleus/heap.h>
00049 #include <native/ppd.h>
00050
00051 #define XENO_BUFFER_MAGIC 0x55550c0c
00052
00053 typedef struct rt_buffer {
00054
00055 unsigned magic;
00056
00057 xnsynch_t isynch_base;
00058 xnsynch_t osynch_base;
00059 xnhandle_t handle;
00060 char name[XNOBJECT_NAME_LEN];
00061
00062 int mode;
00063 off_t rdoff;
00064 off_t wroff;
00065 size_t fillsz;
00066
00067 u_long wrtoken;
00068 u_long rdtoken;
00069
00070 size_t bufsz;
00071 caddr_t bufmem;
00072
00073 #ifdef CONFIG_XENO_OPT_PERVASIVE
00074 pid_t cpid;
00075 #endif
00076 xnholder_t rlink;
00077 #define rlink2buffer(ln) container_of(ln, RT_BUFFER, rlink)
00078 xnqueue_t *rqueue;
00079
00080 } RT_BUFFER;
00081
00082 #ifdef __cplusplus
00083 extern "C" {
00084 #endif
00085
00086 #ifdef CONFIG_XENO_OPT_NATIVE_BUFFER
00087
00088 int __native_buffer_pkg_init(void);
00089
00090 void __native_buffer_pkg_cleanup(void);
00091
00092 static inline void __native_buffer_flush_rq(xnqueue_t *rq)
00093 {
00094 xeno_flush_rq(RT_BUFFER, rq, buffer);
00095 }
00096
00097 struct xnbufd;
00098
00099 ssize_t rt_buffer_read_inner(RT_BUFFER *bf, struct xnbufd *bufd,
00100 xntmode_t timeout_mode, RTIME timeout);
00101
00102 ssize_t rt_buffer_write_inner(RT_BUFFER *bf, struct xnbufd *bufd,
00103 xntmode_t timeout_mode, RTIME timeout);
00104
00105 #else
00106
00107 #define __native_buffer_pkg_init() ({ 0; })
00108 #define __native_buffer_pkg_cleanup() do { } while(0)
00109 #define __native_buffer_flush_rq(rq) do { } while(0)
00110
00111 #endif
00112
00113 #ifdef __cplusplus
00114 }
00115 #endif
00116
00117 #else
00118
00119 typedef RT_BUFFER_PLACEHOLDER RT_BUFFER;
00120
00121 #ifdef __cplusplus
00122 extern "C" {
00123 #endif
00124
00125 int rt_buffer_bind(RT_BUFFER *bf,
00126 const char *name,
00127 RTIME timeout);
00128
00129 static inline int rt_buffer_unbind(RT_BUFFER *bf)
00130 {
00131 bf->opaque = XN_NO_HANDLE;
00132 return 0;
00133 }
00134
00135 #ifdef __cplusplus
00136 }
00137 #endif
00138
00139 #endif
00140
00141 #ifdef __cplusplus
00142 extern "C" {
00143 #endif
00144
00145
00146
00147 int rt_buffer_create(RT_BUFFER *bf,
00148 const char *name,
00149 size_t bufsz,
00150 int mode);
00151
00152 int rt_buffer_delete(RT_BUFFER *bf);
00153
00154 ssize_t rt_buffer_write(RT_BUFFER *bf,
00155 const void *ptr, size_t size,
00156 RTIME timeout);
00157
00158 ssize_t rt_buffer_write_until(RT_BUFFER *bf,
00159 const void *ptr, size_t size,
00160 RTIME timeout);
00161
00162 ssize_t rt_buffer_read(RT_BUFFER *bf,
00163 void *ptr, size_t size,
00164 RTIME timeout);
00165
00166 ssize_t rt_buffer_read_until(RT_BUFFER *bf,
00167 void *ptr, size_t size,
00168 RTIME timeout);
00169
00170 int rt_buffer_clear(RT_BUFFER *bf);
00171
00172 int rt_buffer_inquire(RT_BUFFER *bf,
00173 RT_BUFFER_INFO *info);
00174
00175 #ifdef __cplusplus
00176 }
00177 #endif
00178
00179 #endif