aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_eventcount.cpp
diff options
context:
space:
mode:
authorGravatar Rasmus Munk Larsen <rmlarsen@google.com>2019-02-22 13:56:26 -0800
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2019-02-22 13:56:26 -0800
commit6560692c670bcf34fc922474bf37f3c18b8768af (patch)
tree551dd7bd544c2db42f34b92bfaf368744bcc525f /unsupported/test/cxx11_eventcount.cpp
parent0b25a5c431f2764cd46a04f07536d60256ecd256 (diff)
Improve EventCount used by the non-blocking threadpool.
The current algorithm requires threads to commit/cancel waiting in order they called Prewait. Spinning caused by that serialization can consume lots of CPU time on some workloads. Restructure the algorithm to not require that serialization and remove spin waits from Commit/CancelWait. Note: this reduces max number of threads from 2^16 to 2^14 to leave more space for ABA counter (which is now 22 bits). Implementation details are explained in comments.
Diffstat (limited to 'unsupported/test/cxx11_eventcount.cpp')
-rw-r--r--unsupported/test/cxx11_eventcount.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/unsupported/test/cxx11_eventcount.cpp b/unsupported/test/cxx11_eventcount.cpp
index 2f1418684..3ca8598c7 100644
--- a/unsupported/test/cxx11_eventcount.cpp
+++ b/unsupported/test/cxx11_eventcount.cpp
@@ -30,11 +30,11 @@ static void test_basic_eventcount()
EventCount ec(waiters);
EventCount::Waiter& w = waiters[0];
ec.Notify(false);
- ec.Prewait(&w);
+ VERIFY(ec.Prewait());
ec.Notify(true);
ec.CommitWait(&w);
- ec.Prewait(&w);
- ec.CancelWait(&w);
+ VERIFY(ec.Prewait());
+ ec.CancelWait();
}
// Fake bounded counter-based queue.
@@ -112,7 +112,7 @@ static void test_stress_eventcount()
unsigned idx = rand_reentrant(&rnd) % kQueues;
if (queues[idx].Pop()) continue;
j--;
- ec.Prewait(&w);
+ if (!ec.Prewait()) continue;
bool empty = true;
for (int q = 0; q < kQueues; q++) {
if (!queues[q].Empty()) {
@@ -121,7 +121,7 @@ static void test_stress_eventcount()
}
}
if (!empty) {
- ec.CancelWait(&w);
+ ec.CancelWait();
continue;
}
ec.CommitWait(&w);