src/ssx/ssx/ssx_semaphore_core.c
/// Post a count to a semaphore
///
/// \param semaphore A pointer to the semaphore
///
/// If any thread is pending on the semaphore, the highest priority thread
/// will be made runnable and the internal count will remain 0.
///
/// If no thread is pending on the semaphore then the internal count will be
/// incremented by 1, with overflow wrapping the internal count through 0. If
/// the \a max_count argument supplied when the semaphore was created is
/// non-zero and the new internal count is greater than the \a max_count, an
/// overflow error will be signalled.
///
/// Return values other than SSX_OK (0) are errors; see \ref ssx_errors
///
/// \retval 0 Successful completion
///
/// \retval -SSX_ILLEGAL_CONTEXT The API was called from a critical interrupt
/// context.
///
/// \retval -SSX_INVALID_SEMAPHORE_AT_POST The \a semaphore is a null (0) pointer.
///
/// \retval -SSX_SEMAPHORE_OVERFLOW The \a max_count argument supplied when
/// the semaphore was created is non-zero and the new internal count is
/// greater than the \a max_count.
Post a count to a semaphore
\param semaphore A pointer to the semaphore

If any thread is pending on the semaphore, the highest priority thread
will be made runnable and the internal count will remain 0.

If no thread is pending on the semaphore then the internal count will be
incremented by 1, with overflow wrapping the internal count through 0. If
the \a max_count argument supplied when the semaphore was created is
non-zero and the new internal count is greater than the \a max_count, an
overflow error will be signalled.

Return values other than SSX_OK (0) are errors; see \ref ssx_errors

\retval 0 Successful completion

\retval -SSX_ILLEGAL_CONTEXT The API was called from a critical interrupt
context.

\retval -SSX_INVALID_SEMAPHORE_AT_POST The \a semaphore is a null (0) pointer.

\retval -SSX_SEMAPHORE_OVERFLOW The \a max_count argument supplied when
the semaphore was created is non-zero and the new internal count is
greater than the \a max_count.
Post a count to a semaphore \ param semaphore A pointer to the semaphore If any thread is pending on the semaphore the highest priority thread will be made runnable and the internal count will remain 0 . If no thread is pending on the semaphore then the internal count will be incremented by 1 with overflow wrapping the internal count through 0 . If the \ a max_count argument supplied when the semaphore was created is non - zero and the new internal count is greater than the \ a max_count an overflow error will be signalled . Return values other than SSX_OK ( 0 ) are errors ; see \ ref ssx_errors \ retval 0 Successful completion \ retval - SSX_ILLEGAL_CONTEXT The API was called from a critical interrupt context . \ retval - SSX_INVALID_SEMAPHORE_AT_POST The \ a semaphore is a null ( 0 ) pointer . \ retval - SSX_SEMAPHORE_OVERFLOW The \ a max_count argument supplied when the semaphore was created is non - zero and the new internal count is greater than the \ a max_count .
int
ssx_semaphore_post(SsxSemaphore* semaphore)
{
    SsxMachineContext ctx;
    SsxThreadPriority priority;
    if (SSX_ERROR_CHECK_API)
    {
        SSX_ERROR_IF_CRITICAL_INTERRUPT_CONTEXT();
        SSX_ERROR_IF(semaphore == 0, SSX_INVALID_SEMAPHORE_AT_POST);
    }
    ssx_critical_section_enter(SSX_NONCRITICAL, &ctx);
    priority = __ssx_thread_queue_min(&(semaphore->pending_threads));
    if (priority != SSX_IDLE_THREAD_PRIORITY)
    {
        __ssx_thread_queue_delete(&(semaphore->pending_threads), priority);
        __ssx_thread_queue_insert(&__ssx_run_queue, priority);
        SSX_KERN_TRACE("THREAD_SEMAPHORE_POST(%d)", priority);
        __ssx_schedule();
    }
    else
    {
        semaphore->count++;
        if (SSX_ERROR_CHECK_API)
        {
            SSX_ERROR_IF((semaphore->max_count > 0) &&
                         (semaphore->count > semaphore->max_count),
                         SSX_SEMAPHORE_OVERFLOW);
        }
    }
    ssx_critical_section_exit(&ctx);
    return SSX_OK;
}
int ssx_semaphore_post ( SsxSemaphore * semaphore ) { SsxMachineContext ctx ; SsxThreadPriority priority ; if ( SSX_ERROR_CHECK_API ) { SSX_ERROR_IF_CRITICAL_INTERRUPT_CONTEXT ( ) ; SSX_ERROR_IF ( semaphore == 0 , SSX_INVALID_SEMAPHORE_AT_POST ) ; } ssx_critical_section_enter ( SSX_NONCRITICAL , & ctx ) ; priority = __ssx_thread_queue_min ( & ( semaphore -> pending_threads ) ) ; if ( priority != SSX_IDLE_THREAD_PRIORITY ) { __ssx_thread_queue_delete ( & ( semaphore -> pending_threads ) , priority ) ; __ssx_thread_queue_insert ( & __ssx_run_queue , priority ) ; SSX_KERN_TRACE ( " " , priority ) ; __ssx_schedule ( ) ; } else { semaphore -> count ++ ; if ( SSX_ERROR_CHECK_API ) { SSX_ERROR_IF ( ( semaphore -> max_count > 0 ) && ( semaphore -> count > semaphore -> max_count ) , SSX_SEMAPHORE_OVERFLOW ) ; } } ssx_critical_section_exit ( & ctx ) ; return SSX_OK ; }
Post a count to a semaphore
\param semaphore A pointer to the semaphore
Post a count to a semaphore \ param semaphore A pointer to the semaphore