diff options
Diffstat (limited to 'lib/pthread_mutex_timedlock.c')
-rw-r--r-- | lib/pthread_mutex_timedlock.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/pthread_mutex_timedlock.c b/lib/pthread_mutex_timedlock.c index 2394092e83..2e931bb1d8 100644 --- a/lib/pthread_mutex_timedlock.c +++ b/lib/pthread_mutex_timedlock.c @@ -24,6 +24,10 @@ #include <sys/time.h> #include <time.h> +#ifndef MIN +# define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + int pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime) { @@ -77,9 +81,11 @@ pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime) return ETIMEDOUT; /* Sleep 1 ms. */ - struct timespec duration = { .tv_nsec = 1000000 }; - if (duration.tv_nsec > remaining) - duration.tv_nsec = remaining; + struct timespec duration = + { + .tv_sec = 0, + .tv_nsec = MIN (1000000, remaining) + }; nanosleep (&duration, NULL); } } |