Scippy

UG

Ubiquity Generator framework

Lock Class Reference

Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards. More...

#include <paraPthLock.h>

Public Member Functions

 Lock ()
 Initialize this lock. More...
 
 ~Lock ()
 Destroy this lock. More...
 
void lock ()
 Acquire this lock. The function sets the internal file/line (debugging) fields to generic values. More...
 
void lock (char const *f, int l)
 Acquire this lock. The function sets the internal file/line (debugging) fields to the values specified by f and l. More...
 
void unlock ()
 Release this lock. More...
 

Private Member Functions

 Lock (Lock const &)
 Code like this pthread_mutex_t m1, m2; pthread_mutex_init(&m1, 0); m2 = m1; results in undefined behavior. So we must never assign one instance of pthread_mutex_t to another. To do that we make the copy constructor and the assignment operator private and do not implement it. This way locks can be passed around only by reference or pointer. More...
 
Lockoperator= (Lock const &)
 

Private Attributes

pthread_mutex_t mtx
 The low-level mutex that implements this lock. More...
 
char const * file
 File in which the lock was last acquired (debugging). More...
 
int line
 Line at which the lock was last acquired (debugging). More...
 

Friends

class ConditionVariable
 

Detailed Description

Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards.

Definition at line 82 of file paraPthLock.h.

Constructor & Destructor Documentation

◆ Lock() [1/2]

Lock ( Lock const &  )
private

Code like this pthread_mutex_t m1, m2; pthread_mutex_init(&m1, 0); m2 = m1; results in undefined behavior. So we must never assign one instance of pthread_mutex_t to another. To do that we make the copy constructor and the assignment operator private and do not implement it. This way locks can be passed around only by reference or pointer.

◆ Lock() [2/2]

Lock ( )

Initialize this lock.

Definition at line 109 of file paraPthLock.h.

References Lock::mtx.

◆ ~Lock()

~Lock ( )

Destroy this lock.

Definition at line 122 of file paraPthLock.h.

References Lock::mtx.

Member Function Documentation

◆ lock() [1/2]

void lock ( )

Acquire this lock. The function sets the internal file/line (debugging) fields to generic values.

Definition at line 133 of file paraPthLock.h.

References Lock::lock().

Referenced by ConditionVariable::lock(), Lock::lock(), ParaCommPth::lockApp(), LockRAII::LockRAII(), and ParaCommPth::lockRank().

◆ lock() [2/2]

void lock ( char const *  f,
int  l 
)

Acquire this lock. The function sets the internal file/line (debugging) fields to the values specified by f and l.

Parameters
ffile name
lline number

Definition at line 144 of file paraPthLock.h.

References Lock::file, Lock::line, LOCK_VERBOSE, and Lock::mtx.

◆ operator=()

Lock & operator= ( Lock const &  )
private

◆ unlock()

void unlock ( )

Friends And Related Function Documentation

◆ ConditionVariable

friend class ConditionVariable
friend

Definition at line 84 of file paraPthLock.h.

Member Data Documentation

◆ file

char const* file
private

File in which the lock was last acquired (debugging).

Definition at line 87 of file paraPthLock.h.

Referenced by Lock::lock(), and Lock::unlock().

◆ line

int line
private

Line at which the lock was last acquired (debugging).

Definition at line 88 of file paraPthLock.h.

Referenced by Lock::lock(), and Lock::unlock().

◆ mtx

pthread_mutex_t mtx
private

The low-level mutex that implements this lock.

Definition at line 86 of file paraPthLock.h.

Referenced by Lock::Lock(), Lock::lock(), Lock::unlock(), ConditionVariable::wait(), and Lock::~Lock().