Use acquire/release instead of seq_cst
We don't have any code patterns which will ever notice the difference,
so just use acquire/release everywhere to minimize the number of
hardware memory barriers the compiler needs to emit.
Change-Id: I403535debbe72a23201d6e60e546d68e1a0cde4a
diff --git a/aos/ipc_lib/index.h b/aos/ipc_lib/index.h
index b1afdc8..7d979ea 100644
--- a/aos/ipc_lib/index.h
+++ b/aos/ipc_lib/index.h
@@ -138,8 +138,12 @@
}
// Full bidirectional barriers here.
- QueueIndex Load(uint32_t count) { return QueueIndex(index_.load(), count); }
- inline void Store(QueueIndex value) { index_.store(value.index_); }
+ QueueIndex Load(uint32_t count) {
+ return QueueIndex(index_.load(::std::memory_order_acquire), count);
+ }
+ inline void Store(QueueIndex value) {
+ index_.store(value.index_, ::std::memory_order_release);
+ }
// Invalidates the element unconditionally.
inline void Invalidate() { Store(QueueIndex::Invalid()); }
@@ -147,7 +151,8 @@
// Swaps expected for index atomically. Returns true on success, false
// otherwise.
inline bool CompareAndExchangeStrong(QueueIndex expected, QueueIndex index) {
- return index_.compare_exchange_strong(expected.index_, index.index_);
+ return index_.compare_exchange_strong(expected.index_, index.index_,
+ ::std::memory_order_acq_rel);
}
private:
@@ -221,16 +226,18 @@
// Invalidates the index atomically, but without any ordering constraints.
void RelaxedInvalidate() { RelaxedStore(Index::Invalid()); }
- // Full bidirectional barriers here.
+ // Full barriers here.
void Invalidate() { Store(Index::Invalid()); }
- void Store(Index index) { index_.store(index.index_); }
- Index Load() { return Index(index_.load()); }
-
+ void Store(Index index) {
+ index_.store(index.index_, ::std::memory_order_release);
+ }
+ Index Load() { return Index(index_.load(::std::memory_order_acquire)); }
// Swaps expected for index atomically. Returns true on success, false
// otherwise.
inline bool CompareAndExchangeStrong(Index expected, Index index) {
- return index_.compare_exchange_strong(expected.index_, index.index_);
+ return index_.compare_exchange_strong(expected.index_, index.index_,
+ ::std::memory_order_acq_rel);
}
private: