1 // RUN: %clang_tsan -O1 %s -o %t -lrt && %run %t 2>&1 | FileCheck %s
2 // Test that pthread_cond is properly intercepted,
3 // previously there were issues with versioned symbols.
13 typedef unsigned long long u64
;
16 pthread_condattr_t at
;
17 struct timespec ts0
, ts1
, ts2
;
21 pthread_mutex_init(&m
, 0);
22 pthread_condattr_init(&at
);
23 pthread_condattr_setclock(&at
, CLOCK_MONOTONIC
);
24 pthread_cond_init(&c
, &at
);
26 clock_gettime(CLOCK_MONOTONIC
, &ts0
);
30 pthread_mutex_lock(&m
);
32 res
= pthread_cond_timedwait(&c
, &m
, &ts1
);
34 pthread_mutex_unlock(&m
);
36 clock_gettime(CLOCK_MONOTONIC
, &ts2
);
37 sleep
= (u64
)ts2
.tv_sec
* 1000000000 + ts2
.tv_nsec
-
38 ((u64
)ts0
.tv_sec
* 1000000000 + ts0
.tv_nsec
);
40 exit(printf("bad return value %d, want %d\n", res
, ETIMEDOUT
));
41 if (sleep
< 1000000000)
42 exit(printf("bad sleep duration %lluns, want %dns\n", sleep
, 1000000000));
43 fprintf(stderr
, "OK\n");