Skip to content

Commit

Permalink
No longer use volatile in CTaskManager
Browse files Browse the repository at this point in the history
  • Loading branch information
kaetemi committed Mar 3, 2023
1 parent 94e15e3 commit 406ddb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 4 additions & 3 deletions nel/include/nel/misc/task_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "mutex.h"
#include "thread.h"
#include "atomic.h"

namespace NLMISC {

Expand Down Expand Up @@ -139,10 +140,10 @@ class CTaskManager : public IRunnable
CSynchronized<std::deque<std::string> > _DoneTaskQueue;

/// thread pointer
IThread *_Thread;
CUniquePtr<IThread> _Thread;

/// flag indicate thread loop, if false cause thread exit
volatile bool _ThreadRunning;
CAtomicBool _ThreadRunning;

private:

Expand All @@ -154,7 +155,7 @@ class CTaskManager : public IRunnable

private:

volatile bool _IsTaskRunning;
CAtomicBool _IsTaskRunning;

};

Expand Down
20 changes: 11 additions & 9 deletions nel/src/misc/task_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ CTaskManager::CTaskManager() : _RunningTask (""), _TaskQueue (""), _DoneTaskQueu
{
_IsTaskRunning = false;
_ThreadRunning = true;
_ChangePriorityCallback = NULL;
CSynchronized<string>::CAccessor currentTask(&_RunningTask);
currentTask.value ().clear();
_Thread = IThread::create(this);
_Thread.reset(IThread::create(this));
_Thread->start();
_ChangePriorityCallback = NULL;
}

/*
Expand All @@ -52,16 +52,19 @@ CTaskManager::CTaskManager() : _RunningTask (""), _TaskQueue (""), _DoneTaskQueu
CTaskManager::~CTaskManager()
{
_ThreadRunning = false;
while(!_ThreadRunning)
nlSleep(10);
try
{
_Thread->wait();
}
catch (EThread &)
{
// no exception in destructor
}

// There should be no remaining Tasks
CSynchronized<std::list<CWaitingTask> >::CAccessor acces(&_TaskQueue);
nlassert(acces.value().empty());
_Thread->wait();
delete _Thread;
_Thread = NULL;

_Thread.reset(NULL);
}

// Manage TaskQueue
Expand Down Expand Up @@ -127,7 +130,6 @@ void CTaskManager::run(void)
}
}
CBigFile::getInstance().currentThreadFinished();
_ThreadRunning = true;
}

// Add a task to TaskManager
Expand Down

0 comments on commit 406ddb4

Please sign in to comment.