Belle II Software  release-05-01-25
MMutex.cc
1 #include "daq/slc/system/MMutex.h"
2 
3 using namespace Belle2;
4 
5 MMutex::MMutex() {}
6 
7 MMutex::MMutex(const MMutex& mutex)
8 {
9  *this = mutex;
10 }
11 
12 MMutex::MMutex(void* addr)
13 {
14  set((pthread_mutex_t*)addr);
15 }
16 
17 MMutex::~MMutex() {}
18 
19 bool MMutex::init(void* addr)
20 {
21  set(addr);
22  init();
23  return true;
24 }
25 
26 bool MMutex::init()
27 {
28  pthread_mutexattr_t attr;
29  pthread_mutexattr_init(&attr);
30  pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
31  pthread_mutex_init(m_mu, &attr);
32  pthread_mutexattr_destroy(&attr);
33  return true;
34 }
35 
36 bool MMutex::set(void* addr)
37 {
38  m_mu = (pthread_mutex_t*)addr;
39  return true;
40 }
41 
42 bool MMutex::lock()
43 {
44  if (pthread_mutex_lock(m_mu) != 0) {
45  return false;
46  } else {
47  return true;
48  }
49 }
50 
51 bool MMutex::trylock()
52 {
53  if (pthread_mutex_lock(m_mu) != 0) {
54  return false;
55  }
56  return true;
57 }
58 
59 bool MMutex::unlock()
60 {
61  if (pthread_mutex_unlock(m_mu) != 0) {
62  return true;
63  } else {
64  return false;
65  }
66 }
67 
68 bool MMutex::destroy()
69 {
70  if (pthread_mutex_destroy(m_mu) != 0) {
71  return true;
72  } else {
73  return false;
74  }
75 }
76 
77 const MMutex& MMutex::operator=(const MMutex& mutex)
78 {
79  m_mu = mutex.m_mu;
80  return *this;
81 }
Belle2::MMutex
Definition: MMutex.h:19
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19