diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-01-10 22:07:05 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-01-10 22:07:05 +0100 |
commit | 0c6b402b4add4ef20a6ba48d412b38faa0c8caba (patch) | |
tree | 6416007de1f05103aa59821e70c3480ae164dbd9 /src | |
parent | 621292bd02b667d74b532a898b1737b3e0dfe263 (diff) |
Check for EINT in semaphore wait.
Diffstat (limited to 'src')
-rw-r--r-- | src/semaphore.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/semaphore.cc b/src/semaphore.cc index a7c8e74..fdc33f1 100644 --- a/src/semaphore.cc +++ b/src/semaphore.cc @@ -168,6 +168,20 @@ void Semaphore::wait() #elif DG_PLATFORM == DG_PLATFORM_OSX MPWaitOnSemaphore(prv->semaphore, kDurationForever); #else - sem_wait(&prv->semaphore); +again: + int ret = sem_wait(&prv->semaphore); + if(ret < 0) + { + if(errno == EINTR) + { + // The wait were interrupted prematurely so we need to wait again + // To prevent an infinite loop-like behaviour we make a short sleep. + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + goto again; + } + + perror("sem_wait()"); + assert(false); + } #endif } |