2 % (c) The AQUA Project, Glasgow University, 1995
4 %************************************************************************
6 \section[Select.lc]{Select Available File Descriptors}
8 %************************************************************************
14 /* #define STK_CHK_DEBUG */
17 #define NON_POSIX_SOURCE
18 /* Should there be a POSIX alternative based on poll()? */
21 # if defined(HAVE_SYS_TYPES_H)
22 # include <sys/types.h>
25 # ifdef HAVE_SYS_TIME_H
26 # include <sys/time.h>
40 min = delta == 0 ? 0x7fffffff : 0;
43 * Collect all of the fd's that we're interested in, and capture
44 * the minimum waiting time for the delayed threads.
47 for(tso = WaitingThreadsHd; tso != Nil_closure; tso = TSO_LINK(tso)) {
48 us = (I_) TSO_EVENT(tso);
50 /* Looking at a delay event */
54 /* Looking at a wait event */
59 /* Check for any interesting events */
61 tv.tv_sec = min / 1000000;
62 tv.tv_usec = min % 1000000;
64 while (select(FD_SETSIZE, &rfd, NULL, NULL, &tv) < 0) {
67 fprintf(stderr, "AwaitEvent: select failed\n");
76 for(tso = WaitingThreadsHd; tso != Nil_closure; tso = next) {
78 us = (I_) TSO_EVENT(tso);
80 /* Looking at a delay event */
84 TSO_EVENT(tso) = (W_) us;
86 /* Looking at a wait event */
87 ready = FD_ISSET((-us), &rfd);
92 if (ThreadQueueTl == Nil_closure)
95 TSO_LINK(ThreadQueueTl) = tso;
97 TSO_LINK(tso) = Nil_closure;
99 if (RunnableThreadsTl == Nil_closure)
100 RunnableThreadsHd = tso;
102 TSO_LINK(RunnableThreadsTl) = tso;
103 RunnableThreadsTl = tso;
104 TSO_LINK(tso) = Nil_closure;
108 WaitingThreadsHd = tso;
110 TSO_LINK(prev) = tso;
115 WaitingThreadsHd = WaitingThreadsTl = Nil_closure;
117 TSO_LINK(prev) = Nil_closure;
118 WaitingThreadsTl = prev;
122 #endif /* CONCURRENT */