summaryrefslogtreecommitdiff
path: root/sysdeps/unix/clock_nanosleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/clock_nanosleep.c')
-rw-r--r--sysdeps/unix/clock_nanosleep.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sysdeps/unix/clock_nanosleep.c b/sysdeps/unix/clock_nanosleep.c
index ec468ad8c9..34bbc2dae6 100644
--- a/sysdeps/unix/clock_nanosleep.c
+++ b/sysdeps/unix/clock_nanosleep.c
@@ -21,7 +21,7 @@
#include <errno.h>
#include <time.h>
#include <hp-timing.h>
-
+#include <sysdep-cancel.h>
#if HP_TIMING_AVAIL
# define CPUCLOCK_P(clock) \
@@ -94,5 +94,15 @@ clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
/* Not supported. */
return ENOTSUP;
- return __builtin_expect (nanosleep (req, rem), 0) ? errno : 0;
+ if (SINGLE_THREAD_P)
+ return __builtin_expect (nanosleep (req, rem), 0) ? errno : 0;
+
+ /* More than one thread running, enable cancellation. */
+ int oldstate = LIBC_CANCEL_ASYNC ();
+
+ int result = __builtin_expect (nanosleep (req, rem), 0) ? errno : 0;
+
+ LIBC_CANCEL_RESET (oldstate);
+
+ return result;
}