Changeset 08a19ba in mainline


Ignore:
Timestamp:
2008-06-23T18:44:48Z (16 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
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/mm/as_ht.c

    rdeaf8d5 r08a19ba  
    7373        if (flags & FLAG_AS_KERNEL) {
    7474                hash_table_create(&page_ht, PAGE_HT_ENTRIES, 2, &ht_operations);
    75                 mutex_initialize(&page_ht_lock);
     75                mutex_initialize(&page_ht_lock, MUTEX_PASSIVE);
    7676        }
    7777        return NULL;
  • kernel/generic/include/synch/mutex.h

    rdeaf8d5 r08a19ba  
    4040#include <synch/synch.h>
    4141
     42typedef enum {
     43        MUTEX_PASSIVE,
     44        MUTEX_ACTIVE
     45} mutex_type_t;
     46
    4247typedef struct {
     48        mutex_type_t type;
    4349        semaphore_t sem;
    4450} mutex_t;
    4551
    46 #define mutex_lock(mtx) \
     52#define mutex_lock(mtx)                 \
    4753        _mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    48 #define mutex_trylock(mtx) \
     54#define mutex_trylock(mtx)              \
    4955        _mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
    50 #define mutex_lock_timeout(mtx, usec) \
     56#define mutex_lock_timeout(mtx, usec)   \
    5157        _mutex_lock_timeout((mtx), (usec), SYNCH_FLAGS_NON_BLOCKING)
    5258
    53 extern void mutex_initialize(mutex_t *mtx);
    54 extern int _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, int flags);
    55 extern void mutex_unlock(mutex_t *mtx);
     59extern void mutex_initialize(mutex_t *, mutex_type_t);
     60extern int _mutex_lock_timeout(mutex_t *, uint32_t, int);
     61extern void mutex_unlock(mutex_t *);
    5662
    5763#endif
  • kernel/generic/src/ipc/ipc.c

    rdeaf8d5 r08a19ba  
    162162void ipc_phone_init(phone_t *phone)
    163163{
    164         mutex_initialize(&phone->lock);
     164        mutex_initialize(&phone->lock, MUTEX_PASSIVE);
    165165        phone->callee = NULL;
    166166        phone->state = IPC_PHONE_FREE;
  • kernel/generic/src/mm/as.c

    rdeaf8d5 r08a19ba  
    127127
    128128        link_initialize(&as->inactive_as_with_asid_link);
    129         mutex_initialize(&as->lock);   
     129        mutex_initialize(&as->lock, MUTEX_PASSIVE);     
    130130       
    131131        rc = as_constructor_arch(as, flags);
     
    169169        as = [as_t new];
    170170        link_initialize(&as->inactive_as_with_asid_link);
    171         mutex_initialize(&as->lock);   
     171        mutex_initialize(&as->lock, MUTEX_PASSIVE);     
    172172        (void) as_constructor_arch(as, flags);
    173173#else
     
    313313        a = (as_area_t *) malloc(sizeof(as_area_t), 0);
    314314
    315         mutex_initialize(&a->lock);
     315        mutex_initialize(&a->lock, MUTEX_PASSIVE);
    316316       
    317317        a->as = as;
     
    695695        if (!sh_info) {
    696696                sh_info = (share_info_t *) malloc(sizeof(share_info_t), 0);
    697                 mutex_initialize(&sh_info->lock);
     697                mutex_initialize(&sh_info->lock, MUTEX_PASSIVE);
    698698                sh_info->refcount = 2;
    699699                btree_create(&sh_info->pagemap);
  • kernel/generic/src/proc/task.c

    rdeaf8d5 r08a19ba  
    181181        atomic_set(&ta->active_calls, 0);
    182182
    183         mutex_initialize(&ta->futexes_lock);
     183        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
    184184        btree_create(&ta->futexes);
    185185       
  • 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}
  • kernel/test/mm/slab2.c

    rdeaf8d5 r08a19ba  
    217217       
    218218        condvar_initialize(&thread_starter);
    219         mutex_initialize(&starter_mutex);
     219        mutex_initialize(&starter_mutex, MUTEX_PASSIVE);
    220220
    221221        thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
Note: See TracChangeset for help on using the changeset viewer.