cheshirekow  v0.1.0
pthreads::ScopedLock Class Reference

Points to a locked mutex and unlocks the mutex when destroyed. More...

#include <cpp_pthreads/mutex.h>

Public Member Functions

ScopedLockoperator= (ScopedLock &other)
 assignment transfers ownership of the lock to the assignee More...
 
 ScopedLock (Mutex *mutex=0)
 default constructor has an empty mutex More...
 
 ScopedLock (Mutex &mutex)
 explicit creation, locks the mutex More...
 
void swap (ScopedLock &other)
 swaps mutexes with another lock More...
 
 ~ScopedLock ()
 move constructor transfers ownership of the lock to the new object More...
 

Private Attributes

Mutexm_mutex
 < the mutex being locked More...
 

Detailed Description

Points to a locked mutex and unlocks the mutex when destroyed.

Usage:

Mutex mutex;
{
// constructor locks the mutex here
ScopedLock lock(mutex);
// ... (do something)
} // when lock goes out of scope the destructor releases the lock on the
// mutex

Definition at line 53 of file mutex.h.

Constructor & Destructor Documentation

pthreads::ScopedLock::ScopedLock ( Mutex mutex = 0)

default constructor has an empty mutex

pthreads::ScopedLock::ScopedLock ( Mutex mutex)

explicit creation, locks the mutex

pthreads::ScopedLock::~ScopedLock ( )

move constructor transfers ownership of the lock to the new object

unlock the mutex

Member Function Documentation

ScopedLock& pthreads::ScopedLock::operator= ( ScopedLock other)

assignment transfers ownership of the lock to the assignee

If the assignee already owns a mutex, that one is unlocked

void pthreads::ScopedLock::swap ( ScopedLock other)

swaps mutexes with another lock

Member Data Documentation

Mutex* pthreads::ScopedLock::m_mutex
private

< the mutex being locked

Definition at line 56 of file mutex.h.


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