Changeset 08a19ba in mainline for kernel/generic/src/synch


Ignore:
Timestamp:
2008-06-23T18:44:48Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a1744e
Parents:
deaf8d5
Message:

Support for active mutexes. Active mutexes implement busy waiting, pretty much
in the same way as spinlocks, but can be passed to condition variables, which is
the motivation for this enhancement.

Location:
kernel/generic/src/synch
Files:
3 edited

Legend:

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

    rdeaf8d5 r08a19ba  
    4444/** Initialize condition variable.
    4545 *
    46  * @param cv Condition variable.
     46 * @param cv            Condition variable.
    4747 */
    4848void condvar_initialize(condvar_t *cv)
     
    5151}
    5252
    53 /**
    54  * Signal the condition has become true
    55  * to the first waiting thread by waking it up.
     53/** Signal the condition has become true to the first waiting thread by waking
     54 * it up.
    5655 *
    57  * @param cv Condition variable.
     56 * @param cv            Condition variable.
    5857 */
    5958void condvar_signal(condvar_t *cv)
     
    6261}
    6362
    64 /**
    65  * Signal the condition has become true
    66  * to all waiting threads by waking them up.
     63/** Signal the condition has become true to all waiting threads by waking
     64 * them up.
    6765 *
    68  * @param cv Condition variable.
     66 * @param cv            Condition variable.
    6967 */
    7068void condvar_broadcast(condvar_t *cv)
     
    7573/** Wait for the condition becoming true.
    7674 *
    77  * @param cv Condition variable.
    78  * @param mtx Mutex.
    79  * @param usec Timeout value in microseconds.
    80  * @param flags Select mode of operation.
     75 * @param cv            Condition variable.
     76 * @param mtx           Mutex.
     77 * @param usec          Timeout value in microseconds.
     78 * @param flags         Select mode of operation.
    8179 *
    82  * For exact description of meaning of possible combinations
    83  * of usec and flags, see comment for waitq_sleep_timeout().
    84  * Note that when SYNCH_FLAGS_NON_BLOCKING is specified here,
    85  * ESYNCH_WOULD_BLOCK is always returned.
     80 * For exact description of meaning of possible combinations of usec and flags,
     81 * see comment for waitq_sleep_timeout().  Note that when
     82 * SYNCH_FLAGS_NON_BLOCKING is specified here, ESYNCH_WOULD_BLOCK is always
     83 * returned.
    8684 *
    87  * @return See comment for waitq_sleep_timeout().
     85 * @return              See comment for waitq_sleep_timeout().
    8886 */
    8987int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags)
  • kernel/generic/src/synch/mutex.c

    rdeaf8d5 r08a19ba  
    3939#include <synch/semaphore.h>
    4040#include <synch/synch.h>
     41#include <debug.h>
    4142
    42 /** Initialize mutex
     43/** Initialize mutex.
    4344 *
    44  * Initialize mutex.
    45  *
    46  * @param mtx Mutex.
     45 * @param mtx           Mutex.
     46 * @param type          Type of the mutex.
    4747 */
    48 void mutex_initialize(mutex_t *mtx)
     48void mutex_initialize(mutex_t *mtx, mutex_type_t type)
    4949{
     50        mtx->type = type;
    5051        semaphore_initialize(&mtx->sem, 1);
    5152}
    5253
    53 /** Acquire mutex
     54/** Acquire mutex.
    5455 *
    55  * Acquire mutex.
    5656 * Timeout mode and non-blocking mode can be requested.
    5757 *
    58  * @param mtx Mutex.
    59  * @param usec Timeout in microseconds.
    60  * @param flags Specify mode of operation.
     58 * @param mtx           Mutex.
     59 * @param usec          Timeout in microseconds.
     60 * @param flags         Specify mode of operation.
    6161 *
    6262 * For exact description of possible combinations of
    6363 * usec and flags, see comment for waitq_sleep_timeout().
    6464 *
    65  * @return See comment for waitq_sleep_timeout().
     65 * @return              See comment for waitq_sleep_timeout().
    6666 */
    6767int _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, int flags)
    6868{
    69         return _semaphore_down_timeout(&mtx->sem, usec, flags);
     69        int rc;
     70
     71        if (mtx->type == MUTEX_PASSIVE) {
     72                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
     73        } else {
     74                ASSERT(mtx->type == MUTEX_ACTIVE);
     75                ASSERT(usec == SYNCH_NO_TIMEOUT);
     76                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
     77                do {
     78                        rc = semaphore_trydown(&mtx->sem);
     79                } while (SYNCH_FAILED(rc) &&
     80                    !(flags & SYNCH_FLAGS_NON_BLOCKING));
     81        }
     82
     83        return rc;
    7084}
    7185
    72 /** Release mutex
     86/** Release mutex.
    7387 *
    74  * Release mutex.
    75  *
    76  * @param mtx Mutex.
     88 * @param mtx           Mutex.
    7789 */
    7890void mutex_unlock(mutex_t *mtx)
  • kernel/generic/src/synch/rwlock.c

    rdeaf8d5 r08a19ba  
    8383void rwlock_initialize(rwlock_t *rwl) {
    8484        spinlock_initialize(&rwl->lock, "rwlock_t");
    85         mutex_initialize(&rwl->exclusive);
     85        mutex_initialize(&rwl->exclusive, MUTEX_PASSIVE);
    8686        rwl->readers_in = 0;
    8787}
Note: See TracChangeset for help on using the changeset viewer.