osaf/libs/core/cplusplus/base/process.cc     |  31 ++++++++++++++++-----------
 osaf/libs/core/cplusplus/base/process.h      |  19 +++++++++--------
 osaf/libs/core/cplusplus/base/unix_socket.cc |  17 +-------------
 osaf/libs/core/cplusplus/base/unix_socket.h  |   3 +-
 4 files changed, 32 insertions(+), 38 deletions(-)


Use the new Mutex and Lock classes instead of std::mutex, std::unique_lock and
pthread_mutex_t.

diff --git a/osaf/libs/core/cplusplus/base/process.cc 
b/osaf/libs/core/cplusplus/base/process.cc
--- a/osaf/libs/core/cplusplus/base/process.cc
+++ b/osaf/libs/core/cplusplus/base/process.cc
@@ -50,10 +50,12 @@ Process::~Process() {
 }
 
 void Process::Kill(int sig_no, const Duration& wait_time) {
-  std::unique_lock<std::mutex> lock(mutex_);
-  pid_t pgid = process_group_id_;
-  process_group_id_ = 0;
-  lock.unlock();
+  pid_t pgid;
+  {
+    Lock lock(mutex_);
+    pgid = process_group_id_;
+    process_group_id_ = 0;
+  }
   if (pgid > 1) KillProc(-pgid, sig_no, wait_time);
 }
 
@@ -119,20 +121,23 @@ void Process::Execute(int argc, char *ar
       LOG_WA("setpgid(%u, 0) failed: %s",
              (unsigned) child_pid, strerror(errno));
     }
-    std::unique_lock<std::mutex> lock(mutex_);
-    process_group_id_ = child_pid;
-    StartTimer(timeout);
-    lock.unlock();
+    {
+      Lock lock(mutex_);
+      process_group_id_ = child_pid;
+      StartTimer(timeout);
+    }
     int status;
     pid_t wait_pid;
     do {
       wait_pid = waitpid(child_pid, &status, 0);
     } while (wait_pid == (pid_t) -1 && errno == EINTR);
-    lock.lock();
-    StopTimer();
-    bool killed = process_group_id_ == 0;
-    process_group_id_ = 0;
-    lock.unlock();
+    bool killed;
+    {
+      Lock lock(mutex_);
+      StopTimer();
+      killed = process_group_id_ == 0;
+      process_group_id_ = 0;
+    }
     bool successful = false;
     if (!killed && wait_pid != (pid_t) -1) {
       if (!WIFEXITED(status)) {
diff --git a/osaf/libs/core/cplusplus/base/process.h 
b/osaf/libs/core/cplusplus/base/process.h
--- a/osaf/libs/core/cplusplus/base/process.h
+++ b/osaf/libs/core/cplusplus/base/process.h
@@ -15,20 +15,19 @@
  *
  */
 
-#ifndef OPENSAF_OSAF_LIBS_CORE_CPLUSPLUS_BASE_PROCESS_H_
-#define OPENSAF_OSAF_LIBS_CORE_CPLUSPLUS_BASE_PROCESS_H_
+#ifndef OSAF_LIBS_CORE_CPLUSPLUS_BASE_PROCESS_H_
+#define OSAF_LIBS_CORE_CPLUSPLUS_BASE_PROCESS_H_
 
+#include <chrono>
 #include <csignal>
 #include <cstdint>
 #include <ctime>
-#include <chrono>
-#include <mutex>
-#include "base/macros.h"
+#include "osaf/libs/core/cplusplus/base/macros.h"
+#include "osaf/libs/core/cplusplus/base/mutex.h"
 
 namespace base {
 
 class Process {
-  DELETE_COPY_AND_MOVE_OPERATORS(Process);
  public:
   using Duration = std::chrono::steady_clock::duration;
   Process();
@@ -96,18 +95,20 @@ class Process {
    * processes in the process group have terminated.
    */
   static void KillProc(pid_t pid, int sig_no, const Duration& wait_time);
+
  private:
   using Clock = std::chrono::steady_clock;
   using TimePoint = std::chrono::steady_clock::time_point;
   void StartTimer(const Duration& timeout);
   void StopTimer();
   static void TimerExpirationEvent(sigval notification_data);
-  std::mutex mutex_;
+  Mutex mutex_;
   timer_t timer_id_;
   bool is_timer_created_;
   pid_t process_group_id_;
+  DELETE_COPY_AND_MOVE_OPERATORS(Process);
 };
 
-} // namespace base
+}  // namespace base
 
-#endif  /* OPENSAF_OSAF_LIBS_CORE_CPLUSPLUS_BASE_PROCESS_H_ */
+#endif  // OSAF_LIBS_CORE_CPLUSPLUS_BASE_PROCESS_H_
diff --git a/osaf/libs/core/cplusplus/base/unix_socket.cc 
b/osaf/libs/core/cplusplus/base/unix_socket.cc
--- a/osaf/libs/core/cplusplus/base/unix_socket.cc
+++ b/osaf/libs/core/cplusplus/base/unix_socket.cc
@@ -32,19 +32,10 @@ UnixSocket::UnixSocket(const std::string
   } else {
     addr_.sun_path[0] = '\0';
   }
-  pthread_mutexattr_t attr;
-  int result = pthread_mutexattr_init(&attr);
-  if (result != 0) osaf_abort(result);
-  result = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
-  if (result != 0) osaf_abort(result);
-  result = pthread_mutex_init(&mutex_, &attr);
-  if (result != 0) osaf_abort(result);
-  result = pthread_mutexattr_destroy(&attr);
-  if (result != 0) osaf_abort(result);
 }
 
 int UnixSocket::Open() {
-  osaf_mutex_lock_ordie(&mutex_);
+  Lock lock(mutex_);
   int sock = fd_;
   if (sock < 0) {
     if (addr_.sun_path[0] != '\0') {
@@ -60,18 +51,15 @@ int UnixSocket::Open() {
       errno = ENAMETOOLONG;
     }
   }
-  osaf_mutex_unlock_ordie(&mutex_);
   return sock;
 }
 
 UnixSocket::~UnixSocket() {
   Close();
-  int result = pthread_mutex_destroy(&mutex_);
-  if (result != 0) osaf_abort(result);
 }
 
 void UnixSocket::Close() {
-  osaf_mutex_lock_ordie(&mutex_);
+  Lock lock(mutex_);
   int sock = fd_;
   if (sock >= 0) {
     int e = errno;
@@ -80,7 +68,6 @@ void UnixSocket::Close() {
     CloseHook();
     errno = e;
   }
-  osaf_mutex_unlock_ordie(&mutex_);
 }
 
 bool UnixSocket::OpenHook(int) {
diff --git a/osaf/libs/core/cplusplus/base/unix_socket.h 
b/osaf/libs/core/cplusplus/base/unix_socket.h
--- a/osaf/libs/core/cplusplus/base/unix_socket.h
+++ b/osaf/libs/core/cplusplus/base/unix_socket.h
@@ -24,6 +24,7 @@
 #include <cerrno>
 #include <string>
 #include "osaf/libs/core/cplusplus/base/macros.h"
+#include "osaf/libs/core/cplusplus/base/mutex.h"
 
 namespace base {
 
@@ -85,7 +86,7 @@ class UnixSocket {
  private:
   int fd_;
   struct sockaddr_un addr_;
-  pthread_mutex_t mutex_;
+  Mutex mutex_;
 
   DELETE_COPY_AND_MOVE_OPERATORS(UnixSocket);
 };

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to