casacore
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::Mutex Class Reference

Wrapper around a pthreads mutex. More...

#include <Mutex.h>

Public Types

enum  Type {
  Normal,
  ErrorCheck,
  Recursive,
  Default,
  Auto
}
 Define the type of mutex. More...
 

Public Member Functions

 Mutex (Type type=Auto)
 Create the mutex. More...
 
 ~Mutex () noexcept(false)
 Destroy the mutex. More...
 
void lock ()
 Lock the mutex. More...
 
void unlock ()
 Unlock the mutex. More...
 
bool trylock ()
 Try to lock the mutex. More...
 

Private Member Functions

 Mutex (const Mutex &)
 Forbid copy constructor. More...
 
Mutexoperator= (const Mutex &)
 Forbid assignment. More...
 

Private Attributes

pthread_mutex_t itsMutex
 

Detailed Description

Wrapper around a pthreads mutex.

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Synopsis

This class is a wrapper around a pthreads mutex.
Although the Mutex class has a lock function, class ScopedMutexLock should be used to obtain a lock, because it makes locking exception-safe.

Definition at line 58 of file Mutex.h.

Member Enumeration Documentation

◆ Type

Define the type of mutex.

(see phtread_mutexattr_settype for their meaning). In Debug mode, type Auto will use PTHREAD_MUTEX_ERRORCHECK, otherwise PTHREAD_MUTEX_DEFAULT.

Enumerator
Normal 
ErrorCheck 
Recursive 
Default 
Auto 

Definition at line 65 of file Mutex.h.

Constructor & Destructor Documentation

◆ Mutex() [1/2]

casacore::Mutex::Mutex ( Type  type = Auto)

Create the mutex.

Referenced by trylock().

◆ ~Mutex()

casacore::Mutex::~Mutex ( )
noexcept

Destroy the mutex.

declaring noexcept(false) to squash compiler warning, although note that it is usually a bad idea for destructors to throw exceptions

Referenced by trylock().

◆ Mutex() [2/2]

casacore::Mutex::Mutex ( const Mutex )
private

Forbid copy constructor.

Member Function Documentation

◆ lock()

void casacore::Mutex::lock ( )
inline

Lock the mutex.

It blocks until it can get exclusive access to the lock.

Definition at line 78 of file Mutex.h.

References AIPS_UNLIKELY, and itsMutex.

Referenced by trylock().

◆ operator=()

Mutex& casacore::Mutex::operator= ( const Mutex )
private

◆ trylock()

bool casacore::Mutex::trylock ( )
inline

Try to lock the mutex.

True is returned if it succeeded.

Definition at line 98 of file Mutex.h.

References itsMutex, lock(), Mutex(), operator=(), unlock(), and ~Mutex().

◆ unlock()

void casacore::Mutex::unlock ( )
inline

Unlock the mutex.

Terminates if in a destructor during exception, but acceptable, since it would be a serious bug hopefully exposed by a test case.

Definition at line 87 of file Mutex.h.

References AIPS_UNLIKELY, and itsMutex.

Referenced by trylock().

Member Data Documentation

◆ itsMutex

pthread_mutex_t casacore::Mutex::itsMutex
private

Definition at line 129 of file Mutex.h.

Referenced by lock(), trylock(), and unlock().


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