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)) {
|
if (ct_.compare_exchange_weak(cur_ct, nxt_ct, std::memory_order_relaxed)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ipc::yield(k);
|
ipc::sleep<8192>(k);
|
||||||
}
|
}
|
||||||
std::forward<F>(f)(elem_start + detail::index_of(cur_ct));
|
std::forward<F>(f)(elem_start + detail::index_of(cur_ct));
|
||||||
for (unsigned k = 0;;) {
|
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)) {
|
if (wt_.compare_exchange_weak(exp_wt, nxt_ct, std::memory_order_release)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ipc::sleep(k);
|
ipc::sleep<8192>(k);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,13 +57,9 @@
|
|||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
template <std::size_t N = 32, typename K>
|
template <std::size_t N = 4096, typename K>
|
||||||
inline void yield(K& k) noexcept {
|
inline void sleep(K& k) noexcept {
|
||||||
if (k < 4) { /* Do nothing */ }
|
if (k < static_cast<K>(N)) {
|
||||||
else
|
|
||||||
if (k < 16) { IPC_LOCK_PAUSE_(); }
|
|
||||||
else
|
|
||||||
if (k < static_cast<K>(N)) {
|
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -73,9 +69,16 @@ inline void yield(K& k) noexcept {
|
|||||||
++k;
|
++k;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t N = 4096, typename K>
|
template <std::size_t N = 32, typename K>
|
||||||
inline void sleep(K& k) noexcept {
|
inline void yield(K& k) noexcept {
|
||||||
ipc::yield<N>(k);
|
if (k < 4) { /* Do nothing */ }
|
||||||
|
else
|
||||||
|
if (k < 16) { IPC_LOCK_PAUSE_(); }
|
||||||
|
else {
|
||||||
|
ipc::sleep<N>(k);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++k;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ipc
|
} // 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) {
|
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);
|
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) {
|
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);
|
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