提交 404bc88b 编写于 作者: W wxyu

MS-365 Use tasktableitemptr instead in event


Former-commit-id: a2d8fe7456dc59da280f475ae489a63fa9c3d362
上级 8ffd68ec
...@@ -20,6 +20,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -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-359 - Add cost test in new scheduler
- MS-361 - Add event in resource - MS-361 - Add event in resource
- MS-364 - Modify tasktableitem in tasktable - MS-364 - Modify tasktableitem in tasktable
- MS-365 - Use tasktableitemptr instead in event
## New Feature ## New Feature
- MS-343 - Implement ResourceMgr - MS-343 - Implement ResourceMgr
......
...@@ -15,11 +15,11 @@ namespace engine { ...@@ -15,11 +15,11 @@ namespace engine {
class CopyCompletedEvent : public Event { class CopyCompletedEvent : public Event {
public: public:
CopyCompletedEvent(std::weak_ptr<Resource> resource, TaskTableItem &task_table_item) CopyCompletedEvent(std::weak_ptr<Resource> resource, TaskTableItemPtr task_table_item)
: Event(EventType::COPY_COMPLETED, std::move(resource)), : Event(EventType::COPY_COMPLETED, std::move(resource)),
task_table_item_(task_table_item) {} task_table_item_(std::move(task_table_item)) {}
public: public:
TaskTableItem &task_table_item_; TaskTableItemPtr task_table_item_;
}; };
} }
......
...@@ -14,12 +14,12 @@ namespace engine { ...@@ -14,12 +14,12 @@ namespace engine {
class FinishTaskEvent : public Event { class FinishTaskEvent : public Event {
public: public:
FinishTaskEvent(std::weak_ptr<Resource> resource, TaskTableItem &task_table_item) FinishTaskEvent(std::weak_ptr<Resource> resource, TaskTableItemPtr task_table_item)
: Event(EventType::FINISH_TASK, std::move(resource)), : Event(EventType::FINISH_TASK, std::move(resource)),
task_table_item_(task_table_item) {} task_table_item_(std::move(task_table_item)) {}
public: public:
TaskTableItem &task_table_item_; TaskTableItemPtr task_table_item_;
}; };
} }
......
...@@ -41,23 +41,23 @@ void Resource::WakeupLoader() { ...@@ -41,23 +41,23 @@ void Resource::WakeupLoader() {
load_cv_.notify_one(); load_cv_.notify_one();
} }
TaskPtr Resource::pick_task_load() { TaskTableItemPtr Resource::pick_task_load() {
auto indexes = PickToLoad(task_table_, 3); auto indexes = PickToLoad(task_table_, 3);
for (auto index : indexes) { for (auto index : indexes) {
// try to set one task loading, then return // try to set one task loading, then return
if (task_table_.Load(index)) if (task_table_.Load(index))
return task_table_.Get(index)->task; return task_table_.Get(index);
// else try next // else try next
} }
return nullptr; return nullptr;
} }
TaskPtr Resource::pick_task_execute() { TaskTableItemPtr Resource::pick_task_execute() {
auto indexes = PickToExecute(task_table_, 3); auto indexes = PickToExecute(task_table_, 3);
for (auto index : indexes) { for (auto index : indexes) {
// try to set one task executing, then return // try to set one task executing, then return
if (task_table_.Execute(index)) if (task_table_.Execute(index))
return task_table_.Get(index)->task; return task_table_.Get(index);
// else try next // else try next
} }
return nullptr; return nullptr;
...@@ -67,12 +67,12 @@ void Resource::loader_function() { ...@@ -67,12 +67,12 @@ void Resource::loader_function() {
while (running_) { while (running_) {
std::unique_lock<std::mutex> lock(load_mutex_); std::unique_lock<std::mutex> lock(load_mutex_);
load_cv_.wait(lock, [&] { return load_flag_; }); load_cv_.wait(lock, [&] { return load_flag_; });
auto task = pick_task_load(); auto task_item = pick_task_load();
if (task) { if (task_item) {
LoadFile(task); LoadFile(task_item->task);
if (subscriber_) { if (subscriber_) {
// auto event = std::make_shared<CopyCompletedEvent>(shared_from_this(), task); auto event = std::make_shared<CopyCompletedEvent>(shared_from_this(), task_item);
// subscriber_(std::static_pointer_cast<Event>(event)); subscriber_(std::static_pointer_cast<Event>(event));
} }
} }
} }
...@@ -81,18 +81,18 @@ void Resource::loader_function() { ...@@ -81,18 +81,18 @@ void Resource::loader_function() {
void Resource::executor_function() { void Resource::executor_function() {
GetRegisterFunc(RegisterType::START_UP)->Exec(); GetRegisterFunc(RegisterType::START_UP)->Exec();
if (subscriber_) { if (subscriber_) {
// auto event = std::make_shared<StartUpEvent>(shared_from_this()); auto event = std::make_shared<StartUpEvent>(shared_from_this());
// subscriber_(std::static_pointer_cast<Event>(event)); subscriber_(std::static_pointer_cast<Event>(event));
} }
while (running_) { while (running_) {
std::unique_lock<std::mutex> lock(exec_mutex_); std::unique_lock<std::mutex> lock(exec_mutex_);
exec_cv_.wait(lock, [&] { return exec_flag_; }); exec_cv_.wait(lock, [&] { return exec_flag_; });
auto task = pick_task_execute(); auto task_item = pick_task_execute();
if (task) { if (task_item) {
Process(task); Process(task_item->task);
if (subscriber_) { if (subscriber_) {
// auto event = std::make_shared<FinishTaskEvent>(shared_from_this(), task); auto event = std::make_shared<FinishTaskEvent>(shared_from_this(), task_item);
// subscriber_(std::static_pointer_cast<Event>(event)); subscriber_(std::static_pointer_cast<Event>(event));
} }
} }
} }
......
...@@ -114,14 +114,14 @@ private: ...@@ -114,14 +114,14 @@ private:
* Pick one task to load; * Pick one task to load;
* Order by start time; * Order by start time;
*/ */
TaskPtr TaskTableItemPtr
pick_task_load(); pick_task_load();
/* /*
* Pick one task to execute; * Pick one task to execute;
* Pick by start time and priority; * Pick by start time and priority;
*/ */
TaskPtr TaskTableItemPtr
pick_task_execute(); pick_task_execute();
private: private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册