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 
00062     xnhandle_t opaque;
00063 
00064     void *opaque2;
00065 
00066     caddr_t mapbase;
00067 
00068     size_t mapsize;
00069 
00070 } RT_QUEUE_PLACEHOLDER;
00071 
00072 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00073 
00074 #include <native/ppd.h>
00075 
00076 #define XENO_QUEUE_MAGIC 0x55550707
00077 
00078 typedef struct rt_queue {
00079 
00080     unsigned magic;   /* !< Magic code - must be first */
00081 
00082     xnsynch_t synch_base; /* !< Base synchronization object. */
00083 
00084     xnqueue_t pendq;    /* !< Pending message queue. */
00085 
00086     xnheap_t bufpool;   /* !< Message buffer pool. */
00087 
00088     int mode;           /* !< Creation mode. */
00089 
00090     xnhandle_t handle;  /* !< Handle in registry -- zero if unregistered. */
00091 
00092     int qlimit;         /* !< Maximum queued elements. */
00093 
00094     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00095 
00096 #ifdef CONFIG_XENO_OPT_PERVASIVE
00097     pid_t cpid;                 /* !< Creator's pid. */
00098 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00099 
00100     xnholder_t rlink;           /* !< Link in resource queue. */
00101 
00102 #define rlink2queue(ln) container_of(ln, RT_QUEUE, rlink)
00103 
00104     xnqueue_t *rqueue;          /* !< Backpointer to resource queue. */
00105 
00106 } RT_QUEUE;
00107 
00108 typedef struct rt_queue_msg {
00109 
00110     size_t size;
00111 
00112     volatile unsigned refcount;
00113 
00114     xnholder_t link;
00115 
00116 #define link2rtmsg(ln)          container_of(ln, rt_queue_msg_t, link)
00117 
00118 } rt_queue_msg_t;
00119 
00120 #ifdef __cplusplus
00121 extern "C" {
00122 #endif
00123 
00124 #ifdef CONFIG_XENO_OPT_NATIVE_QUEUE
00125 
00126 int __native_queue_pkg_init(void);
00127 
00128 void __native_queue_pkg_cleanup(void);
00129 
00130 static inline void __native_queue_flush_rq(xnqueue_t *rq)
00131 {
00132         xeno_flush_rq(RT_QUEUE, rq, queue);
00133 }
00134 
00135 #else /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
00136 
00137 #define __native_queue_pkg_init()               ({ 0; })
00138 #define __native_queue_pkg_cleanup()            do { } while(0)
00139 #define __native_queue_flush_rq(rq)             do { } while(0)
00140 
00141 #endif /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
00142 
00143 #ifdef __cplusplus
00144 }
00145 #endif
00146 
00147 #else /* !(__KERNEL__ || __XENO_SIM__) */
00148 
00149 typedef RT_QUEUE_PLACEHOLDER RT_QUEUE;
00150 
00151 #ifdef __cplusplus
00152 extern "C" {
00153 #endif
00154 
00155 int rt_queue_bind(RT_QUEUE *q,
00156                   const char *name,
00157                   RTIME timeout);
00158 
00159 int rt_queue_unbind(RT_QUEUE *q);
00160 
00161 #ifdef __cplusplus
00162 }
00163 #endif
00164 
00165 #endif /* __KERNEL__ || __XENO_SIM__ */
00166 
00167 #ifdef __cplusplus
00168 extern "C" {
00169 #endif
00170 
00171 /* Public interface. */
00172 
00173 int rt_queue_create(RT_QUEUE *q,
00174                     const char *name,
00175                     size_t poolsize,
00176                     size_t qlimit,
00177                     int mode);
00178 
00179 int rt_queue_delete(RT_QUEUE *q);
00180 
00181 void *rt_queue_alloc(RT_QUEUE *q,
00182                      size_t size);
00183 
00184 int rt_queue_free(RT_QUEUE *q,
00185                   void *buf);
00186 
00187 int rt_queue_send(RT_QUEUE *q,
00188                   void *buf,
00189                   size_t size,
00190                   int mode);
00191 
00192 int rt_queue_write(RT_QUEUE *q,
00193                    const void *buf,
00194                    size_t size,
00195                    int mode);
00196 
00197 ssize_t rt_queue_receive(RT_QUEUE *q,
00198                          void **bufp,
00199                          RTIME timeout);
00200 
00201 static inline ssize_t __deprecated_call__ rt_queue_recv(RT_QUEUE *q,
00202                                                         void **bufp,
00203                                                         RTIME timeout)
00204 {
00205     return rt_queue_receive(q,bufp,timeout);
00206 }
00207 
00208 ssize_t rt_queue_read(RT_QUEUE *q,
00209                       void *bufp,
00210                       size_t size,
00211                       RTIME timeout);
00212 
00213 int rt_queue_inquire(RT_QUEUE *q,
00214                      RT_QUEUE_INFO *info);
00215 
00216 #ifdef __cplusplus
00217 }
00218 #endif
00219 
00220 #endif /* !_XENO_QUEUE_H */

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3