16 #ifndef ABSL_FLAGS_INTERNAL_SEQUENCE_LOCK_H_
17 #define ABSL_FLAGS_INTERNAL_SEQUENCE_LOCK_H_
26 #include "absl/base/optimization.h"
30 namespace flags_internal {
65 lock_.store(0, std::memory_order_release);
80 bool TryRead(
void*
dst,
const std::atomic<uint64_t>* src,
size_t size)
const {
83 int64_t seq_before =
lock_.load(std::memory_order_acquire);
88 std::atomic_thread_fence(std::memory_order_acquire);
89 int64_t seq_after =
lock_.load(std::memory_order_relaxed);
99 void Write(std::atomic<uint64_t>*
dst,
const void* src,
size_t size) {
104 int64_t orig_seq =
lock_.load(std::memory_order_relaxed);
105 assert((orig_seq & 1) == 0);
106 lock_.store(orig_seq + 1, std::memory_order_relaxed);
113 std::atomic_thread_fence(std::memory_order_release);
117 lock_.store(orig_seq + 2, std::memory_order_release);
137 lock_.store(val + 2, std::memory_order_relaxed);
145 char* dst_byte =
static_cast<char*
>(
dst);
147 uint64_t word = src->load(std::memory_order_relaxed);
149 dst_byte +=
sizeof(word);
151 size -=
sizeof(word);
154 uint64_t word = src->load(std::memory_order_relaxed);
163 const char* src_byte =
static_cast<const char*
>(src);
167 dst->store(word, std::memory_order_relaxed);
168 src_byte +=
sizeof(word);
170 size -=
sizeof(word);
175 dst->store(word, std::memory_order_relaxed);
187 #endif // ABSL_FLAGS_INTERNAL_SEQUENCE_LOCK_H_