adjust ipc::sleep

This commit is contained in:
mutouyun 2019-01-07 15:25:03 +08:00
parent 45e4429056
commit 0dfbfd3fbf
3 changed files with 18 additions and 12 deletions

View File

@ -134,7 +134,7 @@ struct prod_cons<relat::multi, relat::multi, trans::unicast>
if (ct_.compare_exchange_weak(cur_ct, nxt_ct, std::memory_order_relaxed)) {
break;
}
ipc::yield(k);
ipc::sleep<8192>(k);
}
std::forward<F>(f)(elem_start + detail::index_of(cur_ct));
for (unsigned k = 0;;) {
@ -142,7 +142,7 @@ struct prod_cons<relat::multi, relat::multi, trans::unicast>
if (wt_.compare_exchange_weak(exp_wt, nxt_ct, std::memory_order_release)) {
break;
}
ipc::sleep(k);
ipc::sleep<8192>(k);
}
return true;
}

View File

@ -57,13 +57,9 @@
namespace ipc {
template <std::size_t N = 32, typename K>
inline void yield(K& k) noexcept {
if (k < 4) { /* Do nothing */ }
else
if (k < 16) { IPC_LOCK_PAUSE_(); }
else
if (k < static_cast<K>(N)) {
template <std::size_t N = 4096, typename K>
inline void sleep(K& k) noexcept {
if (k < static_cast<K>(N)) {
std::this_thread::yield();
}
else {
@ -73,9 +69,16 @@ inline void yield(K& k) noexcept {
++k;
}
template <std::size_t N = 4096, typename K>
inline void sleep(K& k) noexcept {
ipc::yield<N>(k);
template <std::size_t N = 32, typename K>
inline void yield(K& k) noexcept {
if (k < 4) { /* Do nothing */ }
else
if (k < 16) { IPC_LOCK_PAUSE_(); }
else {
ipc::sleep<N>(k);
return;
}
++k;
}
} // namespace ipc

View File

@ -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<decltype(index)::value + 1, 1, LoopCount, void>(&el_arr_mmn);
});
ipc::mem::detail::static_for(std::make_index_sequence<10>{}, [&el_arr_mmn](auto index) {
benchmark_prod_cons<decltype(index)::value + 1, decltype(index)::value + 1, LoopCount, void>(&el_arr_mmn);
});