[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sleep on Windows systems
From: |
Paul Kienzle |
Subject: |
Re: Sleep on Windows systems |
Date: |
Thu, 3 Oct 2002 08:01:26 -0500 |
On Wed, Oct 02, 2002 at 10:19:39PM -0500, John W. Eaton wrote:
> On 2-Oct-2002, Paul Kienzle <address@hidden> wrote:
>
> | We don't need to be that sophisticated since we are not event
> | driven. Seems to me their code is wrong, too. As well as
> | sleeping for the entire time, are they not also "sleeping"
> | for the time required to process the event queue?
>
> Yes, I suppose they assume it is only a small fraction of the total
> time, but that may not always be valid.
>
> Anyway, my point was just that they don't test for Sleep, they just
> assume it is present on Windows systems. So that seems easier and not
> as confusing as trying to make autoconf test for a mixed-case name.
That was my conclusion as well. Rather than testing against
defined (__WIN32__) && ! defined(_POSIX_VERSION)
every time, should we define USE_WIN32API in config.h?
>
> How about the following change?
>
Here is an additional patch to define usleep. It seems to work correctly
in that usleep(1000000) is about the same as sleep(1) and usleep(500000)
is half that.
Aside: pause(0.5) doesn't pause. This is an incompatibility.
Aside: Why do we need both sleep and usleep?
Paul Kienzle <address@hidden>
* cutils.c: Win32 version of octave_usleep.
Index: cutils.c
===================================================================
RCS file: /cvs/octave/src/cutils.c,v
retrieving revision 1.9
diff -c -p -r1.9 cutils.c
*** cutils.c 2002/10/03 03:23:15 1.9
--- cutils.c 2002/10/03 12:44:32
*************** Software Foundation, 59 Temple Place - S
*** 24,29 ****
--- 24,40 ----
#include <config.h>
#endif
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
+
+ #include <windows.h>
+
+ #else /* ! defined (__WIN32__) || defined (_POSIX_VERSION) */
+
#ifdef HAVE_UNISTD_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
*************** Software Foundation, 59 Temple Place - S
*** 39,49 ****
#include <sys/poll.h>
#endif
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
static void
do_octave_usleep (unsigned int useconds)
{
--- 50,55 ----
*************** do_octave_usleep (unsigned int useconds)
*** 71,76 ****
--- 77,84 ----
#endif
}
+ #endif /* ! defined (__WIN32__) || defined (_POSIX_VERSION) */
+
void
octave_sleep (unsigned int seconds)
{
*************** octave_sleep (unsigned int seconds)
*** 84,89 ****
--- 92,108 ----
void
octave_usleep (unsigned int useconds)
{
+ #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
+ /* On Windows, round to the nearest millisecond, with a
+ * minimum of 1 millisecond if usleep was called with a
+ * a non-zero value. */
+ if (useconds > 500)
+ Sleep ((useconds+500)/1000);
+ else if (useconds > 0)
+ Sleep (1);
+ else
+ Sleep (0);
+ #else /* ! defined (__WIN32__) || defined (_POSIX_VERSION) */
unsigned int sec = useconds / 1000000;
unsigned int usec = useconds % 1000000;
*************** octave_usleep (unsigned int useconds)
*** 91,96 ****
--- 110,116 ----
sleep (sec);
do_octave_usleep (usec);
+ #endif /* ! defined (__WIN32__) || defined (_POSIX_VERSION) */
}
int