sem_wait() and sem_trywait() no longer modify the errno value UNLESS an error occurs. This allows these functions to be used internallly without clobbering the errno value.
This commit is contained in:
parent
ac1bb127b6
commit
484a1b6104
|
@ -84,13 +84,9 @@ int sem_trywait(FAR sem_t *sem)
|
|||
|
||||
/* This API should not be called from interrupt handlers */
|
||||
|
||||
DEBUGASSERT(up_interrupt_context() == false);
|
||||
DEBUGASSERT(sem != NULL && up_interrupt_context() == false);
|
||||
|
||||
/* Assume any errors reported are due to invalid arguments. */
|
||||
|
||||
set_errno(EINVAL);
|
||||
|
||||
if (sem)
|
||||
if (sem != NULL)
|
||||
{
|
||||
/* The following operations must be performed with interrupts disabled
|
||||
* because sem_post() may be called from an interrupt handler.
|
||||
|
@ -98,12 +94,6 @@ int sem_trywait(FAR sem_t *sem)
|
|||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Any further errors could only occurr because the semaphore is not
|
||||
* available.
|
||||
*/
|
||||
|
||||
set_errno(EAGAIN);
|
||||
|
||||
/* If the semaphore is available, give it to the requesting task */
|
||||
|
||||
if (sem->semcount > 0)
|
||||
|
@ -114,11 +104,21 @@ int sem_trywait(FAR sem_t *sem)
|
|||
rtcb->waitsem = NULL;
|
||||
ret = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Semaphore is not available */
|
||||
|
||||
set_errno(EAGAIN);
|
||||
}
|
||||
|
||||
/* Interrupts may now be enabled. */
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
set_errno(EINVAL);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -84,11 +84,11 @@ int sem_wait(FAR sem_t *sem)
|
|||
|
||||
/* This API should not be called from interrupt handlers */
|
||||
|
||||
DEBUGASSERT(up_interrupt_context() == false);
|
||||
DEBUGASSERT(sem != NULL && up_interrupt_context() == false);
|
||||
|
||||
/* Make sure we were supplied with a valid semaphore. */
|
||||
|
||||
if (sem)
|
||||
if (sem != NULL)
|
||||
{
|
||||
/* The following operations must be performed with interrupts
|
||||
* disabled because sem_post() may be called from an interrupt
|
||||
|
|
Loading…
Reference in New Issue