Changeset 26257

Show
Ignore:
Timestamp:
07/04/08 20:17:00 (5 months ago)
Author:
bonefish
Message:

* Reenabled ASSERT_LOCKED_{MUTEX,RECURSIVE}() macros.
* Added mutex_switch_lock(), which unlocks one lock and locks another

one in an atomic manner (similar to switch_sem()).

Location:
haiku/branches/developer/bonefish/vm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • haiku/branches/developer/bonefish/vm/headers/private/kernel/lock.h

    r25691 r26257  
    5353 
    5454 
    55 #if 0 && KDEBUG // XXX disable this for now, it causes problems when including thread.h here 
    56 #       include <thread.h> 
    57 #define ASSERT_LOCKED_RECURSIVE(r) { ASSERT(thread_get_current_thread_id() == (r)->holder); } 
    58 #define ASSERT_LOCKED_MUTEX(m) { ASSERT(thread_get_current_thread_id() == (m)->holder); } 
     55#if KDEBUG 
     56#       define ASSERT_LOCKED_RECURSIVE(r) \ 
     57                { ASSERT(find_thread(NULL) == (r)->lock.holder); } 
     58#       define ASSERT_LOCKED_MUTEX(m) { ASSERT(find_thread(NULL) == (m)->holder); } 
    5959#else 
    60 #define ASSERT_LOCKED_RECURSIVE(r) 
    61 #define ASSERT_LOCKED_MUTEX(m) 
     60#       define ASSERT_LOCKED_RECURSIVE(r)       do {} while (false) 
     61#       define ASSERT_LOCKED_MUTEX(m)           do {} while (false) 
    6262#endif 
    6363 
     
    101101extern void mutex_init_etc(mutex* lock, const char* name, uint32 flags); 
    102102extern void mutex_destroy(mutex* lock); 
     103extern status_t mutex_switch_lock(mutex* from, mutex* to); 
     104        // Unlocks "from" and locks "to" such that unlocking and starting to wait 
     105        // for the lock is atomically. I.e. if "from" guards the object "to" belongs 
     106        // to, the operation is safe as long as "from" is held while destroying 
     107        // "to". 
    103108 
    104109// implementation private: 
    105110extern status_t _mutex_lock(mutex* lock, bool threadsLocked); 
    106 extern void _mutex_unlock(mutex* lock); 
     111extern void _mutex_unlock(mutex* lock, bool threadsLocked); 
    107112extern status_t _mutex_trylock(mutex* lock); 
    108113 
     
    150155mutex_unlock(mutex* lock) 
    151156{ 
    152 #ifdef KDEBUG 
    153         _mutex_unlock(lock); 
    154 #else 
     157#if !defined(KDEBUG) 
    155158        if (atomic_add(&lock->count, 1) < -1) 
    156                 _mutex_unlock(lock); 
    157159#endif 
     160                _mutex_unlock(lock, false); 
    158161} 
    159162 
  • haiku/branches/developer/bonefish/vm/src/system/kernel/lock.cpp

    r25812 r26257  
    382382 
    383383        free(name); 
     384} 
     385 
     386 
     387status_t 
     388mutex_switch_lock(mutex* from, mutex* to) 
     389{ 
     390        InterruptsSpinLocker locker(thread_spinlock); 
     391 
     392#if !defined(KDEBUG) 
     393        if (atomic_add(&from->count, 1) < -1) 
     394#endif 
     395                _mutex_unlock(from, true); 
     396 
     397        return mutex_lock_threads_locked(to); 
    384398} 
    385399 
     
    442456 
    443457void 
    444 _mutex_unlock(mutex* lock) 
    445 { 
    446         InterruptsSpinLocker _(thread_spinlock); 
     458_mutex_unlock(mutex* lock, bool threadsLocked) 
     459{ 
     460        // lock only, if !threadsLocked 
     461        InterruptsSpinLocker locker(thread_spinlock, false, !threadsLocked); 
    447462 
    448463#ifdef KDEBUG