You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
581 B
37 lines
581 B
#include "Task.h"
|
|
|
|
Task::Task()
|
|
{
|
|
}
|
|
|
|
Task::~Task()
|
|
{
|
|
}
|
|
|
|
int Task::sendTask(std::shared_ptr<TaskInfo> task)
|
|
{
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_task_mutex_);
|
|
task->SetStatus(TaskStep_Waite);
|
|
m_tasks_.push(task);
|
|
}
|
|
|
|
m_task_cv_.notify_one();
|
|
return 0;
|
|
}
|
|
|
|
std::shared_ptr<TaskInfo> Task::GetTask()
|
|
{
|
|
std::shared_ptr<TaskInfo> task;
|
|
{
|
|
std::unique_lock<std::mutex> lock(m_task_mutex_);
|
|
m_task_cv_.wait(lock, [this]()
|
|
{ return !m_tasks_.empty(); });
|
|
|
|
task = std::move(m_tasks_.front());
|
|
m_tasks_.pop();
|
|
}
|
|
|
|
return task;
|
|
}
|