diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/api_wrappers/linux/CEventObject.cpp | 32 | ||||
-rw-r--r-- | source/api_wrappers/linux/CEventObject.h | 4 | ||||
-rw-r--r-- | source/api_wrappers/linux/CSemaphore.cpp | 30 | ||||
-rw-r--r-- | source/api_wrappers/linux/CSemaphore.h | 5 | ||||
-rw-r--r-- | source/api_wrappers/linux/CSemaphoreQueue.cpp | 4 | ||||
-rw-r--r-- | source/api_wrappers/linux/Types.h | 2 | ||||
-rw-r--r-- | source/api_wrappers/linux/sdf | 0 |
7 files changed, 77 insertions, 0 deletions
diff --git a/source/api_wrappers/linux/CEventObject.cpp b/source/api_wrappers/linux/CEventObject.cpp index 1a09fa9..eecbe6d 100644 --- a/source/api_wrappers/linux/CEventObject.cpp +++ b/source/api_wrappers/linux/CEventObject.cpp @@ -18,6 +18,7 @@ // ****************************************************************************** CEventObject::CEventObject() { +#if defined(__APPLE__) char sem_name[SEM_NAME_MAX_LENGTH]; int sem_nr = 1; @@ -33,6 +34,9 @@ CEventObject::CEventObject() sem_nr++; } +#elif defined(__linux__) + sem_init(&m_sem, 0, 0); +#endif } // ****************************************************************************** @@ -42,7 +46,11 @@ CEventObject::CEventObject() // ****************************************************************************** CEventObject::~CEventObject() { +#if defined(__APPLE__) sem_close(m_sem); +#elif defined(__linux__) + sem_destroy(&m_sem); +#endif } // ****************************************************************************** @@ -52,7 +60,11 @@ CEventObject::~CEventObject() // ****************************************************************************** void CEventObject::SetEvent() { +#if defined(__APPLE__) sem_post(m_sem); +#elif defined(__linux__) + sem_post(&m_sem); +#endif } // ****************************************************************************** @@ -62,6 +74,7 @@ void CEventObject::SetEvent() // ****************************************************************************** DWORD CEventObject::Wait(DWORD dwTimeout) { +#if defined(__APPLE__) if (INFINITE == dwTimeout) { sem_wait(m_sem); } else { @@ -97,4 +110,23 @@ DWORD CEventObject::Wait(DWORD dwTimeout) } return WAIT_OBJECT_0; + +#elif defined(__linux__) + if (INFINITE == dwTimeout) { + sem_wait(&m_sem); + return WAIT_OBJECT_0; + } else { + timespec absolute_time = OS::GetAbsoluteTime(dwTimeout); + int ret; + + /* coverity[returned_null] */ + while (-1 == (ret = sem_timedwait(&m_sem, &absolute_time)) && errno == EINTR); + + if (0 == ret) { + return WAIT_OBJECT_0; + } else { + return WAIT_TIMEOUT; + } + } +#endif } diff --git a/source/api_wrappers/linux/CEventObject.h b/source/api_wrappers/linux/CEventObject.h index 987b33e..ec7d126 100644 --- a/source/api_wrappers/linux/CEventObject.h +++ b/source/api_wrappers/linux/CEventObject.h @@ -33,7 +33,11 @@ public: void UnsetEvent(); DWORD Wait(DWORD dwTimeout = INFINITE); private: +#if defined(__APPLE__) sem_t *m_sem; +#elif defined(__linux__) + sem_t m_sem; +#endif }; #endif /* _CEVENTOBJECT_H */ diff --git a/source/api_wrappers/linux/CSemaphore.cpp b/source/api_wrappers/linux/CSemaphore.cpp index 166ab88..b7e4224 100644 --- a/source/api_wrappers/linux/CSemaphore.cpp +++ b/source/api_wrappers/linux/CSemaphore.cpp @@ -14,6 +14,7 @@ CSemaphore::CSemaphore(unsigned int initial_count) { +#if defined(__APPLE__) char sem_name[SEM_NAME_MAX_LENGTH]; int sem_nr = 1; @@ -29,11 +30,18 @@ CSemaphore::CSemaphore(unsigned int initial_count) sem_nr++; } +#elif defined(__linux__) + sem_init(&m_semaphore, 0, initial_count); +#endif } CSemaphore::~CSemaphore() { +#if defined(__APPLE__) sem_close(m_semaphore); +#elif defined(__linux__) + sem_destroy(&m_semaphore); +#endif } bool CSemaphore::Release(unsigned int count) @@ -43,7 +51,11 @@ bool CSemaphore::Release(unsigned int count) } for (unsigned int i = 0; i < count; ++i) { +#if defined(__APPLE__) if (sem_post(m_semaphore)) { +#elif defined(__linux__) + if (sem_post(&m_semaphore)) { +#endif return false; } } @@ -53,6 +65,7 @@ bool CSemaphore::Release(unsigned int count) DWORD CSemaphore::Wait(DWORD timeout) { +#if defined(__APPLE__) if (INFINITE == timeout) { sem_wait(m_semaphore); } else { @@ -88,4 +101,21 @@ DWORD CSemaphore::Wait(DWORD timeout) } return WAIT_OBJECT_0; +#elif defined(__linux__) + if (INFINITE == timeout) { + sem_wait(&m_semaphore); + } else { + timespec absoulute_time = OS::GetAbsoluteTime(timeout); + int ret; + + /* coverity[returned_null] */ + while (-1 == (ret = sem_timedwait(&m_semaphore, &absoulute_time)) && errno == EINTR); + + if (0 != ret) { + return WAIT_TIMEOUT; + } + } + + return WAIT_OBJECT_0; +#endif } diff --git a/source/api_wrappers/linux/CSemaphore.h b/source/api_wrappers/linux/CSemaphore.h index 3d68b63..32d8ca2 100644 --- a/source/api_wrappers/linux/CSemaphore.h +++ b/source/api_wrappers/linux/CSemaphore.h @@ -19,7 +19,12 @@ public: DWORD Wait(DWORD timeout = INFINITE); private: +#if defined(__APPLE__) sem_t *m_semaphore; +#elif defined(__linux__) + sem_t m_semaphore; +#endif + }; #endif /* _CSEMAPHORE_H */ diff --git a/source/api_wrappers/linux/CSemaphoreQueue.cpp b/source/api_wrappers/linux/CSemaphoreQueue.cpp index 448b4ee..55871ca 100644 --- a/source/api_wrappers/linux/CSemaphoreQueue.cpp +++ b/source/api_wrappers/linux/CSemaphoreQueue.cpp @@ -13,7 +13,11 @@ CSemaphoreQueue::CSemaphoreQueue(unsigned int MaxCount) : m_MaximumCount(MaxCount) { m_pEventObject = new CEventObject(); +#if defined(__APPLE__) m_pSemaphore = new CSemaphore(0); +#elif defined(__linux__) + m_pSemaphore = new CSemaphore(); +#endif m_ObjectCollection.Add(m_pEventObject); m_ObjectCollection.Add(m_pSemaphore); diff --git a/source/api_wrappers/linux/Types.h b/source/api_wrappers/linux/Types.h index 4f720aa..6008996 100644 --- a/source/api_wrappers/linux/Types.h +++ b/source/api_wrappers/linux/Types.h @@ -17,8 +17,10 @@ typedef unsigned int DWORD; #define WINAPI +#if defined(__APPLE__) #define SEM_NAME_MAX_LENGTH 16 #define SEM_MAX_NR 1000 +#endif #endif /* _TYPES_H */ diff --git a/source/api_wrappers/linux/sdf b/source/api_wrappers/linux/sdf deleted file mode 100644 index e69de29..0000000 --- a/source/api_wrappers/linux/sdf +++ /dev/null |