Permalink
Browse files

Fix live-sleeping problem on OS X due to heartbeat interrupting nanos…

…leep call
  • Loading branch information...
1 parent 7e3dc30 commit 83e20780e9b81e963af883e7f506026b8bc31ae9 @feeley feeley committed Feb 9, 2014
Showing with 25 additions and 16 deletions.
  1. +1 −1 include/stamp.h
  2. +24 −15 lib/os_io.c
View
@@ -3,4 +3,4 @@
*/
#define ___STAMP_YMD 20140209
-#define ___STAMP_HMS 180955
+#define ___STAMP_HMS 181406
View
@@ -1,6 +1,6 @@
/* File: "os_io.c" */
-/* Copyright (c) 1994-2013 by Marc Feeley, All Rights Reserved. */
+/* Copyright (c) 1994-2014 by Marc Feeley, All Rights Reserved. */
/*
* This module implements the operating system specific routines
@@ -984,6 +984,20 @@ ___time timeout;)
#ifdef USE_select
+ /*
+ * Heartbeat interrupts must be disabled in case they are based on the
+ * real-time timer. This is needed to bypass issues in two buggy
+ * operating systems:
+ *
+ * - On MacOS X, the virtual-time timer does not fire at the correct
+ * rate (apparently this happens only on machines with more than
+ * one core).
+ *
+ * - On CYGWIN, the select system call can be interrupted by the
+ * timer and in some cases the error "No child processes" will
+ * be returned by select.
+ */
+
{
struct timeval delta_tv_struct;
struct timeval *delta_tv = &delta_tv_struct;
@@ -1031,27 +1045,18 @@ ___time timeout;)
struct timespec delta_ts_struct;
delta_ts_struct.tv_sec = delta_tv->tv_sec;
delta_ts_struct.tv_nsec = delta_tv->tv_usec * 1000;
+
+ ___disable_heartbeat_interrupts ();
+
result = nanosleep (&delta_ts_struct, NULL);
+ ___enable_heartbeat_interrupts ();
+
goto select_done;
}
#endif
}
- /*
- * Heartbeat interrupts must be disabled in case they are based on the
- * real-time timer. This is needed to bypass issues in two buggy
- * operating systems:
- *
- * - On MacOS X, the virtual-time timer does not fire at the correct
- * rate (apparently this happens only on machines with more than
- * one core).
- *
- * - On CYGWIN, the select system call can be interrupted by the
- * timer and in some cases the error "No child processes" will
- * be returned by select.
- */
-
___disable_heartbeat_interrupts ();
result =
@@ -1105,8 +1110,12 @@ ___time timeout;)
delta_ts_struct.tv_sec = delta_tv->tv_sec;
delta_ts_struct.tv_nsec = delta_tv->tv_usec * 1000;
+ ___disable_heartbeat_interrupts ();
+
result = nanosleep (&delta_ts_struct, NULL);
+ ___enable_heartbeat_interrupts ();
+
goto poll_done;
}
#endif

0 comments on commit 83e2078

Please sign in to comment.