diff options
Diffstat (limited to 'src/OSSupport')
-rw-r--r-- | src/OSSupport/CriticalSection.cpp | 10 | ||||
-rw-r--r-- | src/OSSupport/CriticalSection.h | 2 | ||||
-rw-r--r-- | src/OSSupport/Event.cpp | 6 | ||||
-rw-r--r-- | src/OSSupport/File.cpp | 7 | ||||
-rw-r--r-- | src/OSSupport/IsThread.cpp | 2 | ||||
-rw-r--r-- | src/OSSupport/Queue.h | 4 | ||||
-rw-r--r-- | src/OSSupport/Semaphore.cpp | 58 | ||||
-rw-r--r-- | src/OSSupport/Semaphore.h | 2 | ||||
-rw-r--r-- | src/OSSupport/Sleep.cpp | 4 | ||||
-rw-r--r-- | src/OSSupport/Socket.cpp | 4 | ||||
-rw-r--r-- | src/OSSupport/SocketThreads.cpp | 2 | ||||
-rw-r--r-- | src/OSSupport/Thread.cpp | 12 |
12 files changed, 66 insertions, 47 deletions
diff --git a/src/OSSupport/CriticalSection.cpp b/src/OSSupport/CriticalSection.cpp index bda97e3a1..5dfc8b5f9 100644 --- a/src/OSSupport/CriticalSection.cpp +++ b/src/OSSupport/CriticalSection.cpp @@ -6,7 +6,7 @@ -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cCriticalSection: cCriticalSection::cCriticalSection() @@ -105,10 +105,10 @@ bool cCriticalSection::IsLockedByCurrentThread(void) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cCSLock -cCSLock::cCSLock(cCriticalSection * a_CS) +cCSLock::cCSLock(cCriticalSection * a_CS) : m_CS(a_CS) , m_IsLocked(false) { @@ -119,7 +119,7 @@ cCSLock::cCSLock(cCriticalSection * a_CS) -cCSLock::cCSLock(cCriticalSection & a_CS) +cCSLock::cCSLock(cCriticalSection & a_CS) : m_CS(&a_CS) , m_IsLocked(false) { @@ -165,7 +165,7 @@ void cCSLock::Unlock(void) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cCSUnlock: cCSUnlock::cCSUnlock(cCSLock & a_Lock) : diff --git a/src/OSSupport/CriticalSection.h b/src/OSSupport/CriticalSection.h index 73a71f5e1..c3c6e57f0 100644 --- a/src/OSSupport/CriticalSection.h +++ b/src/OSSupport/CriticalSection.h @@ -47,7 +47,7 @@ class cCSLock cCriticalSection * m_CS; // Unlike a cCriticalSection, this object should be used from a single thread, therefore access to m_IsLocked is not threadsafe - // In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, + // In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, // therefore we need to check this value whether we are locked or not. bool m_IsLocked; diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp index 6b8fccde2..72bce4c3c 100644 --- a/src/OSSupport/Event.cpp +++ b/src/OSSupport/Event.cpp @@ -18,7 +18,7 @@ cEvent::cEvent(void) m_Event = CreateEvent(NULL, FALSE, FALSE, NULL); if (m_Event == NULL) { - LOGERROR("cEvent: cannot create event, GLE = %d. Aborting server.", GetLastError()); + LOGERROR("cEvent: cannot create event, GLE = %u. Aborting server.", (unsigned)GetLastError()); abort(); } #else // *nix @@ -86,7 +86,7 @@ void cEvent::Wait(void) DWORD res = WaitForSingleObject(m_Event, INFINITE); if (res != WAIT_OBJECT_0) { - LOGWARN("cEvent: waiting for the event failed: %d, GLE = %d. Continuing, but server may be unstable.", res, GetLastError()); + LOGWARN("cEvent: waiting for the event failed: %u, GLE = %u. Continuing, but server may be unstable.", (unsigned)res, (unsigned)GetLastError()); } #else int res = sem_wait(m_Event); @@ -107,7 +107,7 @@ void cEvent::Set(void) #ifdef _WIN32 if (!SetEvent(m_Event)) { - LOGWARN("cEvent: Could not set cEvent: GLE = %d", GetLastError()); + LOGWARN("cEvent: Could not set cEvent: GLE = %u", (unsigned)GetLastError()); } #else int res = sem_post(m_Event); diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 8c24fa541..ff6fb5898 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -7,6 +7,9 @@ #include "File.h" #include <fstream> +#ifdef _WIN32 + #include <share.h> // for _SH_DENYWRITE +#endif // _WIN32 @@ -78,7 +81,7 @@ bool cFile::Open(const AString & iFileName, eMode iMode) m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), Mode, _SH_DENYWR); #else m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), Mode); -#endif // _WIN32 +#endif // _WIN32 if ((m_File == NULL) && (iMode == fmReadWrite)) { @@ -91,7 +94,7 @@ bool cFile::Open(const AString & iFileName, eMode iMode) m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+", _SH_DENYWR); #else m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+"); -#endif // _WIN32 +#endif // _WIN32 } return (m_File != NULL); diff --git a/src/OSSupport/IsThread.cpp b/src/OSSupport/IsThread.cpp index 67f336c97..1a436623a 100644 --- a/src/OSSupport/IsThread.cpp +++ b/src/OSSupport/IsThread.cpp @@ -90,7 +90,7 @@ bool cIsThread::Start(void) m_Handle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &m_ThreadID); if (m_Handle == NULL) { - LOGERROR("ERROR: Could not create thread \"%s\", GLE = %d!", m_ThreadName.c_str(), GetLastError()); + LOGERROR("ERROR: Could not create thread \"%s\", GLE = %u!", m_ThreadName.c_str(), (unsigned)GetLastError()); return false; } ResumeThread(m_Handle); diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index beb6a63f1..269f9db41 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -21,7 +21,7 @@ cQueueFuncs and is used as the default behavior. /// This empty struct allows for the callback functions to be inlined template<class T> -struct cQueueFuncs +struct cQueueFuncs { public: @@ -88,7 +88,7 @@ public: cCSLock Lock(m_CS); if (m_Contents.size() == 0) { - return false; + return false; } item = m_Contents.front(); m_Contents.pop_front(); diff --git a/src/OSSupport/Semaphore.cpp b/src/OSSupport/Semaphore.cpp index 468de6858..d919c4744 100644 --- a/src/OSSupport/Semaphore.cpp +++ b/src/OSSupport/Semaphore.cpp @@ -36,56 +36,72 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* } #else m_Handle = CreateSemaphore( - NULL, // security attribute - a_InitialCount, // initial count - a_MaxCount, // maximum count - 0 // name (optional) + NULL, // security attribute + a_InitialCount, // initial count + a_MaxCount, // maximum count + 0 // name (optional) ); #endif } + + + + cSemaphore::~cSemaphore() { #ifdef _WIN32 CloseHandle( m_Handle ); #else - if( m_bNamed ) - { - if( sem_close( (sem_t*)m_Handle ) != 0 ) - { - LOG("ERROR: Could not close cSemaphore. (%i)", errno); - } - } - else - { - sem_destroy( (sem_t*)m_Handle ); - delete (sem_t*)m_Handle; - } + if( m_bNamed ) + { + if( sem_close( (sem_t*)m_Handle ) != 0 ) + { + LOG("ERROR: Could not close cSemaphore. (%i)", errno); + } + } + else + { + sem_destroy( (sem_t*)m_Handle ); + delete (sem_t*)m_Handle; + } m_Handle = 0; #endif } + + + + void cSemaphore::Wait() { #ifndef _WIN32 - if( sem_wait( (sem_t*)m_Handle ) != 0) - { - LOG("ERROR: Could not wait for cSemaphore. (%i)", errno); - } + if( sem_wait( (sem_t*)m_Handle ) != 0) + { + LOG("ERROR: Could not wait for cSemaphore. (%i)", errno); + } #else WaitForSingleObject( m_Handle, INFINITE); #endif } + + + + void cSemaphore::Signal() { #ifndef _WIN32 if( sem_post( (sem_t*)m_Handle ) != 0 ) { - LOG("ERROR: Could not signal cSemaphore. (%i)", errno); + LOG("ERROR: Could not signal cSemaphore. (%i)", errno); } #else ReleaseSemaphore( m_Handle, 1, NULL ); #endif } + + + + diff --git a/src/OSSupport/Semaphore.h b/src/OSSupport/Semaphore.h index fbe8907f1..ac574e8a1 100644 --- a/src/OSSupport/Semaphore.h +++ b/src/OSSupport/Semaphore.h @@ -9,7 +9,7 @@ public: void Wait(); void Signal(); private: - void* m_Handle; // HANDLE pointer + void* m_Handle; // HANDLE pointer #ifndef _WIN32 bool m_bNamed; diff --git a/src/OSSupport/Sleep.cpp b/src/OSSupport/Sleep.cpp index 70fb06b40..223a8b855 100644 --- a/src/OSSupport/Sleep.cpp +++ b/src/OSSupport/Sleep.cpp @@ -12,8 +12,8 @@ void cSleep::MilliSleep( unsigned int a_MilliSeconds ) { #ifdef _WIN32 - Sleep(a_MilliSeconds); // Don't tick too much + Sleep(a_MilliSeconds); // Don't tick too much #else - usleep(a_MilliSeconds*1000); + usleep(a_MilliSeconds*1000); #endif } diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 56835b518..7d4d9e598 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -244,7 +244,7 @@ cSocket cSocket::AcceptIPv6(void) // Windows XP doesn't have inet_ntop, so we need to improvise. And MSVC has different headers than GCC #ifdef _MSC_VER // MSVC version - Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", + Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", from.sin6_addr.u.Word[0], from.sin6_addr.u.Word[1], from.sin6_addr.u.Word[2], @@ -256,7 +256,7 @@ cSocket cSocket::AcceptIPv6(void) ); #else // _MSC_VER // MinGW - Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", + Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", from.sin6_addr.s6_addr16[0], from.sin6_addr.s6_addr16[1], from.sin6_addr.s6_addr16[2], diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index ca8b8438d..f436318a5 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -13,7 +13,7 @@ -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cSocketThreads: cSocketThreads::cSocketThreads(void) diff --git a/src/OSSupport/Thread.cpp b/src/OSSupport/Thread.cpp index 535784613..084e0810e 100644 --- a/src/OSSupport/Thread.cpp +++ b/src/OSSupport/Thread.cpp @@ -91,12 +91,12 @@ void cThread::Start( bool a_bWaitOnDelete /* = true */ ) LOGERROR("ERROR: Could not create thread!"); #else DWORD ThreadID = 0; - HANDLE hThread = CreateThread( 0 // security - ,0 // stack size - , (LPTHREAD_START_ROUTINE) MyThread // function name - ,this // parameters - ,0 // flags - ,&ThreadID ); // thread id + HANDLE hThread = CreateThread(NULL // security + ,0 // stack size + , (LPTHREAD_START_ROUTINE) MyThread // function name + ,this // parameters + ,0 // flags + ,&ThreadID ); // thread id CloseHandle( hThread ); #ifdef _MSC_VER |