+ assert(Creator);
+ if (llvm_is_multithreaded()) {
+ MutexGuard Lock(getManagedStaticMutex());
+
+ if (!Ptr) {
+ void* tmp = Creator();
+
+ 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.
+ Next = StaticList;
+ StaticList = this;
+ }
+ } else {
+ assert(!Ptr && !DeleterFn && !Next &&
+ "Partially initialized ManagedStatic!?");
+ Ptr = Creator();
+ DeleterFn = Deleter;