From 736e3447273f45af4f3bc1c47ecf47730e3bd6ce Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 6 Feb 2021 13:58:35 -0800 Subject: [PATCH] assert_is_locked to take std::mutex, not void * It's unclear why this had the void* cast. --- src/common.cpp | 8 +++----- src/common.h | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 2861a54d0..98e3852e5 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1820,16 +1820,14 @@ void assert_is_background_thread(const char *who) { } } -void assert_is_locked(void *vmutex, const char *who, const char *caller) { - auto mutex = static_cast(vmutex); - +void assert_is_locked(std::mutex &mutex, const char *who, const char *caller) { // Note that std::mutex.try_lock() is allowed to return false when the mutex isn't // actually locked; fortunately we are checking the opposite so we're safe. - if (mutex->try_lock()) { + if (mutex.try_lock()) { FLOGF(error, L"%s is not locked when it should be in '%s'", who, caller); FLOG(error, L"Break on debug_thread_error to debug."); debug_thread_error(); - mutex->unlock(); + mutex.unlock(); } } diff --git a/src/common.h b/src/common.h index 66a37b604..485512c5a 100644 --- a/src/common.h +++ b/src/common.h @@ -311,8 +311,8 @@ void assert_is_background_thread(const char *who); /// Useful macro for asserting that a lock is locked. This doesn't check whether this thread locked /// it, which it would be nice if it did, but here it is anyways. -void assert_is_locked(void *mutex, const char *who, const char *caller); -#define ASSERT_IS_LOCKED(x) assert_is_locked(reinterpret_cast(&x), #x, __FUNCTION__) +void assert_is_locked(std::mutex &mutex, const char *who, const char *caller); +#define ASSERT_IS_LOCKED(m) assert_is_locked(m, #m, __FUNCTION__) /// Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer. wcstring format_size(long long sz);