From 404bc88b3f70846a2794feceb01eb394664fae4a Mon Sep 17 00:00:00 2001 From: wxyu Date: Fri, 16 Aug 2019 15:36:56 +0800 Subject: [PATCH] MS-365 Use tasktableitemptr instead in event Former-commit-id: a2d8fe7456dc59da280f475ae489a63fa9c3d362 --- cpp/CHANGELOG.md | 1 + cpp/src/scheduler/event/CopyCompletedEvent.h | 6 ++-- cpp/src/scheduler/event/FinishTaskEvent.h | 6 ++-- cpp/src/scheduler/resource/Resource.cpp | 32 ++++++++++---------- cpp/src/scheduler/resource/Resource.h | 4 +-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index e05cb6cd..5e3d747e 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -20,6 +20,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-359 - Add cost test in new scheduler - MS-361 - Add event in resource - MS-364 - Modify tasktableitem in tasktable +- MS-365 - Use tasktableitemptr instead in event ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/event/CopyCompletedEvent.h b/cpp/src/scheduler/event/CopyCompletedEvent.h index 8db63490..c84c5933 100644 --- a/cpp/src/scheduler/event/CopyCompletedEvent.h +++ b/cpp/src/scheduler/event/CopyCompletedEvent.h @@ -15,11 +15,11 @@ namespace engine { class CopyCompletedEvent : public Event { public: - CopyCompletedEvent(std::weak_ptr resource, TaskTableItem &task_table_item) + CopyCompletedEvent(std::weak_ptr resource, TaskTableItemPtr task_table_item) : Event(EventType::COPY_COMPLETED, std::move(resource)), - task_table_item_(task_table_item) {} + task_table_item_(std::move(task_table_item)) {} public: - TaskTableItem &task_table_item_; + TaskTableItemPtr task_table_item_; }; } diff --git a/cpp/src/scheduler/event/FinishTaskEvent.h b/cpp/src/scheduler/event/FinishTaskEvent.h index 34658719..2739bb2f 100644 --- a/cpp/src/scheduler/event/FinishTaskEvent.h +++ b/cpp/src/scheduler/event/FinishTaskEvent.h @@ -14,12 +14,12 @@ namespace engine { class FinishTaskEvent : public Event { public: - FinishTaskEvent(std::weak_ptr resource, TaskTableItem &task_table_item) + FinishTaskEvent(std::weak_ptr resource, TaskTableItemPtr task_table_item) : Event(EventType::FINISH_TASK, std::move(resource)), - task_table_item_(task_table_item) {} + task_table_item_(std::move(task_table_item)) {} public: - TaskTableItem &task_table_item_; + TaskTableItemPtr task_table_item_; }; } diff --git a/cpp/src/scheduler/resource/Resource.cpp b/cpp/src/scheduler/resource/Resource.cpp index 9650f216..cf9ff9d8 100644 --- a/cpp/src/scheduler/resource/Resource.cpp +++ b/cpp/src/scheduler/resource/Resource.cpp @@ -41,23 +41,23 @@ void Resource::WakeupLoader() { load_cv_.notify_one(); } -TaskPtr Resource::pick_task_load() { +TaskTableItemPtr Resource::pick_task_load() { auto indexes = PickToLoad(task_table_, 3); for (auto index : indexes) { // try to set one task loading, then return if (task_table_.Load(index)) - return task_table_.Get(index)->task; + return task_table_.Get(index); // else try next } return nullptr; } -TaskPtr Resource::pick_task_execute() { +TaskTableItemPtr Resource::pick_task_execute() { auto indexes = PickToExecute(task_table_, 3); for (auto index : indexes) { // try to set one task executing, then return if (task_table_.Execute(index)) - return task_table_.Get(index)->task; + return task_table_.Get(index); // else try next } return nullptr; @@ -67,12 +67,12 @@ void Resource::loader_function() { while (running_) { std::unique_lock lock(load_mutex_); load_cv_.wait(lock, [&] { return load_flag_; }); - auto task = pick_task_load(); - if (task) { - LoadFile(task); + auto task_item = pick_task_load(); + if (task_item) { + LoadFile(task_item->task); if (subscriber_) { -// auto event = std::make_shared(shared_from_this(), task); -// subscriber_(std::static_pointer_cast(event)); + auto event = std::make_shared(shared_from_this(), task_item); + subscriber_(std::static_pointer_cast(event)); } } } @@ -81,18 +81,18 @@ void Resource::loader_function() { void Resource::executor_function() { GetRegisterFunc(RegisterType::START_UP)->Exec(); if (subscriber_) { -// auto event = std::make_shared(shared_from_this()); -// subscriber_(std::static_pointer_cast(event)); + auto event = std::make_shared(shared_from_this()); + subscriber_(std::static_pointer_cast(event)); } while (running_) { std::unique_lock lock(exec_mutex_); exec_cv_.wait(lock, [&] { return exec_flag_; }); - auto task = pick_task_execute(); - if (task) { - Process(task); + auto task_item = pick_task_execute(); + if (task_item) { + Process(task_item->task); if (subscriber_) { -// auto event = std::make_shared(shared_from_this(), task); -// subscriber_(std::static_pointer_cast(event)); + auto event = std::make_shared(shared_from_this(), task_item); + subscriber_(std::static_pointer_cast(event)); } } } diff --git a/cpp/src/scheduler/resource/Resource.h b/cpp/src/scheduler/resource/Resource.h index b33f17c4..a9a1454e 100644 --- a/cpp/src/scheduler/resource/Resource.h +++ b/cpp/src/scheduler/resource/Resource.h @@ -114,14 +114,14 @@ private: * Pick one task to load; * Order by start time; */ - TaskPtr + TaskTableItemPtr pick_task_load(); /* * Pick one task to execute; * Pick by start time and priority; */ - TaskPtr + TaskTableItemPtr pick_task_execute(); private: -- GitLab