You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by wk...@apache.org on 2022/09/30 18:36:07 UTC

[trafficserver] branch master updated: Change use of std::shared_mutex to ts::shared_mutex. (#9109)

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

wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new e14c0274f Change use of std::shared_mutex to ts::shared_mutex. (#9109)
e14c0274f is described below

commit e14c0274f0502810b2fae6f3f32ecf831124a055
Author: Walt Karas <wk...@verizonmedia.com>
AuthorDate: Fri Sep 30 13:35:59 2022 -0500

    Change use of std::shared_mutex to ts::shared_mutex. (#9109)
    
    Co-authored-by: Walt Karas <wk...@yahooinc.com>
---
 include/tscore/JeAllocator.h       |  1 -
 include/tscpp/util/TsSharedMutex.h | 30 ++++++++++++++++++------------
 iocore/hostdb/HostDB.cc            |  1 +
 iocore/hostdb/P_HostDBProcessor.h  |  5 +++--
 iocore/net/P_TLSKeyLogger.h        |  4 ++--
 iocore/net/SSLSessionCache.cc      |  5 +++--
 iocore/net/SSLSessionCache.h       | 10 +++++-----
 iocore/net/TLSKeyLogger.cc         |  1 +
 8 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/include/tscore/JeAllocator.h b/include/tscore/JeAllocator.h
index b67da12d0..6b3533031 100644
--- a/include/tscore/JeAllocator.h
+++ b/include/tscore/JeAllocator.h
@@ -25,7 +25,6 @@
 #include <cstddef>
 #include <unordered_map>
 #include <mutex>
-#include <shared_mutex>
 
 #if TS_HAS_JEMALLOC
 #include <jemalloc/jemalloc.h>
diff --git a/include/tscpp/util/TsSharedMutex.h b/include/tscpp/util/TsSharedMutex.h
index 92bd20f4f..fe1769a3c 100644
--- a/include/tscpp/util/TsSharedMutex.h
+++ b/include/tscpp/util/TsSharedMutex.h
@@ -27,13 +27,17 @@
 #include <pthread.h>
 #include <tscpp/util/Strerror.h>
 
-#if __has_include(<ts/ts.h>)
-#include <ts/ts.h>
-#else
-#include <tscore/Diags.h>
-#define TSFatal Fatal
+#if __has_include(<tscore/ink_assert.h>)
+// Included in core.
 #include <tscore/ink_assert.h>
-#define TSAssert ink_assert
+#define L_Assert ink_assert
+#include <tscore/Diags.h>
+#define L_Fatal Fatal
+#else
+// Should be plugin code.
+#include <ts/ts.h>
+#define L_Assert TSAssert
+#define L_Fatal TSFatal
 #endif
 
 #ifdef X
@@ -94,7 +98,7 @@ public:
   void
   unlock()
   {
-    X(TSAssert(_exclusive);)
+    X(L_Assert(_exclusive);)
     X(_exclusive = false;)
 
     _unlock();
@@ -107,9 +111,9 @@ public:
     if (error != 0) {
       _call_fatal("pthread_rwlock_rdlock", &_lock, error);
     }
-    X(TSAssert(_shared >= 0);)
+    X(L_Assert(_shared >= 0);)
     X(++_shared;)
-    X(TSAssert(_shared > 0);)
+    X(L_Assert(_shared > 0);)
   }
 
   bool
@@ -131,9 +135,9 @@ public:
   void
   unlock_shared()
   {
-    X(TSAssert(_shared > 0);)
+    X(L_Assert(_shared > 0);)
     X(--_shared;)
-    X(TSAssert(_shared >= 0);)
+    X(L_Assert(_shared >= 0);)
 
     _unlock();
   }
@@ -181,7 +185,7 @@ private:
   static void
   _call_fatal(char const *func_name, void *ptr, int errnum)
   {
-    TSFatal("%s(%p) failed: %s (%d)", func_name, ptr, Strerror(errnum).c_str(), errnum);
+    L_Fatal("%s(%p) failed: %s (%d)", func_name, ptr, Strerror(errnum).c_str(), errnum);
   }
 
   // In debug builds, make sure shared vs. exlusive locks and unlocks are properly paired.
@@ -193,3 +197,5 @@ private:
 } // end namespace ts
 
 #undef X
+#undef L_Assert
+#undef L_Fatal
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 79c55bff2..03c808511 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -36,6 +36,7 @@
 #include <algorithm>
 #include <random>
 #include <chrono>
+#include <shared_mutex>
 #include <http/HttpConfig.h>
 
 using ts::TextView;
diff --git a/iocore/hostdb/P_HostDBProcessor.h b/iocore/hostdb/P_HostDBProcessor.h
index 4549496cd..f110fbe26 100644
--- a/iocore/hostdb/P_HostDBProcessor.h
+++ b/iocore/hostdb/P_HostDBProcessor.h
@@ -27,9 +27,10 @@
 
 #pragma once
 
-#include <shared_mutex>
 #include <unordered_map>
 
+#include <tscpp/util/TsSharedMutex.h>
+
 #include "I_HostDBProcessor.h"
 #include "P_RefCountCache.h"
 #include "tscore/TsBuffer.h"
@@ -164,7 +165,7 @@ struct HostDBCache {
   int start(int flags = 0);
   // Map to contain all of the host file overrides, initialize it to empty
   std::shared_ptr<HostFile> host_file;
-  std::shared_mutex host_file_mutex;
+  ts::shared_mutex host_file_mutex;
 
   // TODO: make ATS call a close() method or something on shutdown (it does nothing of the sort today)
   RefCountCache<HostDBRecord> *refcountcache = nullptr;
diff --git a/iocore/net/P_TLSKeyLogger.h b/iocore/net/P_TLSKeyLogger.h
index 755506135..18fadbe87 100644
--- a/iocore/net/P_TLSKeyLogger.h
+++ b/iocore/net/P_TLSKeyLogger.h
@@ -28,7 +28,7 @@
 
 #include <memory>
 #include <mutex>
-#include <shared_mutex>
+#include <tscpp/util/TsSharedMutex.h>
 
 /** A class for handling TLS secrets logging. */
 class TLSKeyLogger
@@ -126,5 +126,5 @@ private:
 
   /** A mutex to coordinate dynamically changing TLS logging config changes and
    * logging to the TLS log file. */
-  std::shared_mutex _mutex;
+  ts::shared_mutex _mutex;
 };
diff --git a/iocore/net/SSLSessionCache.cc b/iocore/net/SSLSessionCache.cc
index 38c4d29d1..d62dba27b 100644
--- a/iocore/net/SSLSessionCache.cc
+++ b/iocore/net/SSLSessionCache.cc
@@ -25,6 +25,7 @@
 
 #include <cstring>
 #include <memory>
+#include <shared_mutex>
 
 #define SSLSESSIONCACHE_STRINGIFY0(x) #x
 #define SSLSESSIONCACHE_STRINGIFY(x) SSLSESSIONCACHE_STRINGIFY0(x)
@@ -274,7 +275,7 @@ void inline SSLSessionBucket::print(const char *ref_str) const
   }
 }
 
-void inline SSLSessionBucket::removeOldestSession(const std::unique_lock<std::shared_mutex> &lock)
+void inline SSLSessionBucket::removeOldestSession(const std::unique_lock<ts::shared_mutex> &lock)
 {
   // Caller must hold the bucket shared_mutex with unique_lock.
   ink_assert(lock.owns_lock());
@@ -398,7 +399,7 @@ SSLOriginSessionCache::get_session(const std::string &lookup_key, ssl_curve_id *
 }
 
 void
-SSLOriginSessionCache::remove_oldest_session(const std::unique_lock<std::shared_mutex> &lock)
+SSLOriginSessionCache::remove_oldest_session(const std::unique_lock<ts::shared_mutex> &lock)
 {
   // Caller must hold the bucket shared_mutex with unique_lock.
   ink_release_assert(lock.owns_lock());
diff --git a/iocore/net/SSLSessionCache.h b/iocore/net/SSLSessionCache.h
index 01edf7662..dddf23075 100644
--- a/iocore/net/SSLSessionCache.h
+++ b/iocore/net/SSLSessionCache.h
@@ -30,7 +30,7 @@
 #include "ts/apidefs.h"
 #include <openssl/ssl.h>
 #include <mutex>
-#include <shared_mutex>
+#include <tscpp/util/TsSharedMutex.h>
 
 #define SSL_MAX_SESSION_SIZE 256
 #define SSL_MAX_ORIG_SESSION_SIZE 4096
@@ -159,9 +159,9 @@ public:
 private:
   /* these method must be used while hold the lock */
   void print(const char *) const;
-  void removeOldestSession(const std::unique_lock<std::shared_mutex> &lock);
+  void removeOldestSession(const std::unique_lock<ts::shared_mutex> &lock);
 
-  mutable std::shared_mutex mutex;
+  mutable ts::shared_mutex mutex;
   CountQueue<SSLSession> bucket_que;
   std::map<SSLSessionID, SSLSession *> bucket_map;
 };
@@ -210,9 +210,9 @@ public:
   void remove_session(const std::string &lookup_key);
 
 private:
-  void remove_oldest_session(const std::unique_lock<std::shared_mutex> &lock);
+  void remove_oldest_session(const std::unique_lock<ts::shared_mutex> &lock);
 
-  mutable std::shared_mutex mutex;
+  mutable ts::shared_mutex mutex;
   CountQueue<SSLOriginSession> orig_sess_que;
   std::map<std::string, SSLOriginSession *> orig_sess_map;
 };
diff --git a/iocore/net/TLSKeyLogger.cc b/iocore/net/TLSKeyLogger.cc
index bdae514ec..587390206 100644
--- a/iocore/net/TLSKeyLogger.cc
+++ b/iocore/net/TLSKeyLogger.cc
@@ -23,6 +23,7 @@
 #include "tscore/Diags.h"
 
 #include <cstring>
+#include <shared_mutex>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/types.h>