/* -----------------------------------------------------------------------------
- * $Id: Select.c,v 1.14 2000/08/25 13:12:07 simonmar Exp $
+ * $Id: Select.c,v 1.19 2001/11/13 13:38:02 simonmar Exp $
*
* (c) The GHC Team 1995-1999
*
* ---------------------------------------------------------------------------*/
/* we're outside the realms of POSIX here... */
-#define NON_POSIX_SOURCE
+/* #include "PosixSource.h" */
#include "Rts.h"
#include "Schedule.h"
#include "Itimer.h"
#include "Signals.h"
-# if defined(HAVE_SYS_TYPES_H)
+# ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
# include <sys/time.h>
# endif
+# ifdef mingw32_TARGET_OS
+# include <windows.h>
+# endif
+
/* last timestamp */
nat timestamp = 0;
-/* keep track of the number of ticks since we last called
- * gettimeofday(), to avoid having to call it every time we need
- * a timestamp.
- */
-nat ticks_since_timestamp = 0;
-
/* There's a clever trick here to avoid problems when the time wraps
* around. Since our maximum delay is smaller than 31 bits of ticks
* (it's actually 31 bits of microseconds), we can safely check
* otherwise we wait (see Schedule.c).
*
* SMP note: must be called with sched_mutex locked.
+ *
+ * Windows: select only works on sockets, so this doesn't really work,
+ * though it makes things better than before. MsgWaitForMultipleObjects
+ * should really be used, though it only seems to work for read handles,
+ * not write handles.
+ *
*/
void
awaitEvent(rtsBool wait)
{
-#ifdef mingw32_TARGET_OS
-/*
- * Win32 doesn't support select(). ToDo: use MsgWaitForMultipleObjects()
- * to achieve (similar) effect.
- *
- */
- return;
-#else
-
StgTSO *tso, *prev, *next;
rtsBool ready;
fd_set rfd,wfd;
+#ifndef mingw32_TARGET_OS
int numFound;
int maxfd = -1;
+#endif
rtsBool select_succeeded = rtsTrue;
struct timeval tv;
lnat min, ticks;
do {
ticks = timestamp = getourtimeofday();
- ticks_since_timestamp = 0;
if (wakeUpSleepingThreads(ticks)) {
return;
}
min = 0x7ffffff;
}
+#ifndef mingw32_TARGET_OS
/*
* Collect all of the fd's that we're interested in
*/
tv.tv_usec = min % 1000000;
while ((numFound = select(maxfd+1, &rfd, &wfd, NULL, &tv)) < 0) {
-
if (errno != EINTR) {
- /* fflush(stdout); */
+
+ printf("%d\n", errno);
+ fflush(stdout);
perror("select");
barf("select failed");
}
+#else /* on mingwin */
+ while (1) {
+ Sleep(0); /* don't busy wait */
+#endif /* mingw32_TARGET_OS */
ACQUIRE_LOCK(&sched_mutex);
-
+
+#ifndef mingw32_TARGET_OS
/* We got a signal; could be one of ours. If so, we need
* to start up the signal handler straight away, otherwise
* we could block for a long time before the signal is
*/
if (signals_pending()) {
RELEASE_LOCK(&sched_mutex); /* ToDo: kill */
- start_signal_handlers();
+ startSignalHandlers();
ACQUIRE_LOCK(&sched_mutex);
return; /* still hold the lock */
}
-
+#endif
+
/* we were interrupted, return to the scheduler immediately.
*/
if (interrupted) {
}
} while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE);
-#endif
}