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.
6 // OS X doesn't have pthread_condattr_setclock.
16 typedef unsigned long long u64
;
19 pthread_condattr_t at
;
20 struct timespec ts0
, ts1
, ts2
;
24 pthread_mutex_init(&m
, 0);
25 pthread_condattr_init(&at
);
26 pthread_condattr_setclock(&at
, CLOCK_MONOTONIC
);
27 pthread_cond_init(&c
, &at
);
29 clock_gettime(CLOCK_MONOTONIC
, &ts0
);
33 pthread_mutex_lock(&m
);
35 res
= pthread_cond_timedwait(&c
, &m
, &ts1
);
37 pthread_mutex_unlock(&m
);
39 clock_gettime(CLOCK_MONOTONIC
, &ts2
);
40 sleep
= (u64
)ts2
.tv_sec
* 1000000000 + ts2
.tv_nsec
-
41 ((u64
)ts0
.tv_sec
* 1000000000 + ts0
.tv_nsec
);
43 exit(printf("bad return value %d, want %d\n", res
, ETIMEDOUT
));
44 if (sleep
< 1000000000)
45 exit(printf("bad sleep duration %lluns, want %dns\n", sleep
, 1000000000));
46 fprintf(stderr
, "OK\n");