Rename Executioner to Executor

Reviewers: buda, florijan

Reviewed By: florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D764
This commit is contained in:
Mislav Bradac 2017-09-07 14:43:27 +02:00
parent be16409da2
commit 38c83d80cb
4 changed files with 30 additions and 30 deletions

View File

@ -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;

View File

@ -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

View File

@ -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 <typename TRep, typename TPeriod>
Executioner(const std::chrono::duration<TRep, TPeriod> pause) {
Executor(const std::chrono::duration<TRep, TPeriod> 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.

View File

@ -3,56 +3,56 @@
#include "gtest/gtest.h"
#include "utils/executioner.hpp"
#include "utils/executor.hpp"
TEST(Executioner, DontRun) {
TEST(Executor, DontRun) {
std::atomic<int> 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<int> 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<int> count1{0};
std::atomic<int> 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);