diff mbox series

tsan: fix test for machines without pthread_cond_clockwait

Message ID CAJbH2PyhVRnAgtEPnHc+3-XpdXVVbmV70V2rNmxFh5YRDmb1tw@mail.gmail.com
State New
Headers show
Series tsan: fix test for machines without pthread_cond_clockwait | expand

Commit Message

Michael de Lang Oct. 25, 2022, 5:39 p.m. UTC
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
diff mbox series

Patch

--- a/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C
+++ b/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C
@@ -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);