Belle II Software development
MMutex Class Reference

Public Member Functions

 MMutex (void *)
 
 MMutex (const MMutex &)
 
bool init (void *)
 
bool init ()
 
bool set (void *)
 
bool lock ()
 
bool trylock ()
 
bool unlock ()
 
bool destroy ()
 
const MMutexoperator= (const MMutex &)
 

Static Public Member Functions

static size_t size ()
 

Private Attributes

pthread_mutex_t * m_mu
 

Friends

class MCond
 

Detailed Description

Definition at line 26 of file MMutex.h.

Constructor & Destructor Documentation

◆ MMutex() [1/3]

MMutex ( )

Definition at line 12 of file MMutex.cc.

12{}

◆ MMutex() [2/3]

MMutex ( void *  addr)
explicit

Definition at line 19 of file MMutex.cc.

20{
21 set((pthread_mutex_t*)addr);
22}

◆ MMutex() [3/3]

MMutex ( const MMutex mutex)

Definition at line 14 of file MMutex.cc.

15{
16 *this = mutex;
17}

◆ ~MMutex()

~MMutex ( )

Definition at line 24 of file MMutex.cc.

24{}

Member Function Documentation

◆ destroy()

bool destroy ( )

Definition at line 75 of file MMutex.cc.

76{
77 if (pthread_mutex_destroy(m_mu) != 0) {
78 return true;
79 } else {
80 return false;
81 }
82}

◆ init() [1/2]

bool init ( )

Definition at line 33 of file MMutex.cc.

34{
35 pthread_mutexattr_t attr;
36 pthread_mutexattr_init(&attr);
37 pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
38 pthread_mutex_init(m_mu, &attr);
39 pthread_mutexattr_destroy(&attr);
40 return true;
41}

◆ init() [2/2]

bool init ( void *  addr)

Definition at line 26 of file MMutex.cc.

27{
28 set(addr);
29 init();
30 return true;
31}

◆ lock()

bool lock ( )

Definition at line 49 of file MMutex.cc.

50{
51 if (pthread_mutex_lock(m_mu) != 0) {
52 return false;
53 } else {
54 return true;
55 }
56}

◆ operator=()

const MMutex & operator= ( const MMutex mutex)

Definition at line 84 of file MMutex.cc.

85{
86 m_mu = mutex.m_mu;
87 return *this;
88}

◆ set()

bool set ( void *  addr)

Definition at line 43 of file MMutex.cc.

44{
45 m_mu = (pthread_mutex_t*)addr;
46 return true;
47}

◆ size()

static size_t size ( )
inlinestatic

Definition at line 31 of file MMutex.h.

31{ return sizeof(pthread_mutex_t); }

◆ trylock()

bool trylock ( )

Definition at line 58 of file MMutex.cc.

59{
60 if (pthread_mutex_lock(m_mu) != 0) {
61 return false;
62 }
63 return true;
64}

◆ unlock()

bool unlock ( )

Definition at line 66 of file MMutex.cc.

67{
68 if (pthread_mutex_unlock(m_mu) != 0) {
69 return true;
70 } else {
71 return false;
72 }
73}

Friends And Related Function Documentation

◆ MCond

friend class MCond
friend

Definition at line 28 of file MMutex.h.

Member Data Documentation

◆ m_mu

pthread_mutex_t* m_mu
private

Definition at line 55 of file MMutex.h.


The documentation for this class was generated from the following files: