summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/ManagedStatic.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-11-14 20:50:16 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-11-14 20:50:16 +0000
commitfe856110aa71fa0d10972793a9b0af3c171aec30 (patch)
treefeddada18458bb2533b334613d4d5e2ae02c40f4 /llvm/lib/Support/ManagedStatic.cpp
parentfb13d32b3f8dbb4c789ee422a55596c586a4285a (diff)
downloadbcm5719-llvm-fe856110aa71fa0d10972793a9b0af3c171aec30.tar.gz
bcm5719-llvm-fe856110aa71fa0d10972793a9b0af3c171aec30.zip
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! llvm-svn: 144567
Diffstat (limited to 'llvm/lib/Support/ManagedStatic.cpp')
-rw-r--r--llvm/lib/Support/ManagedStatic.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp
index c767c15e71c..098cccb68df 100644
--- a/llvm/lib/Support/ManagedStatic.cpp
+++ b/llvm/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();
}
-
OpenPOWER on IntegriCloud