diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-14 21:22:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-14 21:22:26 +0200 |
commit | 34701ddb6dcc23aa0adf3e18fe474959200431d0 (patch) | |
tree | f7508ed8b7e44d4bf08fae3abf23d3793c3f1067 /vespalib | |
parent | 9f929ef46780a299748c7a5cf4978f842e74fe88 (diff) | |
parent | b7d1919875893a8e9d27a51f495e6e245c92da9f (diff) |
Merge pull request #14881 from vespa-engine/balder/modernize-rendevouz
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); } } } |