Reduce code duplication resulting from the ConstantVector/ConstantDataVector split.
[oota-llvm.git] / lib / Support / ManagedStatic.cpp
index 4e655a0f9eec461b9a41c8f4c72104859275d6ac..098cccb68df51880522f63ff520fccf57e4ba0b9 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Config/config.h"
-#include "llvm/System/Atomic.h"
+#include "llvm/Support/Atomic.h"
 #include <cassert>
 using namespace llvm;
 
@@ -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();
 }
-