Public Member Functions

ScopedReadLock Class Reference

Automatically locks and unlocks a ReadWriteLock object. More...

List of all members.

Public Member Functions

 ScopedReadLock (const ReadWriteLock &lock) noexcept
 Creates a ScopedReadLock.
 ~ScopedReadLock () noexcept
 Destructor.

Detailed Description

Automatically locks and unlocks a ReadWriteLock object.

Use one of these as a local variable to control access to a ReadWriteLock.

e.g.

    ReadWriteLock myLock;

    for (;;)
    {
        const ScopedReadLock myScopedLock (myLock);
        // myLock is now locked

        ...do some stuff...

        // myLock gets unlocked here.
    }
See also:
ReadWriteLock, ScopedWriteLock

Constructor & Destructor Documentation

ScopedReadLock::ScopedReadLock ( const ReadWriteLock lock ) [explicit]

Creates a ScopedReadLock.

As soon as it is created, this will call ReadWriteLock::enterRead(), and when the ScopedReadLock object is deleted, the ReadWriteLock will be unlocked.

Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen! Best just to use it as a local stack object, rather than creating one with the new() operator.

ScopedReadLock::~ScopedReadLock (  )

Destructor.

The ReadWriteLock's exitRead() method will be called when the destructor is called.

Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen!


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines