JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ScopedReadLock Class Reference

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

#include <juce_ScopedReadLock.h>

Collaboration diagram for juce::ScopedReadLock:

Public Member Functions

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

Private Attributes

const ReadWriteLocklock_
 

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

@tags{Core}

Constructor & Destructor Documentation

◆ ScopedReadLock()

juce::ScopedReadLock::ScopedReadLock ( const ReadWriteLock lock)
inlineexplicitnoexcept

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()

juce::ScopedReadLock::~ScopedReadLock ( )
inlinenoexcept

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!

Member Data Documentation

◆ lock_

const ReadWriteLock& juce::ScopedReadLock::lock_
private

The documentation for this class was generated from the following file:
juce::ScopedReadLock::ScopedReadLock
ScopedReadLock(const ReadWriteLock &lock) noexcept
Creates a ScopedReadLock.
Definition: juce_ScopedReadLock.h:65