diff options
Diffstat (limited to 'source/api_wrappers')
-rw-r--r-- | source/api_wrappers/linux/CEventObject.cpp | 11 | ||||
-rw-r--r-- | source/api_wrappers/linux/CSemaphore.cpp | 10 | ||||
-rw-r--r-- | source/api_wrappers/linux/CSemaphore.h | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/source/api_wrappers/linux/CEventObject.cpp b/source/api_wrappers/linux/CEventObject.cpp index 6c0f6c3..1a09fa9 100644 --- a/source/api_wrappers/linux/CEventObject.cpp +++ b/source/api_wrappers/linux/CEventObject.cpp @@ -20,13 +20,17 @@ CEventObject::CEventObject() { char sem_name[SEM_NAME_MAX_LENGTH]; int sem_nr = 1; - while(sem_nr <= SEM_MAX_NR) { + + while (sem_nr <= SEM_MAX_NR) { snprintf(sem_name, SEM_NAME_MAX_LENGTH, "lcdriversem_%d", sem_nr); /* open semaphore with "rw" permissions for everyone - 0666 */ m_sem = sem_open(sem_name, O_CREAT | O_EXCL, 0666 , 0); - if (m_sem != SEM_FAILED) + + if (m_sem != SEM_FAILED) { break; + } + sem_nr++; } } @@ -69,6 +73,7 @@ DWORD CEventObject::Wait(DWORD dwTimeout) /* Try to lock the semaphore */ ret = sem_trywait(m_sem); + if (ret != 0) { while (dwTimePassed < dwTimeout) { /* Sleep 1ms */ @@ -76,6 +81,7 @@ DWORD CEventObject::Wait(DWORD dwTimeout) /* Try to lock the semaphore again*/ ret = sem_trywait(m_sem); + if (ret == 0) { return WAIT_OBJECT_0; } @@ -85,6 +91,7 @@ DWORD CEventObject::Wait(DWORD dwTimeout) dwTimePassed = 1000 * (curr_time.tv_sec - start_time.tv_sec) + \ (curr_time.tv_usec - start_time.tv_usec) / 1000; } + return WAIT_TIMEOUT; } } diff --git a/source/api_wrappers/linux/CSemaphore.cpp b/source/api_wrappers/linux/CSemaphore.cpp index 5dae856..166ab88 100644 --- a/source/api_wrappers/linux/CSemaphore.cpp +++ b/source/api_wrappers/linux/CSemaphore.cpp @@ -16,13 +16,17 @@ CSemaphore::CSemaphore(unsigned int initial_count) { char sem_name[SEM_NAME_MAX_LENGTH]; int sem_nr = 1; - while(sem_nr <= SEM_MAX_NR) { + + while (sem_nr <= SEM_MAX_NR) { snprintf(sem_name, SEM_NAME_MAX_LENGTH, "lcdriversem_%d", sem_nr); /* open semaphore with "rw" permissions for everyone - 0666 */ m_semaphore = sem_open(sem_name, O_CREAT | O_EXCL, 0666 , 0); - if (m_semaphore != SEM_FAILED) + + if (m_semaphore != SEM_FAILED) { break; + } + sem_nr++; } } @@ -60,6 +64,7 @@ DWORD CSemaphore::Wait(DWORD timeout) /* Try to lock the semaphore */ ret = sem_trywait(m_semaphore); + if (ret != 0) { while (dwTimePassed < timeout) { /* Sleep 1ms */ @@ -67,6 +72,7 @@ DWORD CSemaphore::Wait(DWORD timeout) /* Try to lock the semaphore again*/ ret = sem_trywait(m_semaphore); + if (ret == 0) { return WAIT_OBJECT_0; } diff --git a/source/api_wrappers/linux/CSemaphore.h b/source/api_wrappers/linux/CSemaphore.h index 0abe5dd..3d68b63 100644 --- a/source/api_wrappers/linux/CSemaphore.h +++ b/source/api_wrappers/linux/CSemaphore.h @@ -19,7 +19,7 @@ public: DWORD Wait(DWORD timeout = INFINITE); private: - sem_t* m_semaphore; + sem_t *m_semaphore; }; #endif /* _CSEMAPHORE_H */ |