Jpp  debug
the software that should make you happy
Public Member Functions | Private Member Functions | Private Attributes | List of all members
JSYNCHRONIZATION::JBasicScopedLock< Lockable > Class Template Reference

Scoped lock. More...

#include <JMutex.hh>

Public Member Functions

 JBasicScopedLock (Lockable &lock)
 Constructor. More...
 
 ~JBasicScopedLock ()
 Destructor. More...
 
int unlock ()
 Unlock the mutex. More...
 

Private Member Functions

 JBasicScopedLock (const JBasicScopedLock &)
 Neither copy-constructible nor copy-assignable. More...
 
 JBasicScopedLock (JBasicScopedLock &&)
 
JBasicScopedLock operator= (const JBasicScopedLock &)
 
JBasicScopedLock operator= (JBasicScopedLock &&)
 

Private Attributes

Lockable * m_lock
 

Detailed Description

template<typename Lockable>
class JSYNCHRONIZATION::JBasicScopedLock< Lockable >

Scoped lock.

The main purpose of this class is to provide an exception-safe locking facility. The lock on the mutex is acquired during construction, while the unlock is performed in the destructor.

Es: Case 1, without scoped lock: using namespace JSYNCHRONIZATION; JMutex mutex;

{ mutex.lock(); throwing_function(variable_to_protect); // <- this shall throw mutex.lock(); // <- this call is never // executed -> deadlock }

Case 2, with scoped lock: using namespace JSYNCHRONIZATION; JMutex mutex;

{ JScopedLock(mutex); throwing_function(variable_to_protect); // <- this shall throw } // the lock is released here automatically

Definition at line 47 of file JMutex.hh.

Constructor & Destructor Documentation

◆ JBasicScopedLock() [1/3]

template<typename Lockable >
JSYNCHRONIZATION::JBasicScopedLock< Lockable >::JBasicScopedLock ( const JBasicScopedLock< Lockable > &  )
private

Neither copy-constructible nor copy-assignable.

◆ JBasicScopedLock() [2/3]

template<typename Lockable >
JSYNCHRONIZATION::JBasicScopedLock< Lockable >::JBasicScopedLock ( JBasicScopedLock< Lockable > &&  )
private

◆ JBasicScopedLock() [3/3]

template<typename Lockable >
JSYNCHRONIZATION::JBasicScopedLock< Lockable >::JBasicScopedLock ( Lockable &  lock)
inlineexplicit

Constructor.

Parameters
locka lockable object (e.g. JScopedLock)

Definition at line 66 of file JMutex.hh.

67  :
68  m_lock(&lock)
69  {
70  m_lock->lock();
71  }

◆ ~JBasicScopedLock()

template<typename Lockable >
JSYNCHRONIZATION::JBasicScopedLock< Lockable >::~JBasicScopedLock ( )
inline

Destructor.

Definition at line 76 of file JMutex.hh.

77  {
78  unlock();
79  }
int unlock()
Unlock the mutex.
Definition: JMutex.hh:86

Member Function Documentation

◆ operator=() [1/2]

template<typename Lockable >
JBasicScopedLock JSYNCHRONIZATION::JBasicScopedLock< Lockable >::operator= ( const JBasicScopedLock< Lockable > &  )
private

◆ operator=() [2/2]

template<typename Lockable >
JBasicScopedLock JSYNCHRONIZATION::JBasicScopedLock< Lockable >::operator= ( JBasicScopedLock< Lockable > &&  )
private

◆ unlock()

template<typename Lockable >
int JSYNCHRONIZATION::JBasicScopedLock< Lockable >::unlock ( )
inline

Unlock the mutex.

Returns
0 on success, an error code otherwise. See man 3p pthread_mutex_lock for further info.

Definition at line 86 of file JMutex.hh.

87  {
88  return m_lock->unlock();
89  }

Member Data Documentation

◆ m_lock

template<typename Lockable >
Lockable* JSYNCHRONIZATION::JBasicScopedLock< Lockable >::m_lock
private

Definition at line 50 of file JMutex.hh.


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