Rudiments: threadmutex Class Reference

Rudiments

Public Member Functions | List of all members
threadmutex Class Reference

## Public Member Functions
| threadmutex ()
| threadmutex (void *mut)
| ~threadmutex ()
bool | lock ()
bool | tryLock ()
bool | unlock ()
void * | getInternalMutexStructure ()

## Detailed Description

The threadmutex class provides mutual exclusion locks between separate threads of a single process.

## Constructor & Destructor Documentation

## ◆ threadmutex() [1/2]

threadmutex::threadmutex | ( |  | ) |

Creates an instance of the threadmutex class.

## ◆ threadmutex() [2/2]

threadmutex::threadmutex | ( | void * | mut | ) |

Creates an instance of the threadmutex class that uses an already-initialized, system-specific threadmutex structure. On unix systems, this would likely be an instance of struct pthread_mutex_t, though it could possibly be something else.

## ◆ ~threadmutex()

threadmutex::~threadmutex | ( |  | ) |

Deletes this instance of the threadmutex class.

## Member Function Documentation

## ◆ getInternalMutexStructure()

void* threadmutex::getInternalMutexStructure | ( |  | ) |

Returns the mutex structure used by the class internally. On unix systems this would most likely be a struct pthread_mutex_t *, though it could possibly be something else.

## ◆ lock()

bool threadmutex::lock | ( |  | ) |

Locks the mutex. Will wait until the lock succeds. Returns true on success and false if an error occurs.

## ◆ tryLock()

bool threadmutex::tryLock | ( |  | ) |

Attempts to lock the mutex. Will return immediately if the mutex could not be locked, returning false and setting errno to EBUSY. Returns true on success and false if an error occurs.

## ◆ unlock()

bool threadmutex::unlock | ( |  | ) |

Unlocks the mutex. Returns true on success and false if an error occurs.