changeset 4086:ddc722b38e87

[project @ 2002-10-03 19:08:45 by jwe]
author jwe
date Thu, 03 Oct 2002 19:08:45 +0000
parents ee4790097033
children a54f61b5d491
files liboctave/ChangeLog src/ChangeLog src/cutils.c src/sysdep.cc src/toplev.cc src/utils.cc src/utils.h
diffstat 7 files changed, 91 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Thu Oct 03 16:04:56 2002 +0000
+++ b/liboctave/ChangeLog	Thu Oct 03 19:08:45 2002 +0000
@@ -1,6 +1,7 @@
 2002-10-03  Paul Kienzle <pkienzle@users.sf.net>
 
-	* oct-time.cc: Win32 version of octave_time::stamp().
+	* oct-time.cc (octave_time::stamp): Better resolution for Windows
+	systems.
 
 2002-10-02  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
--- a/src/ChangeLog	Thu Oct 03 16:04:56 2002 +0000
+++ b/src/ChangeLog	Thu Oct 03 19:08:45 2002 +0000
@@ -1,3 +1,21 @@
+2002-10-03  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* cutils.c (octave_usleep): Call octave_sleep, not sleep.
+
+	* utils.cc (octave_sleep (double)): New function.
+	* utils.h: Provide decl.
+	* sysdep.cc (Fpause, Fsleep): Use it.
+
+	* cutils.c (do_octave_usleep): Merge with octave_usleep.
+	(octave_usleep): Make it work for Windows systems.  From Paul
+	Kienzle <pkienzle@users.sf.net>.
+
+2002-10-03  Paul Kienzle <pkienzle@users.sf.net>
+
+	* cutils.c (octave_usleep): Make it work for Windows systems.
+
+	* toplev.cc (Fsystem): Error message if fork is not available.
+
 2002-10-02  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* cutils.c (octave_sleep): Handle Windows, which may not have
--- a/src/cutils.c	Thu Oct 03 16:04:56 2002 +0000
+++ b/src/cutils.c	Thu Oct 03 19:08:45 2002 +0000
@@ -24,6 +24,17 @@
 #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
+
 #ifdef HAVE_UNISTD_H
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
@@ -39,37 +50,7 @@
 #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)
-{
-#if defined (HAVE_USLEEP)
-
-  usleep (useconds);
-
-#elif defined (HAVE_SELECT)
-
-  struct timeval delay;
-
-  delay.tv_sec = 0;
-  delay.tv_usec = useconds;
-
-  select (0, 0, 0, 0, &delay);
-
-#elif defined (HAVE_POLL)
-
-  struct pollfd pfd;
-  int delay = useconds / 1000;
-
-  if (delay > 0)
-    poll (&fd, 0, delay);
-
 #endif
-}
 
 void
 octave_sleep (unsigned int seconds)
@@ -88,9 +69,42 @@
   unsigned int usec = useconds % 1000000;
 
   if (sec > 0)
-    sleep (sec);
+    octave_sleep (sec);
+
+#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
+
+  /* Round to the nearest millisecond, with a minimum of 1 millisecond
+     if usleep was called with a a non-zero value.  */
+
+  if (usec > 500)
+    Sleep ((usec+500)/1000);
+  else if (usec > 0)
+    Sleep (1);
+  else
+    Sleep (0);
+
+#elif defined (HAVE_USLEEP)
+
+  usleep (usec);
 
-  do_octave_usleep (usec);
+#elif defined (HAVE_SELECT)
+
+  struct timeval delay;
+
+  delay.tv_sec = 0;
+  delay.tv_usec = usec;
+
+  select (0, 0, 0, 0, &delay);
+
+#elif defined (HAVE_POLL)
+
+  struct pollfd pfd;
+  int delay = usec / 1000;
+
+  if (delay > 0)
+    poll (&fd, 0, delay);
+
+#endif
 }
 
 int
--- a/src/sysdep.cc	Thu Oct 03 16:04:56 2002 +0000
+++ b/src/sysdep.cc	Thu Oct 03 19:08:45 2002 +0000
@@ -497,11 +497,7 @@
 	      octave_kbhit ();
 	    }
 	  else
-	    {
-	      int delay = NINT (dval);
-	      if (delay > 0)
-		octave_sleep (delay);
-	    }
+	    octave_sleep (dval);
 	}
     }
   else
@@ -530,11 +526,7 @@
 	  if (xisnan (dval))
 	    warning ("sleep: NaN is an invalid delay");
 	  else
-	    {
-	      int delay = NINT (dval);
-	      if (delay > 0)
-		octave_sleep (delay);
-	    }
+	    octave_sleep (dval);
 	}
     }
   else
--- a/src/toplev.cc	Thu Oct 03 16:04:56 2002 +0000
+++ b/src/toplev.cc	Thu Oct 03 19:08:45 2002 +0000
@@ -497,6 +497,7 @@
 
 	  if (type == async)
 	    {
+#ifdef HAVE_FORK
 	      pid_t pid = fork ();
 
 	      if (pid < 0) 
@@ -512,6 +513,9 @@
 		}
 	      else
 		retval(0) = static_cast<double> (pid);
+#else
+ 	      error ("asynchronous system calls are not supported");
+#endif
 	    }
 	  else if (return_output)
 	    retval = run_command_and_return_output (cmd_str);
--- a/src/utils.cc	Thu Oct 03 16:04:56 2002 +0000
+++ b/src/utils.cc	Thu Oct 03 19:08:45 2002 +0000
@@ -749,6 +749,22 @@
   return retval;
 }
 
+void
+octave_sleep (double seconds)
+{
+  if (seconds > 0)
+    {
+      double t;
+
+      unsigned int usec = modf (seconds, &t) * 1000000;
+
+      unsigned int sec = (t > UINT_MAX) ? UINT_MAX : (unsigned int) t;
+
+      octave_sleep (sec);
+      octave_usleep (usec);
+    }
+}
+
 static int
 treat_neg_dim_as_zero (void)
 {
--- a/src/utils.h	Thu Oct 03 16:04:56 2002 +0000
+++ b/src/utils.h	Thu Oct 03 19:08:45 2002 +0000
@@ -73,10 +73,12 @@
 extern int
 octave_vformat (std::ostream& os, const char *fmt, va_list args);
 
-extern "C" void octave_usleep (unsigned int useconds);
+extern void octave_sleep (double seconds);
 
 extern "C" void octave_sleep (unsigned int seconds);
 
+extern "C" void octave_usleep (unsigned int useconds);
+
 extern "C" int octave_strcasecmp (const char *s1, const char *s2);
 
 extern "C" int octave_strncasecmp (const char *s1, const char *s2, size_t n);