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/02/17 00:11:38 UTC

[trafficserver] branch 9.2.x updated: Make TsSharedMutex.h compile on MacOS. (#8645)

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 ea42cae  Make TsSharedMutex.h compile on MacOS. (#8645)
ea42cae is described below

commit ea42caedc4fab1f3a39f086f8455e7fe31de73c5
Author: Walt Karas <wk...@verizonmedia.com>
AuthorDate: Fri Feb 4 12:22:45 2022 -0600

    Make TsSharedMutex.h compile on MacOS. (#8645)
    
    (cherry picked from commit bfd5265fd21b45c5fff0affdf8a3b88330d8181a)
---
 include/tscpp/util/TsSharedMutex.h | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/tscpp/util/TsSharedMutex.h b/include/tscpp/util/TsSharedMutex.h
index fa00fc6..3ac7f2e 100644
--- a/include/tscpp/util/TsSharedMutex.h
+++ b/include/tscpp/util/TsSharedMutex.h
@@ -59,12 +59,19 @@ class Strerror
 public:
   Strerror(int err_num)
   {
-    _c_str = strerror_r(err_num, _buf, 256);
-    if (!_c_str) {
+    // Handle either GNU or XSI version of strerror_r().
+    //
+    if (!_success(strerror_r(err_num, _buf, 256))) {
       _c_str = "strerror_r() call failed";
     } else {
       _buf[255] = '\0';
+      _c_str    = _buf;
     }
+
+    // Make sure there are no unused function warnings.
+    //
+    static_cast<void>(_success(0));
+    static_cast<void>(_success(nullptr));
   }
 
   char const *
@@ -76,6 +83,18 @@ public:
 private:
   char _buf[256];
   char const *_c_str;
+
+  bool
+  _success(int retval)
+  {
+    return retval == 0;
+  }
+
+  bool
+  _success(char *retval)
+  {
+    return retval != nullptr;
+  }
 };
 
 // A class with the same interface as std::shared_mutex, but which is not prone to writer starvation.
@@ -200,7 +219,7 @@ private:
 #endif
 #endif
 
-  void
+  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);