tsan: implement RWLOCK annotations

llvm-svn: 162019
This commit is contained in:
Dmitry Vyukov 2012-08-16 13:29:41 +00:00
parent f77c6ea7ea
commit 4723e6b1e5
5 changed files with 27 additions and 10 deletions

View File

@ -782,7 +782,7 @@ TSAN_INTERCEPTOR(int, pthread_mutex_init, void *m, void *a) {
recursive = (type == PTHREAD_MUTEX_RECURSIVE
|| type == PTHREAD_MUTEX_RECURSIVE_NP);
}
MutexCreate(thr, pc, (uptr)m, false, recursive);
MutexCreate(thr, pc, (uptr)m, false, recursive, false);
}
return res;
}
@ -834,7 +834,7 @@ TSAN_INTERCEPTOR(int, pthread_spin_init, void *m, int pshared) {
SCOPED_TSAN_INTERCEPTOR(pthread_spin_init, m, pshared);
int res = REAL(pthread_spin_init)(m, pshared);
if (res == 0) {
MutexCreate(thr, pc, (uptr)m, false, false);
MutexCreate(thr, pc, (uptr)m, false, false, false);
}
return res;
}
@ -877,7 +877,7 @@ TSAN_INTERCEPTOR(int, pthread_rwlock_init, void *m, void *a) {
SCOPED_TSAN_INTERCEPTOR(pthread_rwlock_init, m, a);
int res = REAL(pthread_rwlock_init)(m, a);
if (res == 0) {
MutexCreate(thr, pc, (uptr)m, true, false);
MutexCreate(thr, pc, (uptr)m, true, false, false);
}
return res;
}

View File

@ -52,11 +52,11 @@ class ScopedAnnotation {
if (!flags()->enable_annotations) \
return; \
ThreadState *thr = cur_thread(); \
const uptr pc = (uptr)__builtin_return_address(0); \
StatInc(thr, StatAnnotation); \
StatInc(thr, Stat##typ); \
ScopedAnnotation sa(thr, __FUNCTION__, f, l, \
(uptr)__builtin_return_address(0)); \
const uptr pc = (uptr)&__FUNCTION__; \
(void)pc; \
/**/
@ -185,20 +185,35 @@ void AnnotateCondVarWait(char *f, int l, uptr cv, uptr lock) {
SCOPED_ANNOTATION(AnnotateCondVarWait);
}
void AnnotateRWLockCreate(char *f, int l, uptr lock) {
void AnnotateRWLockCreate(char *f, int l, uptr m) {
SCOPED_ANNOTATION(AnnotateRWLockCreate);
MutexCreate(thr, pc, m, true, true, false);
}
void AnnotateRWLockDestroy(char *f, int l, uptr lock) {
void AnnotateRWLockCreateStatic(char *f, int l, uptr m) {
SCOPED_ANNOTATION(AnnotateRWLockCreateStatic);
MutexCreate(thr, pc, m, true, true, true);
}
void AnnotateRWLockDestroy(char *f, int l, uptr m) {
SCOPED_ANNOTATION(AnnotateRWLockDestroy);
MutexDestroy(thr, pc, m);
}
void AnnotateRWLockAcquired(char *f, int l, uptr lock, uptr is_w) {
void AnnotateRWLockAcquired(char *f, int l, uptr m, uptr is_w) {
SCOPED_ANNOTATION(AnnotateRWLockAcquired);
if (is_w)
MutexLock(thr, pc, m);
else
MutexReadLock(thr, pc, m);
}
void AnnotateRWLockReleased(char *f, int l, uptr lock, uptr is_w) {
void AnnotateRWLockReleased(char *f, int l, uptr m, uptr is_w) {
SCOPED_ANNOTATION(AnnotateRWLockReleased);
if (is_w)
MutexUnlock(thr, pc, m);
else
MutexReadUnlock(thr, pc, m);
}
void AnnotateTraceMemory(char *f, int l, uptr mem) {

View File

@ -468,7 +468,8 @@ void ThreadDetach(ThreadState *thr, uptr pc, int tid);
void ThreadFinalize(ThreadState *thr);
void ThreadFinalizerGoroutine(ThreadState *thr);
void MutexCreate(ThreadState *thr, uptr pc, uptr addr, bool rw, bool recursive);
void MutexCreate(ThreadState *thr, uptr pc, uptr addr,
bool rw, bool recursive, bool linker_init);
void MutexDestroy(ThreadState *thr, uptr pc, uptr addr);
void MutexLock(ThreadState *thr, uptr pc, uptr addr);
void MutexUnlock(ThreadState *thr, uptr pc, uptr addr);

View File

@ -19,7 +19,7 @@
namespace __tsan {
void MutexCreate(ThreadState *thr, uptr pc, uptr addr,
bool rw, bool recursive) {
bool rw, bool recursive, bool linker_init) {
Context *ctx = CTX();
CHECK_GT(thr->in_rtl, 0);
DPrintf("#%d: MutexCreate %zx\n", thr->tid, addr);

View File

@ -209,6 +209,7 @@ enum StatType {
StatAnnotateMutexIsNotPHB,
StatAnnotateCondVarWait,
StatAnnotateRWLockCreate,
StatAnnotateRWLockCreateStatic,
StatAnnotateRWLockDestroy,
StatAnnotateRWLockAcquired,
StatAnnotateRWLockReleased,