diff options
author | Håvard Pettersen <havardpe@oath.com> | 2021-11-23 11:48:48 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2021-11-23 11:48:48 +0000 |
commit | 278f2d4bd3442b72f19e25b5114bb5149729ab0d (patch) | |
tree | 51b8cf5f00f89ac3dc756d9ca6493fd2741fd961 /vespalib | |
parent | aee7a2f2618e08973c407c3993c7d0b2a702da61 (diff) |
add cond case for early unlock
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/wakeup/wakeup_bench.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/vespalib/src/tests/wakeup/wakeup_bench.cpp b/vespalib/src/tests/wakeup/wakeup_bench.cpp index 8a64ccca51d..3661a7c9389 100644 --- a/vespalib/src/tests/wakeup/wakeup_bench.cpp +++ b/vespalib/src/tests/wakeup/wakeup_bench.cpp @@ -84,6 +84,29 @@ struct UseCond : State { } }; +struct UseCondNolock : State { + std::mutex mutex; + std::condition_variable cond; + void wakeup() { + std::unique_lock<std::mutex> lock(mutex); + set_wakeup(); + lock.unlock(); + cond.notify_one(); + } + void stop() { + std::unique_lock<std::mutex> lock(mutex); + set_stop(); + lock.unlock(); + cond.notify_one(); + } + void wait() { + std::unique_lock<std::mutex> lock(mutex); + while (is_ready()) { + cond.wait(lock); + } + } +}; + struct UsePipe : State { int pipefd[2]; UsePipe() { @@ -220,6 +243,7 @@ void benchmark() { TEST(WakeupBench, using_spin) { benchmark<Wakeup<UseSpin>>(); } TEST(WakeupBench, using_spin_yield) { benchmark<Wakeup<UseSpinYield>>(); } TEST(WakeupBench, using_cond) { benchmark<Wakeup<UseCond>>(); } +TEST(WakeupBench, using_cond_nolock) { benchmark<Wakeup<UseCondNolock>>(); } TEST(WakeupBench, using_pipe) { benchmark<Wakeup<UsePipe>>(); } #ifdef __linux__ |