hrev44996 adds 1 changeset to branch 'master' old head: 154b1dd2bf42a534b7099bcc9e2f47cd71199576 new head: 3cdae65125db9d867f328391d69970197e4b9556 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=3cdae65+%5E154b1dd ---------------------------------------------------------------------------- 3cdae65: sem_timedwait: fix errno, return value and NULL behaviour * Takes into account remarks from Ingo. Signed-off-by: Jerome Duval <jerome.duval@xxxxxxxxx> Signed-off-by: Ingo Weinhold <ingo_weinhold@xxxxxx> [ Sam Toyer <sam@xxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev44996 Commit: 3cdae65125db9d867f328391d69970197e4b9556 URL: http://cgit.haiku-os.org/haiku/commit/?id=3cdae65 Author: Sam Toyer <sam@xxxxxxxx> Date: Thu Nov 29 22:57:10 2012 UTC Committer: Jerome Duval <jerome.duval@xxxxxxxxx> Commit-Date: Tue Dec 11 18:23:17 2012 UTC ---------------------------------------------------------------------------- 1 file changed, 18 insertions(+), 4 deletions(-) src/system/libroot/posix/semaphore.cpp | 22 ++++++++++++++++++---- ---------------------------------------------------------------------------- diff --git a/src/system/libroot/posix/semaphore.cpp b/src/system/libroot/posix/semaphore.cpp index b96b835..fb57ced 100644 --- a/src/system/libroot/posix/semaphore.cpp +++ b/src/system/libroot/posix/semaphore.cpp @@ -112,11 +112,25 @@ sem_post(sem_t* semaphore) int sem_timedwait(sem_t* semaphore, const struct timespec* timeout) { - bigtime_t timeoutMicros = ((bigtime_t)timeout->tv_sec) * 1000000 - + timeout->tv_nsec / 1000; + if (timeout != NULL && (timeout->tv_nsec < 0 || + timeout->tv_nsec >= 1000000000)) { + status_t err = _kern_realtime_sem_wait(semaphore->id, 0); + if (err == B_WOULD_BLOCK) + err = EINVAL; + // do nothing, return err as it is. + RETURN_AND_SET_ERRNO_TEST_CANCEL(err); + } - RETURN_AND_SET_ERRNO_TEST_CANCEL( - _kern_realtime_sem_wait(semaphore->id, timeoutMicros)); + bigtime_t timeoutMicros = B_INFINITE_TIMEOUT; + if (timeout != NULL) { + timeoutMicros = ((bigtime_t)timeout->tv_sec) * 1000000 + + timeout->tv_nsec / 1000; + } + status_t err = _kern_realtime_sem_wait(semaphore->id, timeoutMicros); + if (err == B_WOULD_BLOCK) + err = ETIMEDOUT; + + RETURN_AND_SET_ERRNO_TEST_CANCEL(err); }