DCMTK: OFMutex Class Reference

DCMTK Version 3.6.9 OFFIS DICOM Toolkit

Loading...
Searching...
No Matches
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.
int | lock ()
| locks the mutex object.
int | trylock ()
| tries to lock the mutex object.
int | unlock ()
| releases the lock on the mutex object.

## 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.

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

## 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.

## ◆ 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.

## 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 Sat Mar 1 2025 for DCMTK Version 3.6.9 by Doxygen 1.13.2