aboutsummaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-12-06 23:04:43 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-12-16 23:48:45 +0000
commita200bf7708ad94661d1fc8da8776b3884ff78ef5 (patch)
treed9af222fa3376f1e8e77ab50b0c2bd8254560b88 /staging_vespalib
parent2f8e6f0cb74ef77a645e7543975aca736f7649a9 (diff)
fastos::TimeStamp -> vespalib::duration
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/tests/timer/timer_test.cpp8
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp10
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h3
3 files changed, 11 insertions, 10 deletions
diff --git a/staging_vespalib/src/tests/timer/timer_test.cpp b/staging_vespalib/src/tests/timer/timer_test.cpp
index 5472ad6e23f..04b541e75e9 100644
--- a/staging_vespalib/src/tests/timer/timer_test.cpp
+++ b/staging_vespalib/src/tests/timer/timer_test.cpp
@@ -37,8 +37,8 @@ void Test::testScheduling()
vespalib::CountDownLatch latch1(3);
vespalib::CountDownLatch latch2(2);
ScheduledExecutor timer;
- timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 0.1, 0.2);
- timer.scheduleAtFixedRate(Task::UP(new TestTask(latch2)), 0.5, 0.5);
+ timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 100ms, 200ms);
+ timer.scheduleAtFixedRate(Task::UP(new TestTask(latch2)), 500ms, 500ms);
EXPECT_TRUE(latch1.await(60000));
EXPECT_TRUE(latch2.await(60000));
}
@@ -47,10 +47,10 @@ void Test::testReset()
{
vespalib::CountDownLatch latch1(2);
ScheduledExecutor timer;
- timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 2.0, 3.0);
+ timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 2s, 3s);
timer.reset();
EXPECT_TRUE(!latch1.await(3000));
- timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 0.2, 0.3);
+ timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 200ms, 300ms);
EXPECT_TRUE(latch1.await(60000));
}
diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
index 61f9666114c..d9b4feda293 100644
--- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
@@ -16,9 +16,9 @@ private:
FNET_Scheduler *_scheduler;
Task::UP _task;
- double _interval;
+ duration _interval;
public:
- TimerTask(FNET_Scheduler *scheduler, Task::UP task, double interval)
+ TimerTask(FNET_Scheduler *scheduler, Task::UP task, duration interval)
: FNET_Task(scheduler),
_task(std::move(task)),
_interval(interval)
@@ -30,7 +30,7 @@ public:
void PerformTask() override {
_task->run();
- Schedule(_interval);
+ Schedule(to_s(_interval));
}
};
@@ -53,12 +53,12 @@ ScheduledExecutor::~ScheduledExecutor()
void
-ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, double delay, double interval)
+ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, duration delay, duration interval)
{
vespalib::LockGuard guard(_lock);
TimerTaskPtr tTask(new TimerTask(_transport->GetScheduler(), std::move(task), interval));
_taskList.push_back(std::move(tTask));
- _taskList.back()->Schedule(delay);
+ _taskList.back()->Schedule(to_s(delay));
}
void
diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
index d7e56494828..0f052c762a7 100644
--- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
+++ b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
@@ -3,6 +3,7 @@
#include <vespa/vespalib/util/executor.h>
#include <vespa/vespalib/util/sync.h>
+#include <vespa/vespalib/util/time.h>
#include <vespa/fastos/thread.h>
#include <vector>
@@ -46,7 +47,7 @@ public:
* @param delay The delay to wait before first execution.
* @param interval The interval in seconds.
*/
- void scheduleAtFixedRate(vespalib::Executor::Task::UP task, double delay, double interval);
+ void scheduleAtFixedRate(vespalib::Executor::Task::UP task, duration delay, duration interval);
/**
* Reset timer, clearing the list of task to execute.