diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index c1eabb510..6428baab5 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -56,7 +56,7 @@ using NLMISC::CSmartPtr; using NLMISC::CRGBA; using NLMISC::CVector; using NLMISC::CMatrix; -using NLMISC::CUnfairSynchronized; +using NLMISC::CSynchronized; class CMaterial; @@ -144,7 +144,7 @@ public: protected: - CUnfairSynchronized _SyncTexDrvInfos; + CSynchronized _SyncTexDrvInfos; TTexDrvSharePtrList _TexDrvShares; TMatDrvInfoPtrList _MatDrvInfos; diff --git a/code/nel/include/nel/misc/mutex.h b/code/nel/include/nel/misc/mutex.h index 9837cd158..a9b89d96c 100644 --- a/code/nel/include/nel/misc/mutex.h +++ b/code/nel/include/nel/misc/mutex.h @@ -48,9 +48,16 @@ namespace NLMISC { */ #define STORE_MUTEX_NAME +#ifdef NL_OS_WINDOWS + // By default on Windows, all mutex/synchronization use the CFair* class to avoid freeze problem. +# define CMutex CFairMutex +# define CSynchronized CFairSynchronized +#else + // On GNU/Linux and Mac, we use CUnfair* everwise it creates some strange deadlock during loading and after +# define CMutex CUnfairMutex +# define CSynchronized CUnfairSynchronized +#endif -// By default, all mutex use the CFairMutex class to avoid freeze problem. -#define CMutex CFairMutex /** * Classic mutex implementation (not necessarly fair) @@ -572,12 +579,6 @@ extern uint32 NbMutexes; #endif // MUTEX_DEBUG - - - -// By default, all synchronization use the CFairSynchronized class to avoid freeze problem. -#define CSynchronized CFairSynchronized - /** * This class ensure that the Value is accessed by only one thread. First you have to create a CSynchronized class with you type. * Then, if a thread want to modify or do anything on it, you create a CAccessor in a \b sub \b scope. You can modify the value @@ -618,13 +619,13 @@ public: CAccessor(CUnfairSynchronized *cs) { Synchronized = cs; - const_cast(Synchronized->_Mutex).enter(); + const_cast(Synchronized->_Mutex).enter(); } /// release the mutex ~CAccessor() { - const_cast(Synchronized->_Mutex).leave(); + const_cast(Synchronized->_Mutex).leave(); } /// access to the Value diff --git a/code/nel/include/nel/misc/task_manager.h b/code/nel/include/nel/misc/task_manager.h index 17f20f6c3..c8fbdfbcb 100644 --- a/code/nel/include/nel/misc/task_manager.h +++ b/code/nel/include/nel/misc/task_manager.h @@ -140,7 +140,7 @@ protected: /// queue of tasks, using list container instead of queue for DeleteTask methode CSynchronized _RunningTask; - CUnfairSynchronized > _TaskQueue; + CSynchronized > _TaskQueue; CSynchronized > _DoneTaskQueue; /// thread pointer diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index 9aefb3e51..d8a195c3a 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -50,7 +50,7 @@ IDriver::~IDriver() // Must clean up everything before closing driver. // Must doing this in release(), so assert here if not done... { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); nlassert( rTexDrvInfos.size() == 0 ); } @@ -81,7 +81,7 @@ bool IDriver::release(void) // Release refptr of TextureDrvInfos. Should be all null (because of precedent pass). { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); // must be empty, because precedent pass should have deleted all. @@ -234,7 +234,7 @@ void IDriver::removeIBDrvInfoPtr(ItIBDrvInfoPtrList ibDrvInfoIt) // *************************************************************************** void IDriver::removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt) { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); rTexDrvInfos.erase(texDrvInfoIt); @@ -268,7 +268,7 @@ bool IDriver::invalidateShareTexture (ITexture &texture) getTextureShareName (texture, name); // Look for the driver info for this share name - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); TTexDrvInfoPtrMap::iterator iteDrvInfo = rTexDrvInfos.find (name); if (iteDrvInfo != rTexDrvInfos.end()) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp index 0eed232ca..0c10a3eb8 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp @@ -549,7 +549,7 @@ bool CDriverD3D::setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded // insert or get the texture. { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); ItTexDrvInfoPtrMap itTex; @@ -1013,7 +1013,7 @@ bool CDriverD3D::isTextureExist(const ITexture&tex) getTextureShareName (tex, name); { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); result = (rTexDrvInfos.find(name) != rTexDrvInfos.end()); } diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 7c9d7e885..b1e584e25 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -727,7 +727,7 @@ bool CDriverGL::isTextureExist(const ITexture&tex) getTextureShareName (tex, name); { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); result = (rTexDrvInfos.find(name) != rTexDrvInfos.end()); } diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp index 77809fbe3..83a07038a 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp @@ -653,7 +653,7 @@ bool CDriverGL::setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded, // insert or get the texture. { - CUnfairSynchronized::CAccessor access(&_SyncTexDrvInfos); + CSynchronized::CAccessor access(&_SyncTexDrvInfos); TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); ItTexDrvInfoPtrMap itTex; diff --git a/code/nel/src/misc/async_file_manager.cpp b/code/nel/src/misc/async_file_manager.cpp index 194018d6a..e7b2bd072 100644 --- a/code/nel/src/misc/async_file_manager.cpp +++ b/code/nel/src/misc/async_file_manager.cpp @@ -67,7 +67,7 @@ void CAsyncFileManager::addLoadTask(IRunnable *ploadTask) bool CAsyncFileManager::cancelLoadTask(const CAsyncFileManager::ICancelCallback &callback) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); list &rTaskQueue = acces.value (); list::iterator it = rTaskQueue.begin(); @@ -87,8 +87,8 @@ bool CAsyncFileManager::cancelLoadTask(const CAsyncFileManager::ICancelCallback } // If not found, the current running task may be the one we want to cancel. Must wait it. - // Beware that this code works because of the CUnfairSynchronized access we made above (ensure that the - // taskmanager will end just the current task async (if any) and won't start another one. + // Beware that this code works because of the CSynchronized access we made above (ensure that the + // taskmanager will end just the current task async (if any) and won't start an other one. waitCurrentTaskToComplete (); return false; @@ -105,7 +105,7 @@ void CAsyncFileManager::loadMesh(const std::string& meshName, IShape **ppShp, ID /* bool CAsyncFileManager::cancelLoadMesh(const std::string& sMeshName) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); list &rTaskQueue = acces.value (); list::iterator it = rTaskQueue.begin(); @@ -167,7 +167,7 @@ void CAsyncFileManager::signal (bool *pSgn) void CAsyncFileManager::cancelSignal (bool *pSgn) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); list &rTaskQueue = acces.value (); list::iterator it = rTaskQueue.begin(); diff --git a/code/nel/src/misc/task_manager.cpp b/code/nel/src/misc/task_manager.cpp index 4001c1744..10b8ef556 100644 --- a/code/nel/src/misc/task_manager.cpp +++ b/code/nel/src/misc/task_manager.cpp @@ -49,7 +49,7 @@ CTaskManager::~CTaskManager() nlSleep(10); // There should be no remaining Tasks - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); nlassert(acces.value().empty()); _Thread->wait(); delete _Thread; @@ -65,7 +65,7 @@ void CTaskManager::run(void) while(_ThreadRunning) { { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); if(acces.value().empty()) { runnableTask = NULL; @@ -126,14 +126,14 @@ void CTaskManager::run(void) // Add a task to TaskManager void CTaskManager::addTask(IRunnable *r, float priority) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); acces.value().push_back(CWaitingTask(r, priority)); } /// Delete a task, only if task is not running, return true if found and deleted bool CTaskManager::deleteTask(IRunnable *r) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); for(list::iterator it = acces.value().begin(); it != acces.value().end(); it++) { if(it->Task == r) @@ -148,7 +148,7 @@ bool CTaskManager::deleteTask(IRunnable *r) /// Task list size uint CTaskManager::taskListSize(void) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); return (uint)acces.value().size(); } @@ -164,7 +164,7 @@ void CTaskManager::waitCurrentTaskToComplete () void CTaskManager::dump (std::vector &result) { CSynchronized::CAccessor accesCurrent(&_RunningTask); - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); CSynchronized >::CAccessor accesDone(&_DoneTaskQueue); const list &taskList = acces.value(); @@ -215,7 +215,7 @@ void CTaskManager::clearDump() uint CTaskManager::getNumWaitingTasks() { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); return (uint)acces.value().size(); } @@ -225,7 +225,7 @@ void CTaskManager::changeTaskPriority () { if (_ChangePriorityCallback) { - CUnfairSynchronized >::CAccessor acces(&_TaskQueue); + CSynchronized >::CAccessor acces(&_TaskQueue); list &taskList = acces.value(); list::iterator ite = taskList.begin();