summaryrefslogtreecommitdiffstats
path: root/vbench
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-10-14 14:21:01 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-10-14 14:21:01 +0000
commitc127fb84883687fc184c0eafeb2ebb8e9073cc7a (patch)
tree5a8b526948415c521b7f46837e110d96606bb114 /vbench
parent5ab1a8b97842b3a87fc0d3fec5cb631b1d356ab9 (diff)
vespalib::Monitor -> std:.mutex/std::condition_variable
Diffstat (limited to 'vbench')
-rw-r--r--vbench/src/vbench/core/handler_thread.h4
-rw-r--r--vbench/src/vbench/core/handler_thread.hpp15
-rw-r--r--vbench/src/vbench/core/time_queue.h6
-rw-r--r--vbench/src/vbench/core/time_queue.hpp19
4 files changed, 24 insertions, 20 deletions
diff --git a/vbench/src/vbench/core/handler_thread.h b/vbench/src/vbench/core/handler_thread.h
index e03304eff8f..87bc19d86f8 100644
--- a/vbench/src/vbench/core/handler_thread.h
+++ b/vbench/src/vbench/core/handler_thread.h
@@ -3,7 +3,6 @@
#pragma once
#include "handler.h"
-#include <vespa/vespalib/util/sync.h>
#include <vespa/vespalib/util/arrayqueue.hpp>
#include <vespa/vespalib/util/thread.h>
#include <vespa/vespalib/util/runnable.h>
@@ -24,7 +23,8 @@ class HandlerThread : public Handler<T>,
public vespalib::Joinable
{
private:
- vespalib::Monitor _monitor;
+ std::mutex _lock;
+ std::condition_variable _cond;
vespalib::ArrayQueue<std::unique_ptr<T> > _queue;
Handler<T> &_next;
vespalib::Thread _thread;
diff --git a/vbench/src/vbench/core/handler_thread.hpp b/vbench/src/vbench/core/handler_thread.hpp
index 4495c4c7900..88cb4a40526 100644
--- a/vbench/src/vbench/core/handler_thread.hpp
+++ b/vbench/src/vbench/core/handler_thread.hpp
@@ -7,9 +7,9 @@ void
HandlerThread<T>::run()
{
for (;;) {
- vespalib::MonitorGuard guard(_monitor);
+ std::unique_lock guard(_lock);
while (!_done && _queue.empty()) {
- guard.wait();
+ _cond.wait(guard);
}
if (_done && _queue.empty()) {
return;
@@ -24,7 +24,8 @@ HandlerThread<T>::run()
template <typename T>
HandlerThread<T>::HandlerThread(Handler<T> &next)
- : _monitor(),
+ : _lock(),
+ _cond(),
_queue(),
_next(next),
_thread(*this),
@@ -44,10 +45,10 @@ template <typename T>
void
HandlerThread<T>::handle(std::unique_ptr<T> obj)
{
- vespalib::MonitorGuard guard(_monitor);
+ std::unique_lock guard(_lock);
if (!_done) {
if (_queue.empty()) {
- guard.signal();
+ _cond.notify_one();
}
_queue.push(std::move(obj));
}
@@ -58,10 +59,10 @@ void
HandlerThread<T>::join()
{
{
- vespalib::MonitorGuard guard(_monitor);
+ std::lock_guard guard(_lock);
_done = true;
- guard.signal();
}
+ _cond.notify_one();
_thread.join();
}
diff --git a/vbench/src/vbench/core/time_queue.h b/vbench/src/vbench/core/time_queue.h
index 5237a6bc0fb..079aa1fc7f7 100644
--- a/vbench/src/vbench/core/time_queue.h
+++ b/vbench/src/vbench/core/time_queue.h
@@ -4,8 +4,9 @@
#include "closeable.h"
#include <vespa/vespalib/util/priority_queue.h>
-#include <vespa/vespalib/util/sync.h>
#include <memory>
+#include <mutex>
+#include <condition_variable>
namespace vbench {
@@ -33,7 +34,8 @@ private:
}
};
- vespalib::Monitor _monitor;
+ std::mutex _lock;
+ std::condition_variable _cond;
double _time;
double _window;
double _tick;
diff --git a/vbench/src/vbench/core/time_queue.hpp b/vbench/src/vbench/core/time_queue.hpp
index 0a1a74d72db..ddbf574e3c2 100644
--- a/vbench/src/vbench/core/time_queue.hpp
+++ b/vbench/src/vbench/core/time_queue.hpp
@@ -4,7 +4,8 @@ namespace vbench {
template <typename T>
TimeQueue<T>::TimeQueue(double window, double tick)
- : _monitor(),
+ : _lock(),
+ _cond(),
_time(0.0),
_window(window),
_tick(tick),
@@ -20,29 +21,29 @@ template <typename T>
void
TimeQueue<T>::close()
{
- vespalib::MonitorGuard guard(_monitor);
+ std::lock_guard guard(_lock);
_closed = true;
- guard.broadcast();
+ _cond.notify_all();
}
template <typename T>
void
TimeQueue<T>::discard()
{
- vespalib::MonitorGuard guard(_monitor);
+ std::lock_guard guard(_lock);
while (!_queue.empty()) {
_queue.pop_any();
}
- guard.broadcast();
+ _cond.notify_all();
}
template <typename T>
void
TimeQueue<T>::insert(std::unique_ptr<T> obj, double time)
{
- vespalib::MonitorGuard guard(_monitor);
+ std::unique_lock guard(_lock);
while (time > (_time + _window) && !_closed) {
- guard.wait();
+ _cond.wait(guard);
}
if (!_closed) {
_queue.push(Entry(std::move(obj), time));
@@ -53,13 +54,13 @@ template <typename T>
bool
TimeQueue<T>::extract(double time, std::vector<std::unique_ptr<T> > &list, double &delay)
{
- vespalib::MonitorGuard guard(_monitor);
+ std::lock_guard guard(_lock);
_time = time;
while (!_queue.empty() && _queue.front().time <= time) {
list.push_back(std::move(_queue.front().object));
_queue.pop_front();
}
- guard.broadcast();
+ _cond.notify_all();
delay = _queue.empty() ? _tick : (_queue.front().time - time);
return (!_closed || !_queue.empty() || !list.empty());
}