diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-11-14 20:50:16 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-11-14 20:50:16 +0000 |
commit | 4d0a9ff36574da0c042e9bd3ae816301b392ac41 (patch) | |
tree | c5e1c2d7d88829785d73dbe6173da013f4554af3 /lib/Support/ManagedStatic.cpp | |
parent | 76c8f08567c1e06e8555a910e919d4896f18f5e2 (diff) |
Add support for tsan annotations (thread sanitizer, a valgrind-based tool).
These annotations are disabled entirely when either ENABLE_THREADS is off, or
building a release build. When enabled, they add calls to functions with no
statements to ManagedStatic's getters.
Use these annotations to inform tsan that the race used inside ManagedStatic
initialization is actually benign. Thanks to Kostya Serebryany for helping
write this patch!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144567 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ManagedStatic.cpp')
-rw-r--r-- | lib/Support/ManagedStatic.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Support/ManagedStatic.cpp b/lib/Support/ManagedStatic.cpp index c767c15e71..098cccb68d 100644 --- a/lib/Support/ManagedStatic.cpp +++ b/lib/Support/ManagedStatic.cpp @@ -27,8 +27,15 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(), if (Ptr == 0) { void* tmp = Creator ? Creator() : 0; + TsanHappensBefore(this); sys::MemoryFence(); + + // This write is racy against the first read in the ManagedStatic + // accessors. The race is benign because it does a second read after a + // memory fence, at which point it isn't possible to get a partial value. + TsanIgnoreWritesBegin(); Ptr = tmp; + TsanIgnoreWritesEnd(); DeleterFn = Deleter; // Add to list of managed statics. @@ -72,4 +79,3 @@ void llvm::llvm_shutdown() { if (llvm_is_multithreaded()) llvm_stop_multithreaded(); } - |