diff --git a/src/data_structures/concurrent/skiplist_gc.hpp b/src/data_structures/concurrent/skiplist_gc.hpp index df0170502..16cedde92 100644 --- a/src/data_structures/concurrent/skiplist_gc.hpp +++ b/src/data_structures/concurrent/skiplist_gc.hpp @@ -12,7 +12,7 @@ #include "data_structures/concurrent/push_queue.hpp" #include "threading/sync/spinlock.hpp" -#include "utils/executioner.hpp" +#include "utils/executor.hpp" DECLARE_int32(skiplist_gc_interval); @@ -32,13 +32,13 @@ class SkipListGC { public: explicit SkipListGC() { executor_job_id_ = - GetExecutioner().RegisterJob([this]() { GarbageCollect(); }); + GetExecutor().RegisterJob([this]() { GarbageCollect(); }); } ~SkipListGC() { - // We have to unregister the job because otherwise Executioner might access + // We have to unregister the job because otherwise Executor might access // some member variables of this class after it has been destructed. - GetExecutioner().UnRegisterJob(executor_job_id_); + GetExecutor().UnRegisterJob(executor_job_id_); for (auto it = deleted_queue_.begin(); it != deleted_queue_.end(); ++it) { TNode::destroy(it->second); } @@ -46,19 +46,19 @@ class SkipListGC { } /** - * @brief - Returns instance of executioner shared between all SkipLists. + * @brief - Returns instance of executor shared between all SkipLists. */ - auto &GetExecutioner() { - // TODO: Even though executioner is static, there are multiple instance: + auto &GetExecutor() { + // TODO: Even though executor is static, there are multiple instance: // one for each TNode param type. We probably don't want that kind of // behavior. Static variables with nontrivial destructor create subtle bugs // because of their order of destruction. For example of one bug take a look // at documentation in database/dbms.hpp. Rethink ownership and lifetime of - // executioner. - static Executioner executioner( + // executor. + static Executor executor( (std::chrono::seconds(FLAGS_skiplist_gc_interval))); - return executioner; + return executor; } SkipListGC(const SkipListGC &other) = delete; diff --git a/src/database/dbms.hpp b/src/database/dbms.hpp index e6e4c9a75..0e478cc6d 100644 --- a/src/database/dbms.hpp +++ b/src/database/dbms.hpp @@ -29,11 +29,11 @@ namespace fs = std::experimental::filesystem; // v.add_label(dba->Label( // "Start")); // New SkipList is created in KeyIndex for LabelIndex. // // That SkipList creates SkipListGc which -// // initialises static Executioner object. +// // initialises static Executor object. // return 0; // } // -// After main exits: 1. Executioner is destructed, 2. KeyIndex is destructed. +// After main exits: 1. Executor is destructed, 2. KeyIndex is destructed. // Destructor of KeyIndex calls delete on created SkipLists which destroy // SkipListGc that tries to use Excutioner object that doesn't exist anymore. // -> CRASH diff --git a/src/utils/executioner.hpp b/src/utils/executor.hpp similarity index 93% rename from src/utils/executioner.hpp rename to src/utils/executor.hpp index 97d10ed99..c6018cae9 100644 --- a/src/utils/executioner.hpp +++ b/src/utils/executor.hpp @@ -10,15 +10,15 @@ * @brief - Provides execution of jobs in job queue on one thread with 'pause' * time between two consecutives starts. */ -class Executioner { +class Executor { public: template - Executioner(const std::chrono::duration pause) { + Executor(const std::chrono::duration pause) { if (pause != pause.zero()) - scheduler_.Run(pause, std::bind(&Executioner::Execute, this)); + scheduler_.Run(pause, std::bind(&Executor::Execute, this)); } - ~Executioner() { + ~Executor() { // Be sure to first stop scheduler because otherwise we might destroy the // mutex before the scheduler and that might cause problems since mutex is // used in Execute method passed to scheduler along with jobs vector. diff --git a/tests/unit/executioner.cpp b/tests/unit/executor.cpp similarity index 63% rename from tests/unit/executioner.cpp rename to tests/unit/executor.cpp index 01c3ef694..92e19b1c8 100644 --- a/tests/unit/executioner.cpp +++ b/tests/unit/executor.cpp @@ -3,56 +3,56 @@ #include "gtest/gtest.h" -#include "utils/executioner.hpp" +#include "utils/executor.hpp" -TEST(Executioner, DontRun) { +TEST(Executor, DontRun) { std::atomic count{0}; { - Executioner exec(std::chrono::seconds(0)); - // Be sure executioner is sleeping. + Executor exec(std::chrono::seconds(0)); + // Be sure executor is sleeping. std::this_thread::sleep_for(std::chrono::milliseconds(100)); exec.RegisterJob([&count]() { ++count; }); - // Try to wait to test if executioner might somehow become awake and execute + // Try to wait to test if executor might somehow become awake and execute // the job. std::this_thread::sleep_for(std::chrono::milliseconds(500)); } EXPECT_EQ(count, 0); } -TEST(Executioner, Run) { +TEST(Executor, Run) { std::atomic count{0}; { - Executioner exec(std::chrono::milliseconds(500)); - // Be sure executioner is sleeping. + Executor exec(std::chrono::milliseconds(500)); + // Be sure executor is sleeping. std::this_thread::sleep_for(std::chrono::milliseconds(100)); exec.RegisterJob([&count]() { ++count; }); exec.RegisterJob([&count]() { ++count; }); exec.RegisterJob([&count]() { ++count; }); - // Be sure executioner execute thread is triggered + // Be sure executor execute thread is triggered std::this_thread::sleep_for(std::chrono::milliseconds(500)); } EXPECT_EQ(count, 3); } -TEST(Executioner, RunUnregister) { +TEST(Executor, RunUnregister) { std::atomic count1{0}; std::atomic count2{0}; { - Executioner exec(std::chrono::milliseconds(500)); - // Be sure executioner is sleeping. + Executor exec(std::chrono::milliseconds(500)); + // Be sure executor is sleeping. std::this_thread::sleep_for(std::chrono::milliseconds(100)); auto job = exec.RegisterJob([&count1]() { ++count1; }); exec.RegisterJob([&count2]() { ++count2; }); - // Be sure executioner execute thread is triggered + // Be sure executor execute thread is triggered std::this_thread::sleep_for(std::chrono::milliseconds(500)); exec.UnRegisterJob(job); - // Be sure executioner execute thread is triggered + // Be sure executor execute thread is triggered std::this_thread::sleep_for(std::chrono::milliseconds(500)); } EXPECT_EQ(count1, 1);