Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/semaphore.c

    re88eb48 r111b9b9  
    5252void semaphore_initialize(semaphore_t *sem, int val)
    5353{
    54         waitq_initialize(&sem->wq);
    55         waitq_count_set(&sem->wq, val);
     54        waitq_initialize_with_count(&sem->wq, val);
    5655}
    5756
    58 /** Semaphore down
    59  *
    60  * Semaphore down.
    61  * Conditional mode and mode with timeout can be requested.
     57errno_t semaphore_trydown(semaphore_t *sem)
     58{
     59        return semaphore_down_timeout(sem, 0);
     60}
     61
     62/** Semaphore down with timeout
    6263 *
    6364 * @param sem   Semaphore.
    6465 * @param usec  Timeout in microseconds.
    65  * @param flags Select mode of operation.
    66  *
    67  * For exact description of possible combinations of
    68  * usec and flags, see comment for waitq_sleep_timeout().
    6966 *
    7067 * @return See comment for waitq_sleep_timeout().
    7168 *
    7269 */
    73 errno_t _semaphore_down_timeout(semaphore_t *sem, uint32_t usec, unsigned int flags)
     70errno_t semaphore_down_timeout(semaphore_t *sem, uint32_t usec)
    7471{
    75         return waitq_sleep_timeout(&sem->wq, usec, flags, NULL);
     72        errno_t rc = waitq_sleep_timeout(&sem->wq, usec);
     73        assert(rc == EOK || rc == ETIMEOUT || rc == EAGAIN);
     74        return rc;
     75}
     76
     77void semaphore_down(semaphore_t *sem)
     78{
     79        errno_t rc = waitq_sleep(&sem->wq);
     80        assert(rc == EOK);
    7681}
    7782
     
    8590void semaphore_up(semaphore_t *sem)
    8691{
    87         waitq_wakeup(&sem->wq, WAKEUP_FIRST);
    88 }
    89 
    90 /** Get the semaphore counter value.
    91  *
    92  * @param sem           Semaphore.
    93  * @return              The number of threads that can down the semaphore
    94  *                      without blocking.
    95  */
    96 int semaphore_count_get(semaphore_t *sem)
    97 {
    98         return waitq_count_get(&sem->wq);
     92        waitq_wake_one(&sem->wq);
    9993}
    10094
Note: See TracChangeset for help on using the changeset viewer.