diff --git a/include/circ_elem_array.h b/include/circ_elem_array.h index 46c396f..a5b4b77 100644 --- a/include/circ_elem_array.h +++ b/include/circ_elem_array.h @@ -134,7 +134,7 @@ struct prod_cons if (ct_.compare_exchange_weak(cur_ct, nxt_ct, std::memory_order_relaxed)) { break; } - ipc::yield(k); + ipc::sleep<8192>(k); } std::forward(f)(elem_start + detail::index_of(cur_ct)); for (unsigned k = 0;;) { @@ -142,7 +142,7 @@ struct prod_cons if (wt_.compare_exchange_weak(exp_wt, nxt_ct, std::memory_order_release)) { break; } - ipc::sleep(k); + ipc::sleep<8192>(k); } return true; } diff --git a/include/rw_lock.h b/include/rw_lock.h index 362e2bf..2cea0ca 100644 --- a/include/rw_lock.h +++ b/include/rw_lock.h @@ -57,13 +57,9 @@ namespace ipc { -template -inline void yield(K& k) noexcept { - if (k < 4) { /* Do nothing */ } - else - if (k < 16) { IPC_LOCK_PAUSE_(); } - else - if (k < static_cast(N)) { +template +inline void sleep(K& k) noexcept { + if (k < static_cast(N)) { std::this_thread::yield(); } else { @@ -73,9 +69,16 @@ inline void yield(K& k) noexcept { ++k; } -template -inline void sleep(K& k) noexcept { - ipc::yield(k); +template +inline void yield(K& k) noexcept { + if (k < 4) { /* Do nothing */ } + else + if (k < 16) { IPC_LOCK_PAUSE_(); } + else { + ipc::sleep(k); + return; + } + ++k; } } // namespace ipc diff --git a/test/test_circ.cpp b/test/test_circ.cpp index 93b78f5..1cf1995 100644 --- a/test/test_circ.cpp +++ b/test/test_circ.cpp @@ -333,6 +333,9 @@ void Unit::test_prod_cons_performance() { ipc::mem::detail::static_for(std::make_index_sequence<10>{}, [&el_arr_mmn](auto index) { benchmark_prod_cons<1, decltype(index)::value + 1, LoopCount, void>(&el_arr_mmn); }); + ipc::mem::detail::static_for(std::make_index_sequence<10>{}, [&el_arr_mmn](auto index) { + benchmark_prod_cons(&el_arr_mmn); + }); ipc::mem::detail::static_for(std::make_index_sequence<10>{}, [&el_arr_mmn](auto index) { benchmark_prod_cons(&el_arr_mmn); });