DCMTK: OFSemaphore Class Reference

DCMTK Version 3.7.0 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
OFSemaphore Class Reference

provides an operating system independent abstraction for semaphores. More...

## Public Member Functions
| OFSemaphore (unsigned int numResources)
| constructor.
| ~OFSemaphore ()
| destructor
OFBool | initialized () const
| checks whether creation of the object was successful.
int | wait ()
| blocks the calling thread until the semaphore counter is greater than zero and then atomically decreases the counter.
int | trywait ()
| atomically decreases the counter if it is larger than zero, otherwise returns OFSemaphore::busy.
int | post ()
| atomically increases the counter.

## 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 trywait() method if the semaphore is already locked.

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

## Private Attributes
volatile void * | theSemaphore
| semaphore resource

## Detailed Description

provides an operating system independent abstraction for semaphores.

A semaphore is a non-negative integer counter that is used to coordinate access to resources. The initial and maximum value of the counter is defined by the constructor. Each call to wait() decreases the counter by one and each call to post() increases the count by one. If a thread calls wait() while the counter is zero, the thread is blocked until another thread has increased the counter using post().

## Constructor & Destructor Documentation

## ◆ OFSemaphore()

OFSemaphore::OFSemaphore | ( | unsigned int | numResources | ) |

constructor.

Parameters

  numResources | is the initial and maximum value for the semaphore.

Referenced by OFSemaphore(), and operator=().

## Member Function Documentation

## ◆ errorstr()

void OFSemaphore::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 OFSemaphore::initialized | ( |  | ) | const

checks whether creation of the object was successful.

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

## ◆ post()

int OFSemaphore::post | ( |  | ) |

atomically increases the counter.

If threads are blocked on the semaphore, at least one of them is unblocked.

Returns
  0 upon success, an error code otherwise.

## ◆ trywait()

int OFSemaphore::trywait | ( |  | ) |

atomically decreases the counter if it is larger than zero, otherwise returns OFSemaphore::busy.

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

## ◆ wait()

int OFSemaphore::wait | ( |  | ) |

blocks the calling thread until the semaphore counter is greater than zero and then atomically decreases the counter.

Returns
  0 upon success, an error code otherwise.

## Member Data Documentation

## ◆ busy

const int OFSemaphore::busy
| static

this constant is returned by the trywait() method if the semaphore is already locked.

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

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

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

Generated on for DCMTK Version 3.7.0 by Doxygen 1.16.1