Beispiel #1
0
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;
}
Beispiel #2
0
bool ItemThread::performTask()
{
    if (isStopped())
        return true;

    UserCore::ItemTask::BaseItemTask* task = getNewTask();

    if (!task)
        return false;

    m_DeleteMutex.lock();
    m_bDeleteCurrentTask = false;
    m_DeleteMutex.unlock();

    uint32 taskType = task->getTaskType();

    m_DeleteMutex.lock();
    m_pCurrentTask = task;
    m_DeleteMutex.unlock();

    if (!m_bDeleteCurrentTask)
    {
        m_bRunningTask = true;
        onTaskStartEvent(taskType);

        task->doTask();

        onTaskCompleteEvent(taskType);
        m_bRunningTask = false;
    }

    m_DeleteMutex.lock();
    m_pCurrentTask = NULL;
    m_DeleteMutex.unlock();

    safe_delete(task);
    setThreadName(m_szBaseName.c_str());

    return true;
}