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

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

#include <juce_ScopedLock.h>

Collaboration diagram for juce::GenericScopedLock< LockType >:

Public Member Functions

 GenericScopedLock (const LockType &lock) noexcept
 Creates a GenericScopedLock. More...
 
 ~GenericScopedLock () noexcept
 Destructor. More...
 

Private Attributes

const LockType & lock_
 

Detailed Description

template<class LockType>
class juce::GenericScopedLock< LockType >

Automatically locks and unlocks a mutex object.

Use one of these as a local variable to provide RAII-based locking of a mutex.

The templated class could be a CriticalSection, SpinLock, or anything else that provides enter() and exit() methods.

e.g.

CriticalSection myCriticalSection;
for (;;)
{
const GenericScopedLock<CriticalSection> myScopedLock (myCriticalSection);
// myCriticalSection is now locked
...do some stuff...
// myCriticalSection gets unlocked here.
}
See also
GenericScopedUnlock, CriticalSection, SpinLock, ScopedLock, ScopedUnlock

@tags{Core}

Constructor & Destructor Documentation

◆ GenericScopedLock()

template<class LockType >
juce::GenericScopedLock< LockType >::GenericScopedLock ( const LockType &  lock)
inlineexplicitnoexcept

Creates a GenericScopedLock.

As soon as it is created, this will acquire the lock, and when the GenericScopedLock object is deleted, the lock will be released.

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.

◆ ~GenericScopedLock()

template<class LockType >
juce::GenericScopedLock< LockType >::~GenericScopedLock ( )
inlinenoexcept

Destructor.

The lock will be released 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!

References juce::GenericScopedLock< LockType >::lock_.

Member Data Documentation

◆ lock_

template<class LockType >
const LockType& juce::GenericScopedLock< LockType >::lock_
private

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