Ignore:
File:
1 edited

Legend:

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

    ra3900cc rd7da4284  
    3333/**
    3434 * @file
    35  * @brief       Mutexes.
     35 * @brief Mutexes.
    3636 */
    37  
     37
    3838#include <synch/mutex.h>
    3939#include <synch/semaphore.h>
     
    4444/** Initialize mutex.
    4545 *
    46  * @param mtx           Mutex.
    47  * @param type          Type of the mutex.
     46 * @param mtx  Mutex.
     47 * @param type Type of the mutex.
    4848 */
    4949void mutex_initialize(mutex_t *mtx, mutex_type_t type)
     
    5353}
    5454
     55/** Find out whether the mutex is currently locked.
     56 *
     57 * @param mtx           Mutex.
     58 * @return              True if the mutex is locked, false otherwise.
     59 */
     60bool mutex_locked(mutex_t *mtx)
     61{
     62        return semaphore_count_get(&mtx->sem) <= 0;
     63}
     64
    5565/** Acquire mutex.
    5666 *
    5767 * Timeout mode and non-blocking mode can be requested.
    5868 *
    59  * @param mtx           Mutex.
    60  * @param usec          Timeout in microseconds.
    61  * @param flags         Specify mode of operation.
     69 * @param mtx   Mutex.
     70 * @param usec  Timeout in microseconds.
     71 * @param flags Specify mode of operation.
    6272 *
    6373 * For exact description of possible combinations of
    6474 * usec and flags, see comment for waitq_sleep_timeout().
    6575 *
    66  * @return              See comment for waitq_sleep_timeout().
     76 * @return See comment for waitq_sleep_timeout().
     77 *
    6778 */
    68 int _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, int flags)
     79int _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, unsigned int flags)
    6980{
    7081        int rc;
    7182
    72         if (mtx->type == MUTEX_PASSIVE && THREAD) {
     83        if ((mtx->type == MUTEX_PASSIVE) && (THREAD)) {
    7384                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
    7485        } else {
    75                 ASSERT(mtx->type == MUTEX_ACTIVE || !THREAD);
     86                ASSERT((mtx->type == MUTEX_ACTIVE) || (!THREAD));
    7687                ASSERT(usec == SYNCH_NO_TIMEOUT);
    7788                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
     89               
    7890                do {
    7991                        rc = semaphore_trydown(&mtx->sem);
     
    8799/** Release mutex.
    88100 *
    89  * @param mtx           Mutex.
     101 * @param mtx Mutex.
    90102 */
    91103void mutex_unlock(mutex_t *mtx)
Note: See TracChangeset for help on using the changeset viewer.