diff options
Diffstat (limited to 'lib/pthread-rwlock.c')
-rw-r--r-- | lib/pthread-rwlock.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/pthread-rwlock.c b/lib/pthread-rwlock.c index 5087661b0b..25ff5eeb37 100644 --- a/lib/pthread-rwlock.c +++ b/lib/pthread-rwlock.c @@ -30,6 +30,10 @@ # include <time.h> #endif +#ifndef MIN +# define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + #if ((defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS) || !HAVE_PTHREAD_H int @@ -409,9 +413,11 @@ pthread_rwlock_timedrdlock (pthread_rwlock_t *lock, 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); } } @@ -464,9 +470,11 @@ pthread_rwlock_timedwrlock (pthread_rwlock_t *lock, 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); } } |