Xenomai 3.3.2
Loading...
Searching...
No Matches
select.h
1/*
2 * Copyright (C) 2008 Efixo <gilles.chanteperdrix@xenomai.org>
3 *
4 * Xenomai is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
8 *
9 * Xenomai is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Xenomai; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
18 */
19#ifndef _COBALT_KERNEL_SELECT_H
20#define _COBALT_KERNEL_SELECT_H
21
22#include <cobalt/kernel/list.h>
23#include <cobalt/kernel/thread.h>
24
30#define XNSELECT_READ 0
31#define XNSELECT_WRITE 1
32#define XNSELECT_EXCEPT 2
33#define XNSELECT_MAX_TYPES 3
34
35struct xnselector {
36 struct xnsynch synchbase;
37 struct fds {
38 fd_set expected;
39 fd_set pending;
40 } fds [XNSELECT_MAX_TYPES];
41 struct list_head destroy_link;
42 struct list_head bindings; /* only used by xnselector_destroy */
43};
44
45#define __NFDBITS__ (8 * sizeof(unsigned long))
46#define __FDSET_LONGS__ (__FD_SETSIZE/__NFDBITS__)
47#define __FDELT__(d) ((d) / __NFDBITS__)
48#define __FDMASK__(d) (1UL << ((d) % __NFDBITS__))
49
50static inline void __FD_SET__(unsigned long __fd, __kernel_fd_set *__fdsetp)
51{
52 unsigned long __tmp = __fd / __NFDBITS__;
53 unsigned long __rem = __fd % __NFDBITS__;
54 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
55}
56
57static inline void __FD_CLR__(unsigned long __fd, __kernel_fd_set *__fdsetp)
58{
59 unsigned long __tmp = __fd / __NFDBITS__;
60 unsigned long __rem = __fd % __NFDBITS__;
61 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
62}
63
64static inline int __FD_ISSET__(unsigned long __fd, const __kernel_fd_set *__p)
65{
66 unsigned long __tmp = __fd / __NFDBITS__;
67 unsigned long __rem = __fd % __NFDBITS__;
68 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
69}
70
71static inline void __FD_ZERO__(__kernel_fd_set *__p)
72{
73 unsigned long *__tmp = __p->fds_bits;
74 int __i;
75
76 __i = __FDSET_LONGS__;
77 while (__i) {
78 __i--;
79 *__tmp = 0;
80 __tmp++;
81 }
82}
83
84struct xnselect {
85 struct list_head bindings;
86};
87
88#define DECLARE_XNSELECT(name) struct xnselect name
89
90struct xnselect_binding {
91 struct xnselector *selector;
92 struct xnselect *fd;
93 unsigned int type;
94 unsigned int bit_index;
95 struct list_head link; /* link in selected fds list. */
96 struct list_head slink; /* link in selector list */
97};
98
99void xnselect_init(struct xnselect *select_block);
100
101int xnselect_bind(struct xnselect *select_block,
102 struct xnselect_binding *binding,
103 struct xnselector *selector,
104 unsigned int type,
105 unsigned int bit_index,
106 unsigned int state);
107
108int __xnselect_signal(struct xnselect *select_block, unsigned int state);
109
120static inline int
121xnselect_signal(struct xnselect *select_block, unsigned int state)
122{
123 if (!list_empty(&select_block->bindings))
124 return __xnselect_signal(select_block, state);
125
126 return 0;
127}
128
129void xnselect_destroy(struct xnselect *select_block);
130
131int xnselector_init(struct xnselector *selector);
132
133int xnselect(struct xnselector *selector,
134 fd_set *out_fds[XNSELECT_MAX_TYPES],
135 fd_set *in_fds[XNSELECT_MAX_TYPES],
136 int nfds,
137 xnticks_t timeout, xntmode_t timeout_mode);
138
139void xnselector_destroy(struct xnselector *selector);
140
141int xnselect_mount(void);
142
143int xnselect_umount(void);
144
147#endif /* _COBALT_KERNEL_SELECT_H */
static int xnselect_signal(struct xnselect *select_block, unsigned int state)
Signal a file descriptor state change.
Definition select.h:121
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:321
void xnselect_destroy(struct xnselect *select_block)
Destroy the xnselect structure associated with a file descriptor.
Definition select.c:174
void xnselect_init(struct xnselect *select_block)
Initialize a struct xnselect structure.
Definition select.c:64
void xnselector_destroy(struct xnselector *selector)
Destroy a selector block.
Definition select.c:392
int xnselector_init(struct xnselector *selector)
Initialize a selector structure.
Definition select.c:282