Print this page
libc: only have one select implementation, and move the pollfds onto the heap if they cross some threshold
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/select.h
+++ new/usr/src/uts/common/sys/select.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 /*
31 31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 32 * The Regents of the University of California
33 33 * All Rights Reserved
34 34 *
35 35 * University Acknowledgment- Portions of this document are derived from
36 36 * software developed by the University of California, Berkeley, and its
37 37 * contributors.
38 38 */
39 39
40 40 #ifndef _SYS_SELECT_H
41 41 #define _SYS_SELECT_H
42 42
43 43 #include <sys/feature_tests.h>
44 44
45 45 #ifndef _KERNEL
46 46 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
47 47 #include <sys/time_impl.h>
48 48 #endif
49 49 #include <sys/time.h>
50 50 #endif /* _KERNEL */
51 51
52 52 #ifdef __cplusplus
53 53 extern "C" {
54 54 #endif
55 55
56 56
57 57 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
58 58 /*
59 59 * The sigset_t type is defined in <sys/signal.h> and duplicated
60 60 * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
61 61 * now allows the visibility of signal.h in this header, however
62 62 * an order of inclusion problem occurs as a result of inclusion
63 63 * of <sys/select.h> in <signal.h> under certain conditions.
64 64 * Rather than include <sys/signal.h> here, we've duplicated
65 65 * the sigset_t type instead. This type is required for the XPG6
66 66 * introduced pselect() function also declared in this header.
67 67 */
68 68 #ifndef _SIGSET_T
69 69 #define _SIGSET_T
70 70 typedef struct { /* signal set type */
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
71 71 unsigned int __sigbits[4];
72 72 } sigset_t;
73 73 #endif /* _SIGSET_T */
74 74
75 75 #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
76 76
77 77 /*
78 78 * Select uses bit masks of file descriptors in longs.
79 79 * These macros manipulate such bit fields.
80 80 * FD_SETSIZE may be defined by the user, but the default here
81 - * should be >= NOFILE (param.h).
81 + * should be >= RLIM_FD_MAX.
82 82 */
83 83 #ifndef FD_SETSIZE
84 -#ifdef _LP64
85 84 #define FD_SETSIZE 65536
86 -#else
87 -#define FD_SETSIZE 1024
88 -#endif /* _LP64 */
89 -#elif FD_SETSIZE > 1024 && !defined(_LP64)
90 -#ifdef __PRAGMA_REDEFINE_EXTNAME
91 -#pragma redefine_extname select select_large_fdset
92 -#if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
93 -#pragma redefine_extname pselect pselect_large_fdset
94 -#endif
95 -#else /* __PRAGMA_REDEFINE_EXTNAME */
96 -#define select select_large_fdset
97 -#if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
98 -#define pselect pselect_large_fdset
99 -#endif
100 -#endif /* __PRAGMA_REDEFINE_EXTNAME */
101 85 #endif /* FD_SETSIZE */
102 86
103 87 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
104 88 typedef long fd_mask;
105 89 #endif
106 90 typedef long fds_mask;
107 91
108 92 /*
109 93 * The value of _NBBY needs to be consistant with the value
110 94 * of NBBY in <sys/param.h>.
111 95 */
112 96 #define _NBBY 8
113 97 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
114 98 #ifndef NBBY /* number of bits per byte */
115 99 #define NBBY _NBBY
116 100 #endif
117 101 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
118 102
119 103 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
120 104 #define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
121 105 #endif
122 106 #define FD_NFDBITS (sizeof (fds_mask) * _NBBY) /* bits per mask */
123 107
124 108 #define __howmany(__x, __y) (((__x)+((__y)-1))/(__y))
125 109 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
126 110 #ifndef howmany
127 111 #define howmany(x, y) (((x)+((y)-1))/(y))
128 112 #endif
129 113 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
130 114
131 115 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
132 116 typedef struct fd_set {
133 117 #else
134 118 typedef struct __fd_set {
135 119 #endif
136 120 long fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
137 121 } fd_set;
138 122
139 123 #define FD_SET(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
140 124 (1ul << ((__n) % FD_NFDBITS)))
141 125
142 126 #define FD_CLR(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
143 127 ~(1ul << ((__n) % FD_NFDBITS)))
144 128
145 129 #define FD_ISSET(__n, __p) (((__p)->fds_bits[(__n)/FD_NFDBITS] & \
146 130 (1ul << ((__n) % FD_NFDBITS))) != 0l)
147 131
148 132 #ifdef _KERNEL
149 133 #define FD_ZERO(p) bzero((p), sizeof (*(p)))
150 134 #else
151 135 #define FD_ZERO(__p) (void) memset((__p), 0, sizeof (*(__p)))
152 136 #endif /* _KERNEL */
153 137
154 138 #ifndef _KERNEL
155 139 #ifdef __STDC__
156 140 extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
157 141 fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD);
158 142
159 143 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
160 144 extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
161 145 fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD,
162 146 const sigset_t *_RESTRICT_KYWD);
163 147 #endif
164 148
165 149 #else
166 150 extern int select();
167 151 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
168 152 extern int pselect();
169 153 #endif
170 154 #endif /* __STDC__ */
171 155 #endif /* _KERNEL */
172 156
173 157 #ifdef __cplusplus
174 158 }
175 159 #endif
176 160
177 161 #endif /* _SYS_SELECT_H */
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX