On mach, semaphore_timedwait returns KERN_ABORTED instead of setting the errno variable. The timeout argument is relative so it needs to be updated. We don't need to update the timeout argument on other platforms since it has an absolute value.
}
copy = ts;
- while ((res = WAIT_BLOCK (sem, &ts)) == -1 && errno == EINTR) {
+#ifdef USE_MACH_SEMA
+ gettimeofday (&t, NULL);
+ while ((res = WAIT_BLOCK (sem, &ts)) == KERN_ABORTED)
+#else
+ while ((res = WAIT_BLOCK (sem, &ts)) == -1 && errno == EINTR)
+#endif
+ {
+#ifdef USE_MACH_SEMA
struct timeval current;
+#endif
if (alertable)
return -1;
+ ts = copy;
#ifdef USE_MACH_SEMA
- memset (¤t, 0, sizeof (current));
-#else
gettimeofday (¤t, NULL);
-#endif
- ts = copy;
ts.tv_sec -= (current.tv_sec - t.tv_sec);
ts.tv_nsec -= (current.tv_usec - t.tv_usec) * 1000;
if (ts.tv_nsec < 0) {
ts.tv_sec = 0;
ts.tv_nsec = 0;
}
+#endif
}
/* OSX might return > 0 for error */