Ignore:
File:
1 edited

Legend:

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

    r08a19ba rd7da4284  
    3333/**
    3434 * @file
    35  * @brief       Mutexes.
     35 * @brief Mutexes.
    3636 */
    37  
     37
    3838#include <synch/mutex.h>
    3939#include <synch/semaphore.h>
    4040#include <synch/synch.h>
    4141#include <debug.h>
     42#include <arch.h>
    4243
    4344/** Initialize mutex.
    4445 *
    45  * @param mtx           Mutex.
    46  * @param type          Type of the mutex.
     46 * @param mtx  Mutex.
     47 * @param type Type of the mutex.
    4748 */
    4849void mutex_initialize(mutex_t *mtx, mutex_type_t type)
     
    5253}
    5354
     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
    5465/** Acquire mutex.
    5566 *
    5667 * Timeout mode and non-blocking mode can be requested.
    5768 *
    58  * @param mtx           Mutex.
    59  * @param usec          Timeout in microseconds.
    60  * @param flags         Specify mode of operation.
     69 * @param mtx   Mutex.
     70 * @param usec  Timeout in microseconds.
     71 * @param flags Specify mode of operation.
    6172 *
    6273 * For exact description of possible combinations of
    6374 * usec and flags, see comment for waitq_sleep_timeout().
    6475 *
    65  * @return              See comment for waitq_sleep_timeout().
     76 * @return See comment for waitq_sleep_timeout().
     77 *
    6678 */
    67 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)
    6880{
    6981        int rc;
    7082
    71         if (mtx->type == MUTEX_PASSIVE) {
     83        if ((mtx->type == MUTEX_PASSIVE) && (THREAD)) {
    7284                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
    7385        } else {
    74                 ASSERT(mtx->type == MUTEX_ACTIVE);
     86                ASSERT((mtx->type == MUTEX_ACTIVE) || (!THREAD));
    7587                ASSERT(usec == SYNCH_NO_TIMEOUT);
    7688                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
     89               
    7790                do {
    7891                        rc = semaphore_trydown(&mtx->sem);
     
    8699/** Release mutex.
    87100 *
    88  * @param mtx           Mutex.
     101 * @param mtx Mutex.
    89102 */
    90103void mutex_unlock(mutex_t *mtx)
Note: See TracChangeset for help on using the changeset viewer.