assert_is_locked to take std::mutex, not void *

It's unclear why this had the void* cast.
This commit is contained in:
ridiculousfish 2021-02-06 13:58:35 -08:00
parent 98b0ef532f
commit 736e344727
2 changed files with 5 additions and 7 deletions

View file

@ -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<std::mutex *>(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();
}
}

View file

@ -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<void *>(&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);