DCMTK Version 3.7.0 OFFIS DICOM Toolkit

Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
OFMutex Class Reference

provides an operating system independent abstraction for mutexes (mutual exclusion locks). More...

## Public Member Functions
| OFMutex ()
| default constructor
| ~OFMutex ()
| destructor
OFBool | initialized () const
| checks whether creation of the object was successful. More...
int | lock ()
| locks the mutex object. More...
int | trylock ()
| tries to lock the mutex object. More...
int | unlock ()
| releases the lock on the mutex object. More...

## Static Public Member Functions
static void | errorstr (OFString &description, int code)
| converts any of the error codes returned by the methods of this class into a textual description, which is written into the string object. More...

## Static Public Attributes
static const int | busy
| this constant is returned by the trylock() method if the mutex is already locked. More...

## Private Member Functions
| OFMutex (const OFMutex &arg)
| unimplemented private copy constructor
OFMutex & | operator= (const OFMutex &arg)
| unimplemented private assignment operator

## Private Attributes
volatile void * | theMutex
| mutex resource

## Detailed Description

provides an operating system independent abstraction for mutexes (mutual exclusion locks).

Mutexes prevent multiple threads from simultaneously executing critical sections of code which access shared data. A successful call for a mutex lock by way of lock() will cause another thread that is also trying to lock the same mutex to block until the owner thread unlocks it by way of unlock().

## Member Function Documentation

## ◆ errorstr()

static void OFMutex::errorstr | ( | OFString & | description,
|  | int | code
| ) |  |
| static

converts any of the error codes returned by the methods of this class into a textual description, which is written into the string object.

Parameters

  description | string object into which the error description is written.
  code | error code

## ◆ initialized()

OFBool OFMutex::initialized | ( |  | ) | const

checks whether creation of the object was successful.

Returns
  OFTrue if the object was successfully created, OFFalse otherwise.

## ◆ lock()

int OFMutex::lock | ( |  | ) |

locks the mutex object.

If the mutex is already locked, the calling thread blocks until the mutex is freed; If the current owner of a mutex tries to relock the mutex, it may or may not result in deadlock.

Returns
  0 upon success, an error code otherwise.

Referenced by OFshared_ptr< T >::Data::decrement_count(), and OFshared_ptr< T >::Data::increment_count().

## ◆ trylock()

int OFMutex::trylock | ( |  | ) |

tries to lock the mutex object.

If the mutex is already locked, returns OFMutex::busy.

Returns
  0 upon success, OFMutex::busy if the mutex is already locked, an error code otherwise.

## ◆ unlock()

int OFMutex::unlock | ( |  | ) |

releases the lock on the mutex object.

The mutex must be locked and the calling thread must be the owner of the lock, otherwise the behaviour is undefined. If there are threads blocked on the mutex when unlock() is called, one of them is unblocked and receives ownership of the mutex lock.

Returns
  0 upon success, an error code otherwise.

Referenced by OFshared_ptr< T >::Data::decrement_count(), and OFshared_ptr< T >::Data::increment_count().

## Member Data Documentation

## ◆ busy

const int OFMutex::busy
| static

this constant is returned by the trylock() method if the mutex is already locked.

Since this value is operating system dependent, comparisons should always compare the return value of trylock() with this constant.

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

- ofstd/include/dcmtk/ofstd/ofthread.h

Generated on Mon Dec 15 2025 for DCMTK Version 3.7.0 by Doxygen 1.9.1