Xenomai API  2.5.6.1
include/native/queue.h
Go to the documentation of this file.
00001 
00022 #ifndef _XENO_QUEUE_H
00023 #define _XENO_QUEUE_H
00024 
00025 #include <nucleus/synch.h>
00026 #include <nucleus/heap.h>
00027 #include <native/types.h>
00028 
00029 /* Creation flags. */
00030 #define Q_PRIO   XNSYNCH_PRIO   /* Pend by task priority order. */
00031 #define Q_FIFO   XNSYNCH_FIFO   /* Pend by FIFO order. */
00032 #define Q_DMA    0x100          /* Use memory suitable for DMA. */
00033 #define Q_SHARED 0x200          /* Use mappable shared memory. */
00034 
00035 #define Q_UNLIMITED 0           /* No size limit. */
00036 
00037 /* Operation flags. */
00038 #define Q_NORMAL     0x0
00039 #define Q_URGENT     0x1
00040 #define Q_BROADCAST  0x2
00041 
00042 typedef struct rt_queue_info {
00043 
00044     int nwaiters;               /* !< Number of pending tasks. */
00045 
00046     int nmessages;              /* !< Number of queued messages. */
00047 
00048     int mode;                   /* !< Creation mode. */
00049 
00050     size_t qlimit;              /* !< Queue limit. */
00051 
00052     size_t poolsize;            /* !< Size of pool memory (in bytes). */
00053 
00054     size_t usedmem;             /* !< Amount of pool memory used (in bytes). */
00055 
00056     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00057 
00058 } RT_QUEUE_INFO;
00059 
00060 typedef struct rt_queue_placeholder {
00061         xnhandle_t opaque;
00062         void *opaque2;
00063         caddr_t mapbase;
00064         size_t mapsize;
00065         xnheap_area_decl();
00066 } RT_QUEUE_PLACEHOLDER;
00067 
00068 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00069 
00070 #include <native/ppd.h>
00071 
00072 #define XENO_QUEUE_MAGIC 0x55550707
00073 
00074 typedef struct rt_queue {
00075 
00076     unsigned magic;   /* !< Magic code - must be first */
00077 
00078     xnsynch_t synch_base; /* !< Base synchronization object. */
00079 
00080     xnqueue_t pendq;    /* !< Pending message queue. */
00081 
00082     xnheap_t bufpool;   /* !< Message buffer pool. */
00083 
00084     int mode;           /* !< Creation mode. */
00085 
00086     xnhandle_t handle;  /* !< Handle in registry -- zero if unregistered. */
00087 
00088     int qlimit;         /* !< Maximum queued elements. */
00089 
00090     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00091 
00092 #ifdef CONFIG_XENO_OPT_PERVASIVE
00093     pid_t cpid;                 /* !< Creator's pid. */
00094 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00095 
00096     xnholder_t rlink;           /* !< Link in resource queue. */
00097 
00098 #define rlink2queue(ln) container_of(ln, RT_QUEUE, rlink)
00099 
00100     xnqueue_t *rqueue;          /* !< Backpointer to resource queue. */
00101 
00102 } RT_QUEUE;
00103 
00104 typedef struct rt_queue_msg {
00105 
00106     size_t size;
00107 
00108     volatile unsigned refcount;
00109 
00110     xnholder_t link;
00111 
00112 #define link2rtmsg(ln)          container_of(ln, rt_queue_msg_t, link)
00113 
00114 } rt_queue_msg_t;
00115 
00116 #ifdef __cplusplus
00117 extern "C" {
00118 #endif
00119 
00120 #ifdef CONFIG_XENO_OPT_NATIVE_QUEUE
00121 
00122 int __native_queue_pkg_init(void);
00123 
00124 void __native_queue_pkg_cleanup(void);
00125 
00126 static inline void __native_queue_flush_rq(xnqueue_t *rq)
00127 {
00128         xeno_flush_rq_norelease(RT_QUEUE, rq, queue);
00129 }
00130 
00131 ssize_t rt_queue_receive_inner(RT_QUEUE *q, void **bufp,
00132                                xntmode_t timeout_mode, RTIME timeout);
00133 
00134 int rt_queue_delete_inner(RT_QUEUE *q,
00135                           void __user *mapaddr);
00136 
00137 #else /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
00138 
00139 #define __native_queue_pkg_init()               ({ 0; })
00140 #define __native_queue_pkg_cleanup()            do { } while(0)
00141 #define __native_queue_flush_rq(rq)             do { } while(0)
00142 
00143 #endif /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
00144 
00145 #ifdef __cplusplus
00146 }
00147 #endif
00148 
00149 #else /* !(__KERNEL__ || __XENO_SIM__) */
00150 
00151 typedef RT_QUEUE_PLACEHOLDER RT_QUEUE;
00152 
00153 #ifdef __cplusplus
00154 extern "C" {
00155 #endif
00156 
00157 int rt_queue_bind(RT_QUEUE *q,
00158                   const char *name,
00159                   RTIME timeout);
00160 
00161 int rt_queue_unbind(RT_QUEUE *q);
00162 
00163 #ifdef __cplusplus
00164 }
00165 #endif
00166 
00167 #endif /* __KERNEL__ || __XENO_SIM__ */
00168 
00169 #ifdef __cplusplus
00170 extern "C" {
00171 #endif
00172 
00173 /* Public interface. */
00174 
00175 int rt_queue_create(RT_QUEUE *q,
00176                     const char *name,
00177                     size_t poolsize,
00178                     size_t qlimit,
00179                     int mode);
00180 
00181 int rt_queue_delete(RT_QUEUE *q);
00182 
00183 void *rt_queue_alloc(RT_QUEUE *q,
00184                      size_t size);
00185 
00186 int rt_queue_free(RT_QUEUE *q,
00187                   void *buf);
00188 
00189 int rt_queue_send(RT_QUEUE *q,
00190                   void *buf,
00191                   size_t size,
00192                   int mode);
00193 
00194 int rt_queue_write(RT_QUEUE *q,
00195                    const void *buf,
00196                    size_t size,
00197                    int mode);
00198 
00199 ssize_t rt_queue_receive(RT_QUEUE *q,
00200                          void **bufp,
00201                          RTIME timeout);
00202 
00203 ssize_t rt_queue_receive_until(RT_QUEUE *q,
00204                                void **bufp,
00205                                RTIME timeout);
00206 
00207 ssize_t rt_queue_read(RT_QUEUE *q,
00208                       void *bufp,
00209                       size_t size,
00210                       RTIME timeout);
00211 
00212 ssize_t rt_queue_read_until(RT_QUEUE *q,
00213                             void *bufp,
00214                             size_t size,
00215                             RTIME timeout);
00216 
00217 int rt_queue_flush(RT_QUEUE *q);
00218 
00219 int rt_queue_inquire(RT_QUEUE *q,
00220                      RT_QUEUE_INFO *info);
00221 
00222 #ifdef __cplusplus
00223 }
00224 #endif
00225 
00226 #endif /* !_XENO_QUEUE_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines