* The rw_lock now behaves just like a recursive locker if KDEBUG_RW_LOCK_DEBUG
is defined to 1; this allows asserting the read lock case, too.
* Added ASSERT_{READ|WRITE}_LOCKED_RW_LOCK() macros. The read assertion is only
working when KDEBUG_RW_LOCK_DEBUG is defined to 1, the write assertion works
always.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26686 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -976,6 +976,8 @@
|
||||
|
||||
#define ASSERT_LOCKED_RECURSIVE(r) FSSH_ASSERT_LOCKED_RECURSIVE(r)
|
||||
#define ASSERT_LOCKED_MUTEX(m) FSSH_ASSERT_LOCKED_MUTEX(m)
|
||||
#define ASSERT_WRITE_LOCKED_RW_LOCK(l) FSSH_ASSERT_WRITE_LOCKED_RW_LOCK(l)
|
||||
#define ASSERT_READ_LOCKED_RW_LOCK(l) FSSH_ASSERT_READ_LOCKED_RW_LOCK(l)
|
||||
|
||||
#define MUTEX_INITIALIZER(name) FSSH_MUTEX_INITIALIZER(name)
|
||||
#define RECURSIVE_LOCK_INITIALIZER(name) FSSH_RECURSIVE_LOCK_INITIALIZER(name)
|
||||
|
||||
@@ -40,6 +40,8 @@ typedef struct fssh_rw_lock {
|
||||
|
||||
#define FSSH_ASSERT_LOCKED_RECURSIVE(r)
|
||||
#define FSSH_ASSERT_LOCKED_MUTEX(m)
|
||||
#define FSSH_ASSERT_WRITE_LOCKED_RW_LOCK(l)
|
||||
#define FSSH_ASSERT_READ_LOCKED_RW_LOCK(l)
|
||||
|
||||
// static initializers
|
||||
#define FSSH_MUTEX_INITIALIZER(name) { name, NULL, 0, 0 }
|
||||
|
||||
@@ -54,12 +54,25 @@ typedef struct rw_lock {
|
||||
|
||||
|
||||
#if KDEBUG
|
||||
# define KDEBUG_RW_LOCK_DEBUG 0
|
||||
// Define to 1 if you want to use ASSERT_READ_LOCKED_RW_LOCK().
|
||||
// The rw_lock will just behave like a recursive locker then.
|
||||
# define ASSERT_LOCKED_RECURSIVE(r) \
|
||||
{ ASSERT(find_thread(NULL) == (r)->lock.holder); }
|
||||
# define ASSERT_LOCKED_MUTEX(m) { ASSERT(find_thread(NULL) == (m)->holder); }
|
||||
# define ASSERT_WRITE_LOCKED_RW_LOCK(l) \
|
||||
{ ASSERT(find_thread(NULL) == (l)->holder); }
|
||||
# if KDEBUG_RW_LOCK_DEBUG
|
||||
# define ASSERT_READ_LOCKED_RW_LOCK(l) \
|
||||
{ ASSERT(find_thread(NULL) == (l)->holder); }
|
||||
# else
|
||||
# define ASSERT_READ_LOCKED_RW_LOCK(l) do {} while (false)
|
||||
# endif
|
||||
#else
|
||||
# define ASSERT_LOCKED_RECURSIVE(r) do {} while (false)
|
||||
# define ASSERT_LOCKED_MUTEX(m) do {} while (false)
|
||||
# define ASSERT_LOCKED_RECURSIVE(r) do {} while (false)
|
||||
# define ASSERT_LOCKED_MUTEX(m) do {} while (false)
|
||||
# define ASSERT_WRITE_LOCKED_RW_LOCK(m) do {} while (false)
|
||||
# define ASSERT_READ_LOCKED_RW_LOCK(l) do {} while (false)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -280,6 +280,9 @@ rw_lock_destroy(rw_lock* lock)
|
||||
status_t
|
||||
rw_lock_read_lock(rw_lock* lock)
|
||||
{
|
||||
#if KDEBUG_RW_LOCK_DEBUG
|
||||
return rw_lock_write_lock(lock);
|
||||
#else
|
||||
InterruptsSpinLocker locker(thread_spinlock);
|
||||
|
||||
if (lock->writer_count == 0) {
|
||||
@@ -292,12 +295,16 @@ rw_lock_read_lock(rw_lock* lock)
|
||||
}
|
||||
|
||||
return rw_lock_wait(lock, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
rw_lock_read_unlock(rw_lock* lock)
|
||||
{
|
||||
#if KDEBUG_RW_LOCK_DEBUG
|
||||
return rw_lock_write_unlock(lock);
|
||||
#else
|
||||
InterruptsSpinLocker locker(thread_spinlock);
|
||||
|
||||
if (lock->holder == thread_get_current_thread_id()) {
|
||||
@@ -321,6 +328,7 @@ rw_lock_read_unlock(rw_lock* lock)
|
||||
|
||||
rw_lock_unblock(lock);
|
||||
return B_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user