From 6339f4b081ea645bbba52d2c8a2dd38713b9ef2a Mon Sep 17 00:00:00 2001 From: rrt Date: Tue, 27 Feb 2001 12:43:45 +0000 Subject: [PATCH] [project @ 2001-02-27 12:43:45 by rrt] mingwin "fixes": getourtimeofday now returns the right units, and awaitEvent fudged to use WinSock select(), so that although it doesn't work for file handles, at least it doesn't cause nasty crashes; instead it just blocks. --- ghc/rts/Itimer.c | 4 ++-- ghc/rts/Select.c | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ghc/rts/Itimer.c b/ghc/rts/Itimer.c index 43421b4..812557c 100644 --- a/ghc/rts/Itimer.c +++ b/ghc/rts/Itimer.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Itimer.c,v 1.20 2001/02/13 11:10:28 rrt Exp $ + * $Id: Itimer.c,v 1.21 2001/02/27 12:43:45 rrt Exp $ * * (c) The GHC Team, 1995-1999 * @@ -243,6 +243,6 @@ getourtimeofday(void) unsigned int getourtimeofday(void) { - return (unsigned int)GetTickCount() * 1000; + return ((unsigned int)GetTickCount() * TICK_FREQUENCY) / 1000; } #endif diff --git a/ghc/rts/Select.c b/ghc/rts/Select.c index 486ccba..644bb41 100644 --- a/ghc/rts/Select.c +++ b/ghc/rts/Select.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Select.c,v 1.14 2000/08/25 13:12:07 simonmar Exp $ + * $Id: Select.c,v 1.15 2001/02/27 12:43:45 rrt Exp $ * * (c) The GHC Team 1995-1999 * @@ -17,7 +17,7 @@ #include "Itimer.h" #include "Signals.h" -# if defined(HAVE_SYS_TYPES_H) +# ifdef HAVE_SYS_TYPES_H # include # endif @@ -25,6 +25,10 @@ # include # endif +# ifdef mingw32_TARGET_OS +# include +# endif + /* last timestamp */ nat timestamp = 0; @@ -70,24 +74,23 @@ wakeUpSleepingThreads(nat ticks) * 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; @@ -125,6 +128,7 @@ awaitEvent(rtsBool wait) min = 0x7ffffff; } +#ifndef mingw32_TARGET_OS /* * Collect all of the fd's that we're interested in */ @@ -176,14 +180,20 @@ awaitEvent(rtsBool wait) 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 @@ -195,7 +205,8 @@ awaitEvent(rtsBool wait) ACQUIRE_LOCK(&sched_mutex); return; /* still hold the lock */ } - +#endif + /* we were interrupted, return to the scheduler immediately. */ if (interrupted) { @@ -260,5 +271,4 @@ awaitEvent(rtsBool wait) } } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE); -#endif } -- 1.7.10.4