poor performance on arm-a7

This commit is contained in:
mutouyun 2018-12-13 11:50:26 +08:00
parent b6248ad5dc
commit 7a7426a8b8
2 changed files with 5 additions and 8 deletions

View File

@ -38,8 +38,8 @@ struct alignas(std::max_align_t) elem_array_head {
} }
auto acquire(void) { auto acquire(void) {
for (unsigned k = 0; lc_.exchange(1, std::memory_order_acquire); ++k) { while (lc_.exchange(1, std::memory_order_acquire)) {
yield(k); std::this_thread::yield();
} }
return index_of(wt_.load(std::memory_order_relaxed)); return index_of(wt_.load(std::memory_order_relaxed));
} }
@ -107,7 +107,7 @@ public:
void* acquire(void) { void* acquire(void) {
elem_t* el = elem(base_t::acquire()); elem_t* el = elem(base_t::acquire());
// check all consumers have finished reading // check all consumers have finished reading
for (unsigned k = 0;; ++k) { while(1) {
uint_t<32> expected = 0; uint_t<32> expected = 0;
if (el->head_.rc_.compare_exchange_weak( if (el->head_.rc_.compare_exchange_weak(
expected, expected,
@ -115,7 +115,7 @@ public:
std::memory_order_release)) { std::memory_order_release)) {
break; break;
} }
yield(k); std::this_thread::yield();
} }
return el->data_; return el->data_;
} }

View File

@ -4,7 +4,6 @@
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
#include <thread> #include <thread>
#include <chrono>
namespace ipc { namespace ipc {
@ -87,9 +86,7 @@ inline void yield(unsigned k) {
else else
if (k < 16) { IPC_LOCK_PAUSE_(); } if (k < 16) { IPC_LOCK_PAUSE_(); }
else else
if (k < 32) { std::this_thread::yield(); } { std::this_thread::yield(); }
else
{ std::this_thread::sleep_for(std::chrono::milliseconds(1)); }
} }
} // namespace ipc } // namespace ipc