zyfeier commented on code in PR #14465: URL: https://github.com/apache/nuttx/pull/14465#discussion_r1812531878
########## sched/semaphore/sem_post.c: ########## @@ -217,3 +214,60 @@ int nxsem_post(FAR sem_t *sem) return OK; } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxsem_post + * + * Description: + * When a kernel thread has finished with a semaphore, it will call + * nxsem_post(). This function unlocks the semaphore referenced by sem + * by performing the semaphore unlock operation on that semaphore. + * + * If the semaphore value resulting from this operation is positive, then + * no tasks were blocked waiting for the semaphore to become unlocked; the + * semaphore is simply incremented. + * + * If the value of the semaphore resulting from this operation is zero, + * then one of the tasks blocked waiting for the semaphore shall be + * allowed to return successfully from its call to nxsem_wait(). + * + * 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. + * + * Assumptions: + * This function may be called from an interrupt handler. + * + ****************************************************************************/ + +int nxsem_post(FAR sem_t *sem) +{ + DEBUGASSERT(sem != NULL); + + /* If this is a mutex, we can try to unlock the mutex in fast mode, + * else try to get it in slow mode. + */ + +#if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) + if (sem->flags & SEM_TYPE_MUTEX) Review Comment: If the atomic operation for count is implemented in the lib mutex, when mutex_lock is called, it may exit early due to fast_lock, which can result in the sem->count value not being updated. This, in turn, can cause mutex_unlock to fail. -- 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