tsan: fix test for machines without pthread_cond_clockwait
Checks
Commit Message
Hey,
As per J. Wakeley's comments on
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100655
make the call to pthread_cond_clockwait conditional. This allows
compilation on machines
with older glibc versions.
Cheers,
Michael
2022-10-25 Michael de Lang <kingoipo@gmail.com>
* Fix testcase for pthread_cond_clockwait on machines with old glibc
@@ -4,6 +4,10 @@
#include <pthread.h>
+// Include this to get the libstdc++ _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
+// macro that indicates pthread_cond_clockwait is available.
+#include <type_traits>
+
pthread_cond_t cv;
pthread_mutex_t mtx;
@@ -23,7 +27,9 @@ int main() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
ts.tv_sec += 10;
+#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts);
+#endif
pthread_mutex_unlock(&mtx);
pthread_join(tid, NULL);