llvm.org GIT mirror llvm / 06da926
Remove all of the legacy home-grown atomic operations LLVM provided except for CompareAndSwap. That is the only one still being used anywhere now that statistics have been moved onto std::atomic. Also, add a warning to the header that we shouldn't introduce more uses of these old style atomics and instead should be using C++11's std::atomic facilities. Really hoping that we can hammer out the last couple of users here and replace them with something more localized and/or principled, but figured this was a pretty good start. =] Note that this patch will need to be reverted if r271504 needs to be reverted as that removes the last user of these. However, the biggest risk for that patch was MSVC 2013 and at least one bot has already passed where it would have failed there. I've tested MSVC 2015 using their web interfaces and other platforms seem fine, so I'm optimistic. Differential Revision: http://reviews.llvm.org/D20901 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271540 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 3 years ago
2 changed file(s) with 4 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
77 //===----------------------------------------------------------------------===//
88 //
99 // This file declares the llvm::sys atomic operations.
10 //
11 // DO NOT USE IN NEW CODE!
12 //
13 // New code should always rely on the std::atomic facilities in C++11.
1014 //
1115 //===----------------------------------------------------------------------===//
1216
2731 cas_flag CompareAndSwap(volatile cas_flag* ptr,
2832 cas_flag new_value,
2933 cas_flag old_value);
30 cas_flag AtomicIncrement(volatile cas_flag* ptr);
31 cas_flag AtomicDecrement(volatile cas_flag* ptr);
32 cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
33 cas_flag AtomicMul(volatile cas_flag* ptr, cas_flag val);
34 cas_flag AtomicDiv(volatile cas_flag* ptr, cas_flag val);
3534 }
3635 }
3736
5555 # error No compare-and-swap implementation for your platform!
5656 #endif
5757 }
58
59 sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) {
60 #if LLVM_HAS_ATOMICS == 0
61 ++(*ptr);
62 return *ptr;
63 #elif defined(GNU_ATOMICS)
64 return __sync_add_and_fetch(ptr, 1);
65 #elif defined(_MSC_VER)
66 return InterlockedIncrement(ptr);
67 #else
68 # error No atomic increment implementation for your platform!
69 #endif
70 }
71
72 sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
73 #if LLVM_HAS_ATOMICS == 0
74 --(*ptr);
75 return *ptr;
76 #elif defined(GNU_ATOMICS)
77 return __sync_sub_and_fetch(ptr, 1);
78 #elif defined(_MSC_VER)
79 return InterlockedDecrement(ptr);
80 #else
81 # error No atomic decrement implementation for your platform!
82 #endif
83 }
84
85 sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
86 #if LLVM_HAS_ATOMICS == 0
87 *ptr += val;
88 return *ptr;
89 #elif defined(GNU_ATOMICS)
90 return __sync_add_and_fetch(ptr, val);
91 #elif defined(_MSC_VER)
92 return InterlockedExchangeAdd(ptr, val) + val;
93 #else
94 # error No atomic add implementation for your platform!
95 #endif
96 }
97
98 sys::cas_flag sys::AtomicMul(volatile sys::cas_flag* ptr, sys::cas_flag val) {
99 sys::cas_flag original, result;
100 do {
101 original = *ptr;
102 result = original * val;
103 } while (sys::CompareAndSwap(ptr, result, original) != original);
104
105 return result;
106 }
107
108 sys::cas_flag sys::AtomicDiv(volatile sys::cas_flag* ptr, sys::cas_flag val) {
109 sys::cas_flag original, result;
110 do {
111 original = *ptr;
112 result = original / val;
113 } while (sys::CompareAndSwap(ptr, result, original) != original);
114
115 return result;
116 }