27 auto default_fetch_set = [](
auto&&... args) {
30 auto default_fetch_reset = [](
auto&&... args) {
34 template <
typename Integer,
typename FetchSet = decltype(default_fetch_set)>
35 void atomic_fetch_set_basic(FetchSet fetch_set = default_fetch_set) {
37 auto&& atomic = std::atomic<Integer>{0};
46 auto&& atomic = std::atomic<Integer>{0b1};
56 for (
auto i = 0;
i < 100000; ++
i) {
61 auto&& atomic = std::atomic<Integer>{0};
66 EXPECT_EQ(fetch_set(atomic, bit + 1),
false);
68 EXPECT_EQ(fetch_set(atomic, bit + 2),
false);
74 template <
typename Integer,
typename FetchReset = decltype(default_fetch_reset)>
75 void atomic_fetch_reset_basic(FetchReset fetch_reset = default_fetch_reset) {
77 auto&& atomic = std::atomic<Integer>{0};
87 auto&& atomic = std::atomic<Integer>{0};
97 template <
typename Integer>
100 Atomic(std::function<
void()> onFetchOr, std::function<
void()> onFetchAnd)
105 std::memory_order = std::memory_order_seq_cst) {
111 std::memory_order = std::memory_order_seq_cst) {
116 Integer load(std::memory_order = std::memory_order_seq_cst) {
125 template <
typename Integer,
typename FetchSet = decltype(default_fetch_set)>
126 void atomic_fetch_set_non_std_atomic(FetchSet fetch_set = default_fetch_set) {
129 auto atomic = Atomic<Integer>{[&] { ++sets; }, [&] { ++resets; }};
131 fetch_set(atomic, 0);
136 fetch_set(atomic, 2);
142 template <
typename Integer,
typename F = decltype(default_fetch_reset)>
143 void atomic_fetch_reset_non_std_atomic(F fetch_reset = default_fetch_reset) {
146 auto atomic = Atomic<Integer>{[&] { ++sets; }, [&] { ++resets; }};
147 atomic.integer_ = 0b111;
149 fetch_reset(atomic, 0);
154 fetch_reset(atomic, 2);
165 atomic_fetch_set_basic<std::uint16_t>();
166 atomic_fetch_set_basic<std::uint32_t>();
167 atomic_fetch_set_basic<std::uint64_t>();
168 atomic_fetch_set_basic<std::uint8_t>();
172 atomic_fetch_reset_basic<std::uint16_t>();
173 atomic_fetch_reset_basic<std::uint32_t>();
174 atomic_fetch_reset_basic<std::uint64_t>();
175 atomic_fetch_reset_basic<std::uint8_t>();
179 atomic_fetch_set_non_std_atomic<std::uint8_t>();
180 atomic_fetch_set_non_std_atomic<std::uint16_t>();
181 atomic_fetch_set_non_std_atomic<std::uint32_t>();
182 atomic_fetch_set_non_std_atomic<std::uint64_t>();
186 atomic_fetch_reset_non_std_atomic<std::uint8_t>();
187 atomic_fetch_reset_non_std_atomic<std::uint16_t>();
188 atomic_fetch_reset_non_std_atomic<std::uint32_t>();
189 atomic_fetch_reset_non_std_atomic<std::uint64_t>();
193 auto fetch_set = [](
auto&&... args) {
197 atomic_fetch_set_basic<std::uint16_t>(fetch_set);
198 atomic_fetch_set_basic<std::uint32_t>(fetch_set);
199 atomic_fetch_set_basic<std::uint64_t>(fetch_set);
200 atomic_fetch_set_basic<std::uint8_t>(fetch_set);
202 atomic_fetch_set_non_std_atomic<std::uint8_t>(fetch_set);
203 atomic_fetch_set_non_std_atomic<std::uint16_t>(fetch_set);
204 atomic_fetch_set_non_std_atomic<std::uint32_t>(fetch_set);
205 atomic_fetch_set_non_std_atomic<std::uint64_t>(fetch_set);
209 auto fetch_reset = [](
auto&&... args) {
211 args..., std::memory_order_seq_cst);
214 atomic_fetch_reset_basic<std::uint16_t>(fetch_reset);
215 atomic_fetch_reset_basic<std::uint32_t>(fetch_reset);
216 atomic_fetch_reset_basic<std::uint64_t>(fetch_reset);
217 atomic_fetch_reset_basic<std::uint8_t>(fetch_reset);
219 atomic_fetch_reset_non_std_atomic<std::uint8_t>(fetch_reset);
220 atomic_fetch_reset_non_std_atomic<std::uint16_t>(fetch_reset);
221 atomic_fetch_reset_non_std_atomic<std::uint32_t>(fetch_reset);
222 atomic_fetch_reset_non_std_atomic<std::uint64_t>(fetch_reset);
227 auto fetch_set = [](
auto&&... args) {
231 atomic_fetch_set_basic<std::uint16_t>(fetch_set);
232 atomic_fetch_set_basic<std::uint32_t>(fetch_set);
233 atomic_fetch_set_basic<std::uint64_t>(fetch_set);
234 atomic_fetch_set_basic<std::uint8_t>(fetch_set);
236 atomic_fetch_set_non_std_atomic<std::uint8_t>(fetch_set);
237 atomic_fetch_set_non_std_atomic<std::uint16_t>(fetch_set);
238 atomic_fetch_set_non_std_atomic<std::uint32_t>(fetch_set);
239 atomic_fetch_set_non_std_atomic<std::uint64_t>(fetch_set);
245 auto fetch_reset = [](
auto&&... args) {
249 atomic_fetch_reset_basic<std::uint16_t>(fetch_reset);
250 atomic_fetch_reset_basic<std::uint32_t>(fetch_reset);
251 atomic_fetch_reset_basic<std::uint64_t>(fetch_reset);
252 atomic_fetch_reset_basic<std::uint8_t>(fetch_reset);
254 atomic_fetch_reset_non_std_atomic<std::uint8_t>(fetch_reset);
255 atomic_fetch_reset_non_std_atomic<std::uint16_t>(fetch_reset);
256 atomic_fetch_reset_non_std_atomic<std::uint32_t>(fetch_reset);
257 atomic_fetch_reset_non_std_atomic<std::uint64_t>(fetch_reset);
bool atomic_fetch_set_default(Atomic &atomic, std::size_t bit, std::memory_order order)
bool atomic_fetch_reset_default(Atomic &atomic, std::size_t bit, std::memory_order order)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
bool atomic_fetch_reset_x86(Atomic &, std::size_t, std::memory_order) noexcept
bool atomic_fetch_set(Atomic &atomic, std::size_t bit, std::memory_order mo)
bool atomic_fetch_reset(Atomic &atomic, std::size_t bit, std::memory_order mo)
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
std::function< void()> onFetchAnd_
T exchange(T &obj, U &&new_value)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
constexpr bool kIsArchAmd64
std::function< void()> onFetchOr_
bool atomic_fetch_set_x86(Atomic &, std::size_t, std::memory_order) noexcept
auto makeUnpredictable(T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type