trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [trafficserver] 02/02: Move mutex creation out of line.
Date Tue, 09 May 2017 16:51:51 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 2394fa8a56883d17dbba3cbf48fef545869ccfb4
Author: James Peach <jpeach@apache.org>
AuthorDate: Mon May 8 21:28:55 2017 -0700

    Move mutex creation out of line.
    
    Move the mutex create and destroy out of the header file so that
    we can use static mutex attributes without exposing another global
    variable.
---
 lib/ts/ink_mutex.cc | 39 +++++++++++++++++++++++++++++++++------
 lib/ts/ink_mutex.h  | 46 ++++------------------------------------------
 2 files changed, 37 insertions(+), 48 deletions(-)

diff --git a/lib/ts/ink_mutex.cc b/lib/ts/ink_mutex.cc
index 4d45f09..57a1a7f 100644
--- a/lib/ts/ink_mutex.cc
+++ b/lib/ts/ink_mutex.cc
@@ -29,19 +29,46 @@
 
 ink_mutex __global_death = PTHREAD_MUTEX_INITIALIZER;
 
-x_pthread_mutexattr_t::x_pthread_mutexattr_t()
+class x_pthread_mutexattr_t
 {
-  pthread_mutexattr_init(&attr);
+public:
+  x_pthread_mutexattr_t()
+  {
+    pthread_mutexattr_init(&attr);
 #ifndef POSIX_THREAD_10031c
-  pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+    pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
 #endif
 
 #if DEBUG && HAVE_PTHREAD_MUTEXATTR_SETTYPE
-  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
+    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
 #endif
+  }
+
+  ~x_pthread_mutexattr_t() { pthread_mutexattr_destroy(&attr); }
+
+  pthread_mutexattr_t attr;
+};
+
+static x_pthread_mutexattr_t attr;
+
+void
+ink_mutex_init(ink_mutex *m, const char * /* name */)
+{
+  int error;
+
+  error = pthread_mutex_init(m, &attr.attr);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_mutex_init(%p) failed: %s (%d)", m, strerror(error), error);
+  }
 }
 
-x_pthread_mutexattr_t::~x_pthread_mutexattr_t()
+void
+ink_mutex_destroy(ink_mutex *m)
 {
-  pthread_mutexattr_destroy(&attr);
+  int error;
+
+  error = pthread_mutex_destroy(m);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_mutex_destroy(%p) failed: %s (%d)", m, strerror(error), error);
+  }
 }
diff --git a/lib/ts/ink_mutex.h b/lib/ts/ink_mutex.h
index c25b7ae..5309676 100644
--- a/lib/ts/ink_mutex.h
+++ b/lib/ts/ink_mutex.h
@@ -32,57 +32,22 @@
 
 
 ***********************************************************************/
-#include <stdio.h>
 
 #include "ts/ink_defs.h"
 #include "ts/ink_error.h"
 
-#if defined(POSIX_THREAD)
 #include <pthread.h>
 #include <stdlib.h>
 
 typedef pthread_mutex_t ink_mutex;
 
-// just a wrapper so that the constructor gets executed
-// before the first call to ink_mutex_init();
-class x_pthread_mutexattr_t
-{
-public:
-  pthread_mutexattr_t attr;
-
-  x_pthread_mutexattr_t();
-  ~x_pthread_mutexattr_t();
-};
-
-static inline void
-ink_mutex_init(ink_mutex *m, const char * /* name */)
-{
-  int error;
-  x_pthread_mutexattr_t attr;
-
-  error = pthread_mutex_init(m, &attr.attr);
-  if (unlikely(error != 0)) {
-    ink_abort("pthread_mutex_init(%p) failed: %s (%d)", m, strerror(error), error);
-  }
-}
-
-static inline void
-ink_mutex_destroy(ink_mutex *m)
-{
-  int error;
-
-  error = pthread_mutex_destroy(m);
-  if (unlikely(error != 0)) {
-    ink_abort("pthread_mutex_destroy(%p) failed: %s (%d)", m, strerror(error), error);
-  }
-}
+void ink_mutex_init(ink_mutex *m, const char * /* name */);
+void ink_mutex_destroy(ink_mutex *m);
 
 static inline void
 ink_mutex_acquire(ink_mutex *m)
 {
-  int error;
-
-  error = pthread_mutex_lock(m);
+  int error = pthread_mutex_lock(m);
   if (unlikely(error != 0)) {
     ink_abort("pthread_mutex_lock(%p) failed: %s (%d)", m, strerror(error), error);
   }
@@ -91,9 +56,7 @@ ink_mutex_acquire(ink_mutex *m)
 static inline void
 ink_mutex_release(ink_mutex *m)
 {
-  int error;
-
-  error = pthread_mutex_unlock(m);
+  int error = pthread_mutex_unlock(m);
   if (unlikely(error != 0)) {
     ink_abort("pthread_mutex_unlock(%p) failed: %s (%d)", m, strerror(error), error);
   }
@@ -105,5 +68,4 @@ ink_mutex_try_acquire(ink_mutex *m)
   return pthread_mutex_trylock(m) == 0;
 }
 
-#endif /* #if defined(POSIX_THREAD) */
 #endif /* _ink_mutex_h_ */

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Mime
View raw message