summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2017-10-27 03:14:44 +0200
committerTor Egge <Tor.Egge@oath.com>2017-10-27 08:50:18 +0000
commit07adc22972f295380826def618597a9d229e855a (patch)
treeeef5323f6e39665b3da0380ec40a034149f714a4 /staging_vespalib
parentfb90317434d0f157cb256d3e9df4e64819622e9c (diff)
Use std::mutex and std::condition_variable instead of FastOS_Cond.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/clock.cpp12
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/clock.h6
2 files changed, 10 insertions, 8 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.cpp b/staging_vespalib/src/vespa/vespalib/util/clock.cpp
index 403e1408747..b19b067afa9 100644
--- a/staging_vespalib/src/vespa/vespalib/util/clock.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/clock.cpp
@@ -2,6 +2,7 @@
#include "clock.h"
#include <cassert>
+#include <chrono>
using namespace fastos;
@@ -11,6 +12,7 @@ namespace vespalib {
Clock::Clock(double timePeriod) :
_timeNS(0u),
_timePeriodMS(static_cast<uint32_t>(timePeriod*1000)),
+ _lock(),
_cond(),
_stop(false),
_running(false)
@@ -32,22 +34,20 @@ void Clock::Run(FastOS_ThreadInterface *thread, void *arguments)
{
(void) arguments;
_running = true;
- _cond.Lock();
+ std::unique_lock<std::mutex> guard(_lock);
while ( ! thread->GetBreakFlag() && !_stop) {
setTime();
- _cond.TimedWait(_timePeriodMS);
+ _cond.wait_for(guard, std::chrono::milliseconds(_timePeriodMS));
}
- _cond.Unlock();
_running = false;
}
void
Clock::stop(void)
{
- _cond.Lock();
+ std::unique_lock<std::mutex> guard(_lock);
_stop = true;
- _cond.Broadcast();
- _cond.Unlock();
+ _cond.notify_all();
}
}
diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.h b/staging_vespalib/src/vespa/vespalib/util/clock.h
index 253eba25556..75f407ec95d 100644
--- a/staging_vespalib/src/vespa/vespalib/util/clock.h
+++ b/staging_vespalib/src/vespa/vespalib/util/clock.h
@@ -2,8 +2,9 @@
#pragma once
#include <vespa/fastos/thread.h>
-#include <vespa/fastos/cond.h>
#include <vespa/fastos/timestamp.h>
+#include <mutex>
+#include <condition_variable>
namespace vespalib {
@@ -21,7 +22,8 @@ private:
mutable fastos::TimeStamp _timeNS;
int _timePeriodMS;
- FastOS_Cond _cond;
+ std::mutex _lock;
+ std::condition_variable _cond;
bool _stop;
bool _running;