2023-05-15 Bruno Haible <bruno@clisp.org>
+ 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.
+
select: Fix compilation error (regression from yesterday).
* lib/select.c (rpl_select): Revert last change.
# error "Only 1-second nominal clock resolution found. Is that intended?" \
"If so, compile with the -DOK_TO_USE_1S_CLOCK option."
# endif
- *tv = (struct timeval) { .tv_sec = time (NULL) };
+ *tv = (struct timeval) { .tv_sec = time (NULL), .tv_usec = 0 };
return 0;
/* Memory allocation failed. There is not much we can do. Have to
busy-loop, waiting for the availability of memory. */
{
- struct timespec ts = { .tv_sec = 1 };
+ struct timespec ts =
+ {
+ .tv_sec = 1,
+ .tv_nsec = 0
+ };
thrd_sleep (&ts, NULL);
}
}
Wait endlessly. */
for (;;)
{
- struct timespec duration = { .tv_sec = 86400 };
+ struct timespec duration =
+ {
+ .tv_sec = 86400,
+ .tv_nsec = 0
+ };
nanosleep (&duration, NULL);
}
}
# 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
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);
}
}
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);
}
}
#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)
{
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);
}
}
/* Memory allocation failed. There is not much we can do. Have to
busy-loop, waiting for the availability of memory. */
{
- struct timespec ts = { .tv_sec = 1 };
+ struct timespec ts =
+ {
+ .tv_sec = 1,
+ .tv_nsec = 0
+ };
thrd_sleep (&ts, NULL);
}
}