diff --git a/src/Nazara/Core/Posix/ClockImpl.cpp b/src/Nazara/Core/Posix/ClockImpl.cpp index 3bd944b63..61590c159 100644 --- a/src/Nazara/Core/Posix/ClockImpl.cpp +++ b/src/Nazara/Core/Posix/ClockImpl.cpp @@ -17,12 +17,12 @@ nzUInt64 NzClockImplGetMicroseconds() { timeval clock; gettimeofday(&clock, nullptr); - return static_cast(clock.tv_sec*1000000 + (clock.tv_nsec/1000)); + return static_cast(clock.tv_sec*1000000 + clock.tv_usec); } nzUInt64 NzClockImplGetMilliseconds() { timeval clock; gettimeofday(&clock, nullptr); - return static_cast(clock.tv_sec*1000 + (clock.tv_nsec/1000000)); + return static_cast(clock.tv_sec*1000 + (clock.tv_usec/1000)); } diff --git a/src/Nazara/Core/Posix/ConditionVariableImpl.cpp b/src/Nazara/Core/Posix/ConditionVariableImpl.cpp index b5ae36333..2b4da8ff8 100644 --- a/src/Nazara/Core/Posix/ConditionVariableImpl.cpp +++ b/src/Nazara/Core/Posix/ConditionVariableImpl.cpp @@ -28,7 +28,7 @@ void NzConditionVariableImpl::SignalAll() void NzConditionVariableImpl::Wait(NzMutexImpl* mutex) { - pthread_cond_wait(&m_cv, mutex); + pthread_cond_wait(&m_cv, &mutex->m_handle); } bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout) diff --git a/src/Nazara/Core/Posix/DirectoryImpl.cpp b/src/Nazara/Core/Posix/DirectoryImpl.cpp index c4fc18d0c..bacf2e5b3 100644 --- a/src/Nazara/Core/Posix/DirectoryImpl.cpp +++ b/src/Nazara/Core/Posix/DirectoryImpl.cpp @@ -18,20 +18,24 @@ void NzDirectoryImpl::Close() NzString NzDirectoryImpl::GetResultName() const { - return m_result.d_name; + return m_result->d_name; } nzUInt64 NzDirectoryImpl::GetResultSize() const { struct stat64 resulststat; - stat64(m_result.d_name, &resulststat); + stat64(m_result->d_name, &resulststat); return static_cast(resulststat.st_size); } bool NzDirectoryImpl::IsResultDirectory() const { - return S_ISDIR(m_result.d_name); + struct stat64 filestats; + if (stat64(m_result->d_name, &filestats) == -1) // error + return false; + + return S_ISDIR(filestats.st_mode); } bool NzDirectoryImpl::NextResult() @@ -68,10 +72,11 @@ bool NzDirectoryImpl::Create(const NzString& dirPath) bool NzDirectoryImpl::Exists(const NzString& dirPath) { - if (S_ISDIR(dirPath.GetConstBuffer())) - return true; + struct stat64 filestats; + if (stat64(dirPath.GetConstBuffer(), &filestats) == -1) // error + return false; - return false; + return S_ISDIR(filestats.st_mode) || S_ISREG(filestats.st_mode); } NzString NzDirectoryImpl::GetCurrent() diff --git a/src/Nazara/Core/Posix/FileImpl.cpp b/src/Nazara/Core/Posix/FileImpl.cpp index 523c5b98e..22b6e3a38 100644 --- a/src/Nazara/Core/Posix/FileImpl.cpp +++ b/src/Nazara/Core/Posix/FileImpl.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -26,7 +25,7 @@ bool NzFileImpl::EndOfFile() const { if (!m_endOfFileUpdated) { - stat64 fileSize; + struct stat64 fileSize; if (fstat64(m_fileDescriptor, &fileSize) == -1) fileSize.st_size = 0; @@ -192,7 +191,7 @@ bool NzFileImpl::Delete(const NzString& filePath) bool NzFileImpl::Exists(const NzString& filePath) { - char* path = filePath.GetConstBuffer(); + const char* path = filePath.GetConstBuffer(); if (access(path, F_OK) != -1) return true; diff --git a/src/Nazara/Core/Posix/MutexImpl.cpp b/src/Nazara/Core/Posix/MutexImpl.cpp index a4844cd37..eb57e5783 100644 --- a/src/Nazara/Core/Posix/MutexImpl.cpp +++ b/src/Nazara/Core/Posix/MutexImpl.cpp @@ -12,20 +12,20 @@ NzMutexImpl::NzMutexImpl() NzMutexImpl::~NzMutexImpl() { - pthread_mutex_destroy(m_handle); + pthread_mutex_destroy(&m_handle); } void NzMutexImpl::Lock() { - pthread_mutex_lock(m_handle); + pthread_mutex_lock(&m_handle); } bool NzMutexImpl::TryLock() { - return pthread_mutex_trylock(m_handle) == 0; + return pthread_mutex_trylock(&m_handle) == 0; } void NzMutexImpl::Unlock() { - pthread_mutex_unlock(m_handle); + pthread_mutex_unlock(&m_handle); } diff --git a/src/Nazara/Core/Posix/SemaphoreImpl.cpp b/src/Nazara/Core/Posix/SemaphoreImpl.cpp index ad94b6218..51812579a 100644 --- a/src/Nazara/Core/Posix/SemaphoreImpl.cpp +++ b/src/Nazara/Core/Posix/SemaphoreImpl.cpp @@ -7,11 +7,11 @@ #include #include #include +#include NzSemaphoreImpl::NzSemaphoreImpl(unsigned int count) { - m_semaphore = sem_init(&m_semaphore, 0, count); - if (!m_semaphore) + if(sem_init(&m_semaphore, 0, count) != 0) NazaraError("Failed to create semaphore: " + NzGetLastSystemError()); } @@ -22,8 +22,8 @@ NzSemaphoreImpl::~NzSemaphoreImpl() unsigned int NzSemaphoreImpl::GetCount() const { - int count; - sem_getvalue(&m_semaphore, &count); + int count=0; + sem_getvalue(const_cast(&m_semaphore), &count); return static_cast(count); } @@ -49,13 +49,16 @@ void NzSemaphoreImpl::Wait() bool NzSemaphoreImpl::Wait(nzUInt32 timeout) { + timeval tv; + gettimeofday(&tv, nullptr); + timespec ti; ti.tv_nsec = (tv.tv_usec + (timeout % 1000)) * 1000000; ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000); ti.tv_nsec %= 1000000000; #if NAZARA_CORE_SAFE - if (sem_timedwait(m_semaphore, timeout) == -1) + if (sem_timedwait(&m_semaphore, &ti) != 0) { NazaraError("Failed to wait for semaphore: " + NzGetLastSystemError()); return false; @@ -63,6 +66,6 @@ bool NzSemaphoreImpl::Wait(nzUInt32 timeout) return true; #else - return sem_timedwait(&m_semaphore, ti) == 0 && errno != ETIMEDOUT; + return sem_timedwait(&m_semaphore, &ti) != 0; #endif } diff --git a/src/Nazara/Core/Posix/ThreadImpl.cpp b/src/Nazara/Core/Posix/ThreadImpl.cpp index fd0e0d2af..ddc6df1d3 100644 --- a/src/Nazara/Core/Posix/ThreadImpl.cpp +++ b/src/Nazara/Core/Posix/ThreadImpl.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -27,13 +26,13 @@ void NzThreadImpl::Join() pthread_join(m_handle, nullptr); } -unsigned int NzThreadImpl::ThreadProc(void* userdata) +void* NzThreadImpl::ThreadProc(void* userdata) { NzFunctor* func = static_cast(userdata); func->Run(); delete func; - return 0; + return nullptr; } void NzThreadImpl::Sleep(nzUInt32 time) @@ -48,7 +47,7 @@ void NzThreadImpl::Sleep(nzUInt32 time) // 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/ThreadImpl.hpp b/src/Nazara/Core/Posix/ThreadImpl.hpp index 2a57d021e..130c0f42d 100644 --- a/src/Nazara/Core/Posix/ThreadImpl.hpp +++ b/src/Nazara/Core/Posix/ThreadImpl.hpp @@ -23,7 +23,7 @@ class NzThreadImpl static void Sleep(nzUInt32 time); private: - static unsigned int ThreadProc(void* userdata); + static void* ThreadProc(void* userdata); pthread_t m_handle; };