Xenomai API  2.6.5
select.h
Go to the documentation of this file.
1 
25 #ifndef XNSELECT_H
26 #define XNSELECT_H
27 
31 #include <nucleus/thread.h>
32 
33 #define XNSELECT_READ 0
34 #define XNSELECT_WRITE 1
35 #define XNSELECT_EXCEPT 2
36 #define XNSELECT_MAX_TYPES 3
37 
38 struct xnselector {
39  xnsynch_t synchbase;
40  struct fds {
41  fd_set expected;
42  fd_set pending;
43  } fds [XNSELECT_MAX_TYPES];
44  xnholder_t destroy_link;
45  xnqueue_t bindings; /* only used by xnselector_destroy */
46 };
47 
48 #define __NFDBITS__ (8 * sizeof(unsigned long))
49 #define __FDSET_LONGS__ (__FD_SETSIZE/__NFDBITS__)
50 #define __FDELT__(d) ((d) / __NFDBITS__)
51 #define __FDMASK__(d) (1UL << ((d) % __NFDBITS__))
52 
53 static inline void __FD_SET__(unsigned long __fd, __kernel_fd_set *__fdsetp)
54 {
55  unsigned long __tmp = __fd / __NFDBITS__;
56  unsigned long __rem = __fd % __NFDBITS__;
57  __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
58 }
59 
60 static inline void __FD_CLR__(unsigned long __fd, __kernel_fd_set *__fdsetp)
61 {
62  unsigned long __tmp = __fd / __NFDBITS__;
63  unsigned long __rem = __fd % __NFDBITS__;
64  __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
65 }
66 
67 static inline int __FD_ISSET__(unsigned long __fd, const __kernel_fd_set *__p)
68 {
69  unsigned long __tmp = __fd / __NFDBITS__;
70  unsigned long __rem = __fd % __NFDBITS__;
71  return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
72 }
73 
74 static inline void __FD_ZERO__(__kernel_fd_set *__p)
75 {
76  unsigned long *__tmp = __p->fds_bits;
77  int __i;
78 
79  __i = __FDSET_LONGS__;
80  while (__i) {
81  __i--;
82  *__tmp = 0;
83  __tmp++;
84  }
85 }
86 
87 #ifdef CONFIG_XENO_OPT_SELECT
88 
89 struct xnselect {
90  xnqueue_t bindings;
91 };
92 
93 #define DECLARE_XNSELECT(name) struct xnselect name
94 
95 struct xnselect_binding {
96  struct xnselector *selector;
97  struct xnselect *fd;
98  unsigned type;
99  unsigned bit_index;
100  xnholder_t link; /* link in selected fds list. */
101  xnholder_t slink; /* link in selector list */
102 };
103 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif /* __cplusplus */
107 
108 void xnselect_init(struct xnselect *select_block);
109 
110 int xnselect_bind(struct xnselect *select_block,
111  struct xnselect_binding *binding,
112  struct xnselector *selector,
113  unsigned type,
114  unsigned bit_index,
115  unsigned state);
116 
117 int __xnselect_signal(struct xnselect *select_block, unsigned state);
118 
129 static inline int
130 xnselect_signal(struct xnselect *select_block, unsigned state)
131 {
132  if (!emptyq_p(&select_block->bindings))
133  return __xnselect_signal(select_block, state);
134  return 0;
135 }
136 
137 void xnselect_destroy(struct xnselect *select_block);
138 
139 int xnselector_init(struct xnselector *selector);
140 
141 int xnselect(struct xnselector *selector,
142  fd_set *out_fds[XNSELECT_MAX_TYPES],
143  fd_set *in_fds[XNSELECT_MAX_TYPES],
144  int nfds,
145  xnticks_t timeout, xntmode_t timeout_mode);
146 
147 void xnselector_destroy(struct xnselector *selector);
148 
149 int xnselect_mount(void);
150 
151 int xnselect_umount(void);
152 
153 #ifdef __cplusplus
154 }
155 #endif /* __cplusplus */
156 
157 #else /* !CONFIG_XENO_OPT_SELECT */
158 struct xnselector;
159 #define DECLARE_XNSELECT(name)
160 #define xnselect_init(block)
161 #define xnselect_bind(select_block,binding,selector,type,bit_index,state) \
162  ({ -EBADF; })
163 #define xnselect_signal(block, state) ({ int __ret = 0; __ret; })
164 #define xnselect_destroy(block)
165 #endif /* !CONFIG_XENO_OPT_SELECT */
166 
169 #endif /* XNSELECT_H */
int xnselect_bind(struct xnselect *select_block, struct xnselect_binding *binding, struct xnselector *selector, unsigned type, unsigned index, unsigned state)
Bind a file descriptor (represented by its xnselect structure) to a selector block.
Definition: select.c:110
int xnselect(struct xnselector *selector, fd_set *out_fds[XNSELECT_MAX_TYPES], fd_set *in_fds[XNSELECT_MAX_TYPES], int nfds, xnticks_t timeout, xntmode_t timeout_mode)
Check the state of a number of file descriptors, wait for a state change if no descriptor is ready...
Definition: select.c:322
void xnselect_destroy(struct xnselect *select_block)
Destroy the xnselect structure associated with a file descriptor.
Definition: select.c:179
int xnselector_init(struct xnselector *selector)
Initialize a selector structure.
Definition: select.c:285
void xnselector_destroy(struct xnselector *selector)
Destroy a selector block.
Definition: select.c:397
void xnselect_init(struct xnselect *select_block)
Initialize a struct xnselect structure.
Definition: select.c:70