forked from OSchip/llvm-project
[tsan] Add pthread_cond_clockwait interceptor
Fixes https://github.com/google/sanitizers/issues/1259 Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D91684
This commit is contained in:
parent
8b97e17d16
commit
16eb853ffd
|
@ -1202,6 +1202,21 @@ INTERCEPTOR(int, pthread_cond_timedwait, void *c, void *m, void *abstime) {
|
|||
m);
|
||||
}
|
||||
|
||||
#if SANITIZER_LINUX
|
||||
INTERCEPTOR(int, pthread_cond_clockwait, void *c, void *m,
|
||||
__sanitizer_clockid_t clock, void *abstime) {
|
||||
void *cond = init_cond(c);
|
||||
SCOPED_TSAN_INTERCEPTOR(pthread_cond_clockwait, cond, m, clock, abstime);
|
||||
return cond_wait(
|
||||
thr, pc, &si,
|
||||
[=]() { return REAL(pthread_cond_clockwait)(cond, m, clock, abstime); },
|
||||
cond, m);
|
||||
}
|
||||
#define TSAN_MAYBE_PTHREAD_COND_CLOCKWAIT TSAN_INTERCEPT(pthread_cond_clockwait)
|
||||
#else
|
||||
#define TSAN_MAYBE_PTHREAD_COND_CLOCKWAIT
|
||||
#endif
|
||||
|
||||
#if SANITIZER_MAC
|
||||
INTERCEPTOR(int, pthread_cond_timedwait_relative_np, void *c, void *m,
|
||||
void *reltime) {
|
||||
|
@ -2716,6 +2731,8 @@ void InitializeInterceptors() {
|
|||
TSAN_INTERCEPT_VER(pthread_cond_timedwait, PTHREAD_ABI_BASE);
|
||||
TSAN_INTERCEPT_VER(pthread_cond_destroy, PTHREAD_ABI_BASE);
|
||||
|
||||
TSAN_MAYBE_PTHREAD_COND_CLOCKWAIT;
|
||||
|
||||
TSAN_INTERCEPT(pthread_mutex_init);
|
||||
TSAN_INTERCEPT(pthread_mutex_destroy);
|
||||
TSAN_INTERCEPT(pthread_mutex_trylock);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Regression test for https://github.com/google/sanitizers/issues/1259
|
||||
// RUN: %clang_tsan -O1 %s -o %t && %run %t
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <pthread.h>
|
||||
|
||||
pthread_cond_t cv;
|
||||
pthread_mutex_t mtx;
|
||||
|
||||
void *fn(void *vp) {
|
||||
pthread_mutex_lock(&mtx);
|
||||
pthread_cond_signal(&cv);
|
||||
pthread_mutex_unlock(&mtx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
pthread_mutex_lock(&mtx);
|
||||
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, fn, NULL);
|
||||
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
ts.tv_sec += 10;
|
||||
pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts);
|
||||
pthread_mutex_unlock(&mtx);
|
||||
|
||||
pthread_join(tid, NULL);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue