Ignore:
File:
1 edited

Legend:

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

    rdf4ed85 r5df7928  
    3333/**
    3434 * @file
    35  * @brief       Semaphores.
     35 * @brief Semaphores.
    3636 */
    3737
     
    4747 * Initialize semaphore.
    4848 *
    49  * @param s Semaphore.
     49 * @param sem Semaphore.
    5050 * @param val Maximal number of threads allowed to enter critical section.
     51 *
    5152 */
    52 void semaphore_initialize(semaphore_t *s, int val)
     53void semaphore_initialize(semaphore_t *sem, int val)
    5354{
    54         ipl_t ipl;
    55        
    56         waitq_initialize(&s->wq);
    57        
    58         ipl = interrupts_disable();
    59 
    60         spinlock_lock(&s->wq.lock);
    61         s->wq.missed_wakeups = val;
    62         spinlock_unlock(&s->wq.lock);
    63 
    64         interrupts_restore(ipl);
     55        waitq_initialize(&sem->wq);
     56        waitq_count_set(&sem->wq, val);
    6557}
    6658
     
    7062 * Conditional mode and mode with timeout can be requested.
    7163 *
    72  * @param s Semaphore.
    73  * @param usec Timeout in microseconds.
     64 * @param sem  Semaphore.
     65 * @param usec  Timeout in microseconds.
    7466 * @param flags Select mode of operation.
    7567 *
     
    7870 *
    7971 * @return See comment for waitq_sleep_timeout().
     72 *
    8073 */
    81 int _semaphore_down_timeout(semaphore_t *s, uint32_t usec, int flags)
     74int _semaphore_down_timeout(semaphore_t *sem, uint32_t usec, unsigned int flags)
    8275{
    83         return waitq_sleep_timeout(&s->wq, usec, flags);
     76        return waitq_sleep_timeout(&sem->wq, usec, flags);
    8477}
    8578
     
    8982 *
    9083 * @param s Semaphore.
     84 *
    9185 */
    92 void semaphore_up(semaphore_t *s)
     86void semaphore_up(semaphore_t *sem)
    9387{
    94         waitq_wakeup(&s->wq, WAKEUP_FIRST);
     88        waitq_wakeup(&sem->wq, WAKEUP_FIRST);
     89}
     90
     91/** Get the semaphore counter value.
     92 *
     93 * @param sem           Semaphore.
     94 * @return              The number of threads that can down the semaphore
     95 *                      without blocking.
     96 */
     97int semaphore_count_get(semaphore_t *sem)
     98{
     99        return waitq_count_get(&sem->wq);
    95100}
    96101
Note: See TracChangeset for help on using the changeset viewer.