diff options
author | Bruno Haible <bruno@clisp.org> | 2023-05-15 14:36:17 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-05-15 14:36:17 +0200 |
commit | 3a70af2168910c6ad0d59924d276f831638a52e0 (patch) | |
tree | 9268245b1a4ca43369c4a3583f36936b7c33a026 /lib/pthread_mutex_timedlock.c | |
parent | ebd843b31b8f61d3f9dd250b41c237bf5f3e01a6 (diff) | |
download | gnulib-3a70af2168910c6ad0d59924d276f831638a52e0.tar.gz |
gettimeofday, pthread-*, thread, thrd: Don't omit intended initializers.
* lib/gettimeofday.c (gettimeofday): List the initializers of both
tv_sec and tv_usec.
* lib/glthread/thread.c (gl_thread_self): List the initializers of both
tv_sec and tv_nsec.
* lib/pthread-cond.c (pthread_cond_wait): Likewise.
* lib/thrd.c (rpl_thrd_current): Likewise.
* lib/pthread-rwlock.c (MIN): New macro.
(pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock): List the
initializers of both tv_sec and tv_nsec. Don't modify the duration after
having initialized it.
* lib/pthread_mutex_timedlock.c (MIN): New macro.
(pthread_mutex_timedlock): List the initializers of both tv_sec and
tv_nsec. Don't modify the duration after having initialized it.
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); } } |