This commit is contained in:
mutouyun 2020-09-20 15:30:19 +08:00
parent 8a13571312
commit 32f88c8353

View File

@ -21,7 +21,7 @@ constexpr std::size_t const min_sz = 128;
constexpr std::size_t const max_sz = 1024 * 16; constexpr std::size_t const max_sz = 1024 * 16;
std::atomic<bool> is_quit__{ false }; std::atomic<bool> is_quit__{ false };
std::atomic<std::size_t> size_per_1s__{ 0 }; std::atomic<std::size_t> size_counter__{ 0 };
using msg_que_t = ipc::chan<ipc::relat::single, ipc::relat::single, ipc::trans::unicast>; using msg_que_t = ipc::chan<ipc::relat::single, ipc::relat::single, ipc::trans::unicast>;
@ -49,9 +49,8 @@ void do_counting() {
if (i % 10) continue; if (i % 10) continue;
i = 0; i = 0;
std::cout std::cout
<< speed_of(size_per_1s__.load(std::memory_order_acquire)) << speed_of(size_counter__.exchange(0, std::memory_order_relaxed))
<< std::endl; << std::endl;
size_per_1s__.store(0, std::memory_order_release);
} }
} }
@ -76,7 +75,7 @@ void do_send() {
break; break;
} }
} }
size_per_1s__.fetch_add(sz, std::memory_order_release); size_counter__.fetch_add(sz, std::memory_order_relaxed);
std::this_thread::yield(); std::this_thread::yield();
} }
counting.join(); counting.join();
@ -97,7 +96,7 @@ void do_recv() {
while (!is_quit__.load(std::memory_order_acquire)) { while (!is_quit__.load(std::memory_order_acquire)) {
auto msg = que__.recv(); auto msg = que__.recv();
if (msg.empty()) break; if (msg.empty()) break;
size_per_1s__.fetch_add(msg.size(), std::memory_order_release); size_counter__.fetch_add(msg.size(), std::memory_order_relaxed);
} }
counting.join(); counting.join();
} }