diff options
author | Jason Carey <jcarey@argv.me> | 2018-03-08 16:43:28 -0500 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2018-04-09 17:56:54 -0400 |
commit | 9be2c132cb4713e13bbaa5648077e5346a29c99b (patch) | |
tree | 05a878fb25660d7c224dcf704bfd30d33396eb43 /src | |
parent | c32837da21ec0963773d891c99e92375dadfe6e6 (diff) | |
download | mongo-9be2c132cb4713e13bbaa5648077e5346a29c99b.tar.gz |
SERVER-33413 nia countdownlatch misues condvars
You have to hold the mutex that a condvar is waiting on while modifying
the shared state the predicate checks for, or you can see a misordered
write and hang forever.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/executor/network_interface_asio_test_utils.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/mongo/executor/network_interface_asio_test_utils.h b/src/mongo/executor/network_interface_asio_test_utils.h index 54424735b9b..a95da3dfc5f 100644 --- a/src/mongo/executor/network_interface_asio_test_utils.h +++ b/src/mongo/executor/network_interface_asio_test_utils.h @@ -34,7 +34,6 @@ #include <vector> #include "mongo/executor/task_executor.h" -#include "mongo/platform/atomic_word.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/future.h" #include "mongo/stdx/mutex.h" @@ -120,26 +119,29 @@ private: class CountdownLatch { public: - CountdownLatch(uint32_t count) : _count(count) {} + explicit CountdownLatch(uint32_t count) : _count(count) {} void countDown() { - if (_count.load() == 0) { + stdx::lock_guard<stdx::mutex> lk(_mtx); + if (_count == 0) { return; } - if (_count.subtractAndFetch(1) == 0) { + + --_count; + if (_count == 0) { _cv.notify_all(); } } void await() { stdx::unique_lock<stdx::mutex> lk(_mtx); - _cv.wait(lk, [&] { return _count.load() == 0; }); + _cv.wait(lk, [&] { return _count == 0; }); } private: - stdx::condition_variable _cv; stdx::mutex _mtx; - AtomicUInt32 _count; + stdx::condition_variable _cv; + size_t _count; }; namespace helpers { |