pussuw commented on code in PR #14465: URL: https://github.com/apache/nuttx/pull/14465#discussion_r1812585535
########## sched/semaphore/sem_wait.c: ########## @@ -224,6 +213,65 @@ int nxsem_wait(FAR sem_t *sem) return ret; } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxsem_wait + * + * Description: + * This function attempts to lock the semaphore referenced by 'sem'. If + * the semaphore value is (<=) zero, then the calling task will not return + * until it successfully acquires the lock. + * + * This is an internal OS interface. It is functionally equivalent to + * sem_wait except that: + * + * - It is not a cancellation point, and + * - It does not modify the errno value. + * + * Input Parameters: + * sem - Semaphore descriptor. + * + * Returned Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + * - EINVAL: Invalid attempt to get the semaphore + * - EINTR: The wait was interrupted by the receipt of a signal. + * + ****************************************************************************/ + +int nxsem_wait(FAR sem_t *sem) +{ + /* This API should not be called from interrupt handlers & idleloop */ + + DEBUGASSERT(sem != NULL && up_interrupt_context() == false); + DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask()); + + /* If this is a mutex, we can try to get the mutex in fast mode, + * else try to get it in slow mode. + */ + +#if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) Review Comment: For semaphores this is true, as semaphores can have multiple holders, but for mutexes you can set PID atomically without locking / critical section, as mutexes will only have 1 holder. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org