diff --git a/src/Nazara/Core/ConditionVariable.cpp b/src/Nazara/Core/ConditionVariable.cpp index ac8dcd50a..b9194d233 100644 --- a/src/Nazara/Core/ConditionVariable.cpp +++ b/src/Nazara/Core/ConditionVariable.cpp @@ -11,7 +11,7 @@ #elif defined(NAZARA_PLATFORM_POSIX) #include #else - #error Thread condition has no implementation + #error Condition variable has no implementation #endif #include diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 6c38f30f7..d0959b56e 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -85,10 +85,10 @@ void NzFile::Close() bool NzFile::Delete() { - NazaraLock(m_mutex) - Close(); + NazaraLock(m_mutex) + return Delete(m_filePath); } @@ -266,11 +266,12 @@ std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) bool NzFile::Rename(const NzString& newFilePath) { - NazaraLock(m_mutex) - bool opened = IsOpen(); + Close(); + NazaraLock(m_mutex) + bool success = Rename(m_filePath, newFilePath); if (success) m_filePath = NormalizePath(newFilePath); @@ -283,10 +284,10 @@ bool NzFile::Rename(const NzString& newFilePath) bool NzFile::Open(unsigned long openMode) { - NazaraLock(m_mutex) - Close(); + NazaraLock(m_mutex) + if (m_filePath.IsEmpty()) return false; @@ -314,8 +315,6 @@ bool NzFile::Open(unsigned long openMode) bool NzFile::Open(const NzString& filePath, unsigned long openMode) { - NazaraLock(m_mutex) - Close(); SetFile(filePath); @@ -361,10 +360,10 @@ void NzFile::SetEndianness(nzEndianness endianness) bool NzFile::SetFile(const NzString& filePath) { - NazaraLock(m_mutex) - if (IsOpen()) { + NazaraLock(m_mutex) + if (filePath.IsEmpty()) return false; @@ -446,8 +445,6 @@ bool NzFile::Write(const NzString& string) std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int count) { - NazaraLock(m_mutex) - #if NAZARA_CORE_SAFE if (!IsOpen()) { @@ -462,6 +459,8 @@ std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int } #endif + NazaraLock(m_mutex) + if (!buffer || count == 0 || typeSize == 0) return 0; diff --git a/src/Nazara/Core/MemoryManager.cpp b/src/Nazara/Core/MemoryManager.cpp index a91133234..739c75d82 100644 --- a/src/Nazara/Core/MemoryManager.cpp +++ b/src/Nazara/Core/MemoryManager.cpp @@ -209,6 +209,7 @@ void NzMemoryManager::Initialize() #ifdef NAZARA_PLATFORM_WINDOWS InitializeCriticalSection(&s_mutex); + //#elif defined(NAZARA_PLATFORM_POSIX) is already done in the namespace #endif s_initialized = true; @@ -224,6 +225,8 @@ void NzMemoryManager::Uninitialize() { #ifdef NAZARA_PLATFORM_WINDOWS DeleteCriticalSection(&s_mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_destroy(&s_mutex); #endif FILE* log = std::fopen(s_MLTFileName, "a"); diff --git a/src/Nazara/Core/Posix/ConditionVariableImpl.cpp b/src/Nazara/Core/Posix/ConditionVariableImpl.cpp index d75af776e..7a8ba8fc3 100644 --- a/src/Nazara/Core/Posix/ConditionVariableImpl.cpp +++ b/src/Nazara/Core/Posix/ConditionVariableImpl.cpp @@ -35,7 +35,7 @@ bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout) { // get the current time timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); // construct the time limit (current time + time to wait) timespec ti; diff --git a/src/Nazara/Core/Posix/DirectoryImpl.cpp b/src/Nazara/Core/Posix/DirectoryImpl.cpp index 50451edbe..9bd78e65f 100644 --- a/src/Nazara/Core/Posix/DirectoryImpl.cpp +++ b/src/Nazara/Core/Posix/DirectoryImpl.cpp @@ -82,14 +82,15 @@ bool NzDirectoryImpl::Exists(const NzString& dirPath) NzString NzDirectoryImpl::GetCurrent() { NzString currentPath; - char* path = new char[_PC_PATH_MAX]; + char* path = getcwd(nullptr, 0); - if (getcwd(path, _PC_PATH_MAX)) + if (path) + { currentPath = path; + free(path); + } else - NazaraError("Unable to get current directory: " + NzError::GetLastSystemError()); - - delete[] path; + NazaraError("Unable to get current directory: " + NzError::GetLastSystemError()); // Bug: initialisation -> if no path for log ! return currentPath; } diff --git a/src/Nazara/Core/Posix/MutexImpl.cpp b/src/Nazara/Core/Posix/MutexImpl.cpp index dee6078dc..0ed78092f 100644 --- a/src/Nazara/Core/Posix/MutexImpl.cpp +++ b/src/Nazara/Core/Posix/MutexImpl.cpp @@ -7,7 +7,7 @@ NzMutexImpl::NzMutexImpl() { - pthread_mutex_init(&m_handle, NULL); + pthread_mutex_init(&m_handle, nullptr); } NzMutexImpl::~NzMutexImpl() diff --git a/src/Nazara/Core/Posix/ThreadImpl.cpp b/src/Nazara/Core/Posix/ThreadImpl.cpp index c97abe19c..77099e3c0 100644 --- a/src/Nazara/Core/Posix/ThreadImpl.cpp +++ b/src/Nazara/Core/Posix/ThreadImpl.cpp @@ -57,9 +57,9 @@ void NzThreadImpl::Sleep(nzUInt32 time) // create a mutex and thread condition pthread_mutex_t mutex; - pthread_mutex_init(&mutex, 0); + pthread_mutex_init(&mutex, nullptr); pthread_cond_t condition; - pthread_cond_init(&condition, 0); + pthread_cond_init(&condition, nullptr); // wait... pthread_mutex_lock(&mutex); diff --git a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp index f0a605d4a..4e1439c2d 100644 --- a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp +++ b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp @@ -11,7 +11,7 @@ bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount) { - if (s_workerCount > 0) + if (IsInitialized()) return true; // Déjà initialisé #if NAZARA_CORE_SAFE