summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-05-18 07:20:18 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-05-18 07:20:18 +0000
commit714346ca5e18851c784101537bcb9b0877d413a9 (patch)
tree121764ca0af5de204005d6b16d00a867f07fc5d8 /staging_vespalib
parentf05f60b1ec40be6f3e60349d65da60bc41555db3 (diff)
Move ScheduledExecutor to searchcore and drop fnet dependency in staging_vespalib in order to prepare collapsing stagingg vespalib into vespalib
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/CMakeLists.txt2
-rw-r--r--staging_vespalib/src/tests/timer/.gitignore1
-rw-r--r--staging_vespalib/src/tests/timer/CMakeLists.txt8
-rw-r--r--staging_vespalib/src/tests/timer/timer_test.cpp55
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp68
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h56
7 files changed, 0 insertions, 191 deletions
diff --git a/staging_vespalib/CMakeLists.txt b/staging_vespalib/CMakeLists.txt
index ff152bcc2a1..04ad5f85b74 100644
--- a/staging_vespalib/CMakeLists.txt
+++ b/staging_vespalib/CMakeLists.txt
@@ -9,7 +9,6 @@ vespa_define_module(
fastos
vespalog
vespalib
- fnet
TESTS
src/tests/array
@@ -36,7 +35,6 @@ vespa_define_module(
src/tests/stllike
src/tests/sequencedtaskexecutor
src/tests/singleexecutor
- src/tests/timer
${STAGING_VESPALIB_PROCESS_MEMORY_STATS_TESTDIR}
src/tests/xmlserializable
diff --git a/staging_vespalib/src/tests/timer/.gitignore b/staging_vespalib/src/tests/timer/.gitignore
deleted file mode 100644
index 9031e40152a..00000000000
--- a/staging_vespalib/src/tests/timer/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-staging_vespalib_timer_test_app
diff --git a/staging_vespalib/src/tests/timer/CMakeLists.txt b/staging_vespalib/src/tests/timer/CMakeLists.txt
deleted file mode 100644
index 9fd12f11c7c..00000000000
--- a/staging_vespalib/src/tests/timer/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(staging_vespalib_timer_test_app TEST
- SOURCES
- timer_test.cpp
- DEPENDS
- staging_vespalib
-)
-vespa_add_test(NAME staging_vespalib_timer_test_app COMMAND staging_vespalib_timer_test_app)
diff --git a/staging_vespalib/src/tests/timer/timer_test.cpp b/staging_vespalib/src/tests/timer/timer_test.cpp
deleted file mode 100644
index 1f0ee81e4e6..00000000000
--- a/staging_vespalib/src/tests/timer/timer_test.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vespalib/testkit/testapp.h>
-#include <vespa/vespalib/util/scheduledexecutor.h>
-#include <vespa/vespalib/util/size_literals.h>
-#include <vespa/fnet/transport.h>
-#include <vespa/fastos/thread.h>
-
-using namespace vespalib;
-using vespalib::Executor;
-typedef Executor::Task Task;
-
-namespace {
-
-class TestTask : public Task {
-private:
- vespalib::CountDownLatch &_latch;
-public:
- TestTask(vespalib::CountDownLatch & latch) : _latch(latch) { }
- void run() override { _latch.countDown(); }
-};
-
-}
-
-TEST("testScheduling") {
- vespalib::CountDownLatch latch1(3);
- vespalib::CountDownLatch latch2(2);
- FastOS_ThreadPool threadPool(64_Ki);
- FNET_Transport transport;
- transport.Start(&threadPool);
- ScheduledExecutor timer(transport);
- timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 100ms, 200ms);
- timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch2), 500ms, 500ms);
- EXPECT_TRUE(latch1.await(60s));
- EXPECT_TRUE(latch2.await(60s));
- timer.reset();
- transport.ShutDown(true);
-}
-
-TEST("testReset") {
- vespalib::CountDownLatch latch1(2);
- FastOS_ThreadPool threadPool(64_Ki);
- FNET_Transport transport;
- transport.Start(&threadPool);
- ScheduledExecutor timer(transport);
- timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 2s, 3s);
- timer.reset();
- EXPECT_TRUE(!latch1.await(3s));
- timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 200ms, 300ms);
- EXPECT_TRUE(latch1.await(60s));
- timer.reset();
- transport.ShutDown(true);
-}
-
-TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
index 2912ac2397b..0bdfed505d3 100644
--- a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -21,7 +21,6 @@ vespa_add_library(staging_vespalib_vespalib_util OBJECT
sequencedtaskexecutor.cpp
sequencedtaskexecutorobserver.cpp
shutdownguard.cpp
- scheduledexecutor.cpp
singleexecutor.cpp
testclock.cpp
xmlserializable.cpp
diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
deleted file mode 100644
index 99254240f3c..00000000000
--- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "scheduledexecutor.h"
-#include <vespa/fnet/scheduler.h>
-#include <vespa/fnet/task.h>
-#include <vespa/fnet/transport.h>
-
-namespace vespalib {
-
-using Task = vespalib::Executor::Task;
-
-class TimerTask : public FNET_Task
-{
-private:
- TimerTask(const TimerTask &);
- TimerTask&operator=(const TimerTask &);
-
- FNET_Scheduler *_scheduler;
- Task::UP _task;
- duration _interval;
-public:
- TimerTask(FNET_Scheduler *scheduler, Task::UP task, duration interval)
- : FNET_Task(scheduler),
- _task(std::move(task)),
- _interval(interval)
- { }
-
- ~TimerTask() {
- Kill();
- }
-
- void PerformTask() override {
- _task->run();
- Schedule(to_s(_interval));
- }
-};
-
-ScheduledExecutor::ScheduledExecutor(FNET_Transport & transport)
- : _transport(transport),
- _lock(),
- _taskList()
-{ }
-
-ScheduledExecutor::~ScheduledExecutor()
-{
- reset();
-}
-
-
-void
-ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, duration delay, duration interval)
-{
- std::lock_guard guard(_lock);
- auto tTask = std::make_unique<TimerTask>(_transport.GetScheduler(), std::move(task), interval);
- _taskList.push_back(std::move(tTask));
- _taskList.back()->Schedule(to_s(delay));
-}
-
-void
-ScheduledExecutor::reset()
-{
- std::lock_guard guard(_lock);
- for (auto & task : _taskList) {
- task->Unschedule();
- }
- _taskList.clear();
-}
-
-}
diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
deleted file mode 100644
index 2c29ff52432..00000000000
--- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/vespalib/util/executor.h>
-#include <vespa/vespalib/util/time.h>
-#include <mutex>
-#include <vector>
-
-class FNET_Transport;
-
-namespace vespalib {
-
-class TimerTask;
-
-/**
- * ScheduledExecutor is a class capable of running Tasks at a regular
- * interval. The timer can be reset to clear all tasks currently being
- * scheduled.
- */
-class ScheduledExecutor
-{
-private:
- using TaskList = std::vector<std::unique_ptr<TimerTask>>;
- FNET_Transport & _transport;
- std::mutex _lock;
- TaskList _taskList;
-
-public:
- /**
- * Create a new timer, capable of scheduling tasks at fixed intervals.
- */
- ScheduledExecutor(FNET_Transport & transport);
-
- /**
- * Destroys this timer, finishing the current task executing and then
- * finishing.
- */
- ~ScheduledExecutor();
-
- /**
- * Schedule new task to be executed at specified intervals.
- *
- * @param task The task to schedule.
- * @param delay The delay to wait before first execution.
- * @param interval The interval in seconds.
- */
- void scheduleAtFixedRate(std::unique_ptr<Executor::Task> task, duration delay, duration interval);
-
- /**
- * Reset timer, clearing the list of task to execute.
- */
- void reset();
-};
-
-}
-