[C++11] Replace LLVM atomics with std::atomic.

With C++11 we finally have a standardized way to specify atomic operations. Use
them to replace the existing custom implemention. Sadly the translation is not
entirely trivial as std::atomic allows more fine-grained control over the
atomicity. I tried to preserve the old semantics as well as possible.

Differential Revision: http://llvm-reviews.chandlerc.com/D2915

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202730 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2014-03-03 17:53:30 +00:00
parent 59a4517759
commit 4721e55a0c
9 changed files with 49 additions and 41 deletions

View File

@ -24,8 +24,8 @@
#include "Pass.h"
#include "llvm/InitializePasses.h"
#include "llvm/PassRegistry.h"
#include "llvm/Support/Atomic.h"
#include "llvm/Support/Valgrind.h"
#include <atomic>
#include <vector>
namespace llvm {
@ -147,21 +147,21 @@ private:
};
#define CALL_ONCE_INITIALIZATION(function) \
static volatile sys::cas_flag initialized = 0; \
sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
if (old_val == 0) { \
static std::atomic<int> initialized; \
int old_val = 0; \
if (initialized.compare_exchange_strong(old_val, 1)) { \
function(Registry); \
sys::MemoryFence(); \
std::atomic_thread_fence(std::memory_order_seq_cst); \
TsanIgnoreWritesBegin(); \
TsanHappensBefore(&initialized); \
initialized = 2; \
TsanIgnoreWritesEnd(); \
} else { \
sys::cas_flag tmp = initialized; \
sys::MemoryFence(); \
int tmp = initialized.load(); \
std::atomic_thread_fence(std::memory_order_seq_cst); \
while (tmp != 2) { \
tmp = initialized; \
sys::MemoryFence(); \
tmp = initialized.load(); \
std::atomic_thread_fence(std::memory_order_seq_cst); \
} \
} \
TsanHappensAfter(&initialized);