From b87ba5f12f879b4b0908544f2928494dc6650cf6 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Tue, 16 Aug 2022 16:55:04 -0500 Subject: [PATCH] ts::shared_mutex - Fix lock counting for debug Lock count variable was left uninitialized, causing assertions to fail. This change initializes the debug data so they work properly. Also add a similar check to the locking side. --- include/tscpp/util/TsSharedMutex.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/tscpp/util/TsSharedMutex.h b/include/tscpp/util/TsSharedMutex.h index df0fd2c23ee..92bd20f4ffa 100644 --- a/include/tscpp/util/TsSharedMutex.h +++ b/include/tscpp/util/TsSharedMutex.h @@ -107,7 +107,9 @@ class shared_mutex if (error != 0) { _call_fatal("pthread_rwlock_rdlock", &_lock, error); } + X(TSAssert(_shared >= 0);) X(++_shared;) + X(TSAssert(_shared > 0);) } bool @@ -184,8 +186,8 @@ class shared_mutex // In debug builds, make sure shared vs. exlusive locks and unlocks are properly paired. // - X(std::atomic _exclusive;) - X(std::atomic _shared;) + X(std::atomic _exclusive{false};) + X(std::atomic _shared{0};) }; } // end namespace ts