Ignore:
File:
1 edited

Legend:

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

    r5df7928 rdf4ed85  
    3333/**
    3434 * @file
    35  * @brief Semaphores.
     35 * @brief       Semaphores.
    3636 */
    3737
     
    4747 * Initialize semaphore.
    4848 *
    49  * @param sem Semaphore.
     49 * @param s Semaphore.
    5050 * @param val Maximal number of threads allowed to enter critical section.
    51  *
    5251 */
    53 void semaphore_initialize(semaphore_t *sem, int val)
     52void semaphore_initialize(semaphore_t *s, int val)
    5453{
    55         waitq_initialize(&sem->wq);
    56         waitq_count_set(&sem->wq, val);
     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);
    5765}
    5866
     
    6270 * Conditional mode and mode with timeout can be requested.
    6371 *
    64  * @param sem  Semaphore.
    65  * @param usec  Timeout in microseconds.
     72 * @param s Semaphore.
     73 * @param usec Timeout in microseconds.
    6674 * @param flags Select mode of operation.
    6775 *
     
    7078 *
    7179 * @return See comment for waitq_sleep_timeout().
    72  *
    7380 */
    74 int _semaphore_down_timeout(semaphore_t *sem, uint32_t usec, unsigned int flags)
     81int _semaphore_down_timeout(semaphore_t *s, uint32_t usec, int flags)
    7582{
    76         return waitq_sleep_timeout(&sem->wq, usec, flags);
     83        return waitq_sleep_timeout(&s->wq, usec, flags);
    7784}
    7885
     
    8289 *
    8390 * @param s Semaphore.
    84  *
    8591 */
    86 void semaphore_up(semaphore_t *sem)
     92void semaphore_up(semaphore_t *s)
    8793{
    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  */
    97 int semaphore_count_get(semaphore_t *sem)
    98 {
    99         return waitq_count_get(&sem->wq);
     94        waitq_wakeup(&s->wq, WAKEUP_FIRST);
    10095}
    10196
Note: See TracChangeset for help on using the changeset viewer.