From cdc943532d8f81843e18995f317f1e906c55e370 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 15 May 2009 08:22:07 +0000 Subject: [PATCH] Factor out some common code, fix more typoes, and add a memory fence that might be needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71853 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ManagedStatic.h | 46 ++++++++++++------------------------ 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/include/llvm/Support/ManagedStatic.h b/include/llvm/Support/ManagedStatic.h index c1ff0fef93..a504be31d8 100644 --- a/include/llvm/Support/ManagedStatic.h +++ b/include/llvm/Support/ManagedStatic.h @@ -51,51 +51,35 @@ public: /// template class ManagedStatic : public ManagedStaticBase { -public: - - // Accessors. - C &operator*() { +private: + void checkInit() { sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0); if (OldFlag == 0) { LazyInit(); sys::MemoryFence(); InitFlag = 2; - } else if (OldFlag == 1) - while (OldFlag == 1) ; - + } else if (OldFlag == 1) { + while (InitFlag == 1) ; + sys::MemoryFence(); + } + } +public: + + // Accessors. + C &operator*() { + checkInit(); return *static_cast(Ptr); } C *operator->() { - sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0); - if (OldFlag == 0) { - LazyInit(); - sys::MemoryFence(); - InitFlag = 2; - } else if (OldFlag == 1) - while (OldFlag == 1) ; - + checkInit(); return static_cast(Ptr); } const C &operator*() const { - sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0); - if (OldFlag == 0) { - LazyInit(); - sys::MemoryFence(); - InitFlag = 2; - } else if (OldFlag == 1) - while (InitFlag == 1) ; - + checkInit(); return *static_cast(Ptr); } const C *operator->() const { - sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0); - if (OldFlag == 0) { - LazyInit(); - sys::MemoryFence(); - InitFlag = 2; - } else if (OldFlag == 1) - while (OldFlag == 1) ; - + checkInit(); return static_cast(Ptr); } -- 2.11.4.GIT