sem_timedwait: fix errno, return value and NULL behaviour
* Takes into account remarks from Ingo. Signed-off-by: Jerome Duval <[email protected]> Signed-off-by: Ingo Weinhold <[email protected]>
This commit is contained in:
@@ -112,11 +112,25 @@ sem_post(sem_t* semaphore)
|
|||||||
int
|
int
|
||||||
sem_timedwait(sem_t* semaphore, const struct timespec* timeout)
|
sem_timedwait(sem_t* semaphore, const struct timespec* timeout)
|
||||||
{
|
{
|
||||||
bigtime_t timeoutMicros = ((bigtime_t)timeout->tv_sec) * 1000000
|
if (timeout != NULL && (timeout->tv_nsec < 0 ||
|
||||||
+ timeout->tv_nsec / 1000;
|
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(
|
bigtime_t timeoutMicros = B_INFINITE_TIMEOUT;
|
||||||
_kern_realtime_sem_wait(semaphore->id, timeoutMicros));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user