• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

include/nucleus/select.h

Go to the documentation of this file.
00001 
00025 #ifndef XNSELECT_H
00026 #define XNSELECT_H
00027 
00031 #include <nucleus/thread.h>
00032 
00033 #define XNSELECT_READ      0
00034 #define XNSELECT_WRITE     1
00035 #define XNSELECT_EXCEPT    2
00036 #define XNSELECT_MAX_TYPES 3
00037 
00038 struct xnselector {
00039         xnsynch_t synchbase;
00040         struct fds {
00041                 fd_set expected;
00042                 fd_set pending;
00043         } fds [XNSELECT_MAX_TYPES];
00044         xnholder_t destroy_link;
00045         xnqueue_t bindings; /* only used by xnselector_destroy */
00046 };
00047 
00048 #define __NFDBITS__     (8 * sizeof(unsigned long))
00049 #define __FDSET_LONGS__ (__FD_SETSIZE/__NFDBITS__)
00050 #define __FDELT__(d)    ((d) / __NFDBITS__)
00051 #define __FDMASK__(d)   (1UL << ((d) % __NFDBITS__))
00052 
00053 static inline void __FD_SET__(unsigned long __fd, __kernel_fd_set *__fdsetp)
00054 {
00055         unsigned long __tmp = __fd / __NFDBITS__;
00056         unsigned long __rem = __fd % __NFDBITS__;
00057         __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
00058 }
00059 
00060 static inline void __FD_CLR__(unsigned long __fd, __kernel_fd_set *__fdsetp)
00061 {
00062         unsigned long __tmp = __fd / __NFDBITS__;
00063         unsigned long __rem = __fd % __NFDBITS__;
00064         __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
00065 }
00066 
00067 static inline int __FD_ISSET__(unsigned long __fd, const __kernel_fd_set *__p)
00068 {
00069         unsigned long __tmp = __fd / __NFDBITS__;
00070         unsigned long __rem = __fd % __NFDBITS__;
00071         return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
00072 }
00073 
00074 static inline void __FD_ZERO__(__kernel_fd_set *__p)
00075 {
00076         unsigned long *__tmp = __p->fds_bits;
00077         int __i;
00078 
00079         __i = __FDSET_LONGS__;
00080         while (__i) {
00081                 __i--;
00082                 *__tmp = 0;
00083                 __tmp++;
00084         }
00085 }
00086 
00087 #ifdef CONFIG_XENO_OPT_SELECT
00088 
00089 struct xnselect {
00090         xnqueue_t bindings;
00091 };
00092 
00093 #define DECLARE_XNSELECT(name) struct xnselect name
00094 
00095 struct xnselect_binding {
00096         struct xnselector *selector;
00097         struct xnselect *fd;
00098         unsigned type;
00099         unsigned bit_index;
00100         xnholder_t link;  /* link in selected fds list. */
00101         xnholder_t slink; /* link in selector list */
00102 };
00103 
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif /* __cplusplus */
00107 
00108 void xnselect_init(struct xnselect *select_block);
00109 
00110 int xnselect_bind(struct xnselect *select_block,
00111                   struct xnselect_binding *binding,
00112                   struct xnselector *selector,
00113                   unsigned type,
00114                   unsigned bit_index,
00115                   unsigned state);
00116 
00117 int __xnselect_signal(struct xnselect *select_block, unsigned state);
00118 
00129 static inline int
00130 xnselect_signal(struct xnselect *select_block, unsigned state)
00131 {
00132         if (!emptyq_p(&select_block->bindings))
00133                 return __xnselect_signal(select_block, state);
00134         return 0;
00135 }
00136 
00137 void xnselect_destroy(struct xnselect *select_block);
00138 
00139 int xnselector_init(struct xnselector *selector);
00140 
00141 int xnselect(struct xnselector *selector,
00142              fd_set *out_fds[XNSELECT_MAX_TYPES],
00143              fd_set *in_fds[XNSELECT_MAX_TYPES],
00144              int nfds,
00145              xnticks_t timeout, xntmode_t timeout_mode);
00146 
00147 void xnselector_destroy(struct xnselector *selector);
00148 
00149 int xnselect_mount(void);
00150 
00151 int xnselect_umount(void);
00152 
00153 #ifdef __cplusplus
00154 }
00155 #endif /* __cplusplus */
00156 
00157 #else /* !CONFIG_XENO_OPT_SELECT */
00158 struct xnselector;
00159 #define DECLARE_XNSELECT(name)
00160 #define xnselect_init(block)
00161 #define xnselect_bind(select_block,binding,selector,type,bit_index,state) \
00162         ({ -EBADF; })
00163 #define xnselect_signal(block, state) ({ int __ret = 0; __ret; })
00164 #define xnselect_destroy(block)
00165 #endif /* !CONFIG_XENO_OPT_SELECT */
00166 
00169 #endif /* XNSELECT_H */

Generated on Wed Jan 23 2013 13:24:01 for Xenomai API by  doxygen 1.7.1