You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2022/08/23 15:06:46 UTC

[trafficserver] branch 9.2.x updated: ts::shared_mutex - Fix lock counting for debug (#9040)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new 45d2b8c03 ts::shared_mutex - Fix lock counting for debug (#9040)
45d2b8c03 is described below

commit 45d2b8c03e2abe4494c1d3828becad1bc6065533
Author: Mo Chen <un...@gmail.com>
AuthorDate: Tue Aug 16 19:18:13 2022 -0500

    ts::shared_mutex - Fix lock counting for debug (#9040)
    
    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.
    
    (cherry picked from commit 2e31ef8a5a0a4327a17084c2ae51c0325d1feb61)
---
 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 3ac7f2ea9..530026238 100644
--- a/include/tscpp/util/TsSharedMutex.h
+++ b/include/tscpp/util/TsSharedMutex.h
@@ -150,7 +150,9 @@ public:
     if (error != 0) {
       _call_fatal("pthread_rwlock_rdlock", &_lock, error);
     }
+    X(TSAssert(_shared >= 0);)
     X(++_shared;)
+    X(TSAssert(_shared > 0);)
   }
 
   bool
@@ -227,8 +229,8 @@ private:
 
   // In debug builds, make sure shared vs. exlusive locks and unlocks are properly paired.
   //
-  X(std::atomic<bool> _exclusive;)
-  X(std::atomic<int> _shared;)
+  X(std::atomic<bool> _exclusive{false};)
+  X(std::atomic<int> _shared{0};)
 };
 
 } // end namespace ts