diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-14 19:03:12 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-14 19:03:12 +0000 |
commit | b7d1919875893a8e9d27a51f495e6e245c92da9f (patch) | |
tree | 0a05dbd5d52e7829b6ba5d9cebd85450fb319ee8 /vespalib | |
parent | 44918d807388c5c3d5a652c6f49693b71548f3b7 (diff) |
Use c++11 primitives for synchronization
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/rendezvous.h | 15 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/rendezvous.hpp | 9 |
2 files changed, 13 insertions, 11 deletions
diff --git a/vespalib/src/vespa/vespalib/util/rendezvous.h b/vespalib/src/vespa/vespalib/util/rendezvous.h index 93e0e61290b..be589f57b9d 100644 --- a/vespalib/src/vespa/vespalib/util/rendezvous.h +++ b/vespalib/src/vespa/vespalib/util/rendezvous.h @@ -2,7 +2,7 @@ #pragma once -#include "sync.h" +#include <condition_variable> #include <vector> namespace vespalib { @@ -22,12 +22,13 @@ template <typename IN, typename OUT> class Rendezvous { private: - Monitor _monitor; - size_t _size; - size_t _next; - size_t _gen; - std::vector<IN *> _in; - std::vector<OUT *> _out; + std::mutex _lock; + std::condition_variable _cond; + size_t _size; + size_t _next; + size_t _gen; + std::vector<IN *> _in; + std::vector<OUT *> _out; /** * Function called to perform the actual inter-thread state diff --git a/vespalib/src/vespa/vespalib/util/rendezvous.hpp b/vespalib/src/vespa/vespalib/util/rendezvous.hpp index d5036c143ee..2af5a55c8ab 100644 --- a/vespalib/src/vespa/vespalib/util/rendezvous.hpp +++ b/vespalib/src/vespa/vespalib/util/rendezvous.hpp @@ -6,7 +6,8 @@ namespace vespalib { template <typename IN, typename OUT> Rendezvous<IN, OUT>::Rendezvous(size_t n) - : _monitor(), + : _lock(), + _cond(), _size(n), _next(0), _gen(0), @@ -31,7 +32,7 @@ Rendezvous<IN, OUT>::rendezvous(IN input) _out[0] = &ret; mingle(); } else { - MonitorGuard guard(_monitor); + std::unique_lock guard(_lock); size_t me = _next++; _in[me] = &input; _out[me] = &ret; @@ -39,11 +40,11 @@ Rendezvous<IN, OUT>::rendezvous(IN input) mingle(); _next = 0; ++_gen; - guard.broadcast(); + _cond.notify_all(); } else { size_t oldgen = _gen; while (oldgen == _gen) { - guard.wait(); + _cond.wait(guard); } } } |