diff --git a/headers/private/fs_shell/fssh_api_wrapper.h b/headers/private/fs_shell/fssh_api_wrapper.h index 46d591ea65..3124739b7a 100644 --- a/headers/private/fs_shell/fssh_api_wrapper.h +++ b/headers/private/fs_shell/fssh_api_wrapper.h @@ -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) diff --git a/headers/private/fs_shell/fssh_lock.h b/headers/private/fs_shell/fssh_lock.h index 0c587aa198..8be96a183a 100644 --- a/headers/private/fs_shell/fssh_lock.h +++ b/headers/private/fs_shell/fssh_lock.h @@ -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 } diff --git a/headers/private/kernel/lock.h b/headers/private/kernel/lock.h index d08c7f0cea..0785d30151 100644 --- a/headers/private/kernel/lock.h +++ b/headers/private/kernel/lock.h @@ -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 diff --git a/src/system/kernel/lock.cpp b/src/system/kernel/lock.cpp index 559ba3386a..31cf2e37d9 100644 --- a/src/system/kernel/lock.cpp +++ b/src/system/kernel/lock.cpp @@ -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 }