UserCore::ItemTask::BaseItemTask* ItemThread::getNewTask() { if (isPaused()) return NULL; UserCore::ItemTask::BaseItemTask* task = NULL; m_TaskMutex.lock(); if (m_vTaskList.size() != 0) { task = m_vTaskList.front(); m_vTaskList.pop_front(); gcString name = m_szBaseName; name += " - "; name += task->getTaskName(); this->setThreadName(name.c_str()); } m_TaskMutex.unlock(); return task; }
bool ItemThread::performTask() { if (isStopped()) return true; UserCore::ItemTask::BaseItemTask* task = getNewTask(); if (!task) return false; ITEM_STAGE taskType; { std::lock_guard<std::mutex> guard(m_DeleteMutex); m_bDeleteCurrentTask = false; taskType = task->getTaskType(); m_pCurrentTask = task; } if (!m_bDeleteCurrentTask) { m_bRunningTask = true; onTaskStartEvent(taskType); gcTrace("Task {0}", task->getTaskName()); task->doTask(); onTaskCompleteEvent(taskType); m_bRunningTask = false; } { std::lock_guard<std::mutex> guard(m_DeleteMutex); m_pCurrentTask = nullptr; } safe_delete(task); setThreadName(m_szBaseName.c_str()); return true; }
UserCore::ItemTask::BaseItemTask* ItemThread::getNewTask() { if (isPaused()) return nullptr; UserCore::ItemTask::BaseItemTask* task = nullptr; std::lock_guard<std::mutex> guard(m_TaskMutex); if (m_vTaskList.size() != 0) { task = m_vTaskList.front(); m_vTaskList.pop_front(); gcString name = m_szBaseName; name += " - "; name += task->getTaskName(); this->setThreadName(name.c_str()); } return task; }