mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
adjust ipc::sleep
This commit is contained in:
parent
45e4429056
commit
0dfbfd3fbf
@ -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;
|
||||
}
|
||||
|
||||
@ -57,12 +57,8 @@
|
||||
|
||||
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
|
||||
template <std::size_t N = 4096, typename K>
|
||||
inline void sleep(K& k) noexcept {
|
||||
if (k < static_cast<K>(N)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user