diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-03-12 09:24:37 -0400 |
---|---|---|
committer | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-03-13 11:25:44 -0400 |
commit | 422e304a2b3514c1b3f8f3dd452fcd5fc598b51f (patch) | |
tree | 0887e0deb6e015a4f1a1a72d696f48f101169545 /src/mongo/db/storage/kv/kv_storage_engine_test.cpp | |
parent | 49ce360e77d4fe92e83a5a8091772d283e68d7ef (diff) | |
download | mongo-422e304a2b3514c1b3f8f3dd452fcd5fc598b51f.tar.gz |
SERVER-40085 Avoid using barriers in TimestampMonitorNotifiesListeners
Diffstat (limited to 'src/mongo/db/storage/kv/kv_storage_engine_test.cpp')
-rw-r--r-- | src/mongo/db/storage/kv/kv_storage_engine_test.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/mongo/db/storage/kv/kv_storage_engine_test.cpp b/src/mongo/db/storage/kv/kv_storage_engine_test.cpp index 935bef73175..609df0dc661 100644 --- a/src/mongo/db/storage/kv/kv_storage_engine_test.cpp +++ b/src/mongo/db/storage/kv/kv_storage_engine_test.cpp @@ -573,34 +573,40 @@ TEST_F(TimestampKVEngineTest, TimestampListeners) { } TEST_F(TimestampKVEngineTest, TimestampMonitorNotifiesListeners) { - unittest::Barrier barrier(2); + stdx::mutex mutex; + stdx::condition_variable cv; + bool changes[4] = {false, false, false, false}; TimestampListener first(checkpoint, [&](Timestamp timestamp) { + stdx::lock_guard<stdx::mutex> lock(mutex); if (!changes[0]) { changes[0] = true; - barrier.countDownAndWait(); + cv.notify_all(); } }); TimestampListener second(oldest, [&](Timestamp timestamp) { + stdx::lock_guard<stdx::mutex> lock(mutex); if (!changes[1]) { changes[1] = true; - barrier.countDownAndWait(); + cv.notify_all(); } }); TimestampListener third(stable, [&](Timestamp timestamp) { + stdx::lock_guard<stdx::mutex> lock(mutex); if (!changes[2]) { changes[2] = true; - barrier.countDownAndWait(); + cv.notify_all(); } }); TimestampListener fourth(stable, [&](Timestamp timestamp) { + stdx::lock_guard<stdx::mutex> lock(mutex); if (!changes[3]) { changes[3] = true; - barrier.countDownAndWait(); + cv.notify_all(); } }); @@ -610,11 +616,15 @@ TEST_F(TimestampKVEngineTest, TimestampMonitorNotifiesListeners) { _storageEngine->getTimestampMonitor()->addListener(&fourth); // Wait until all 4 listeners get notified at least once. - size_t listenersNotified = 0; - while (listenersNotified < 4) { - barrier.countDownAndWait(); - listenersNotified++; - } + stdx::unique_lock<stdx::mutex> lk(mutex); + cv.wait(lk, [&] { + for (auto const& change : changes) { + if (!change) { + return false; + } + } + return true; + }); _storageEngine->getTimestampMonitor()->removeListener(&first); _storageEngine->getTimestampMonitor()->removeListener(&second); |