Skip to content

Commit 25da1d4

Browse files
committed
ug_pthread_cond_reltimedwait: glibc < 2.30 compat
In previous commit pthread_cond_clockwait() was used instead of pthread_cond_timedwait+pthread_condattr_setclock(CLOCK_MONOTONIC). BUT _clockwait() was introduced in glibc 2.30, AlmaLinux is using 2.28 therefore it doesn't compile. I don't want to reintroduce ug_pthread_cond_init() with clock in pthread_condattr_t so make a compat using CLOCK_REALITME instead of monotonic. It shouldn't be a big deal. CLOCK_REALTIME was used in UG normally all the time and it doesn't caused problems (CLOCK_MONOTONIC is usually just more correct).
1 parent f004e5f commit 25da1d4

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/utils/pthread.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ ug_pthread_mutex_init(pthread_mutex_t *mutex)
4646
pthread_mutexattr_destroy(&attr);
4747
}
4848

49+
// glibc<2.30 compat; assuming that not present on non-Linux systems now, either
50+
// (pthread_cond_clockwait() was introduced by POSIX v8 in 2024)
51+
#if !defined __APPLE__ && !defined _WIN32 && \
52+
(!defined __GLIBC__ || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 30))
53+
#define pthread_cond_clockwait(cv, lock, clock, tmout) \
54+
pthread_cond_timedwait(cv, lock, tmout)
55+
#undef CLOCK_MONOTONIC
56+
#define CLOCK_MONOTONIC CLOCK_REALTIME
57+
#endif
58+
4959
/**
5060
* wait for condition variable with timeout given by *timeout_ns
5161
*
@@ -61,7 +71,7 @@ ug_pthread_mutex_init(pthread_mutex_t *mutex)
6171
*/
6272
int
6373
ug_pthread_cond_reltimedwait(pthread_cond_t *cv, pthread_mutex_t *lock,
64-
time_ns_t *timeout_reltime_ns)
74+
time_ns_t *timeout_reltime_ns)
6575
{
6676
struct timespec tmout = { 0, 0 };
6777
struct timespec t0;
@@ -91,4 +101,3 @@ ug_pthread_cond_reltimedwait(pthread_cond_t *cv, pthread_mutex_t *lock,
91101
}
92102
return ret;
93103
}
94-

0 commit comments

Comments
 (0)