JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::GenericScopedUnlock< LockType > Class Template Reference

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

#include <juce_ScopedLock.h>

Collaboration diagram for juce::GenericScopedUnlock< LockType >:

Public Member Functions

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

Private Attributes

const LockType & lock_
 

Detailed Description

template<class LockType>
class juce::GenericScopedUnlock< LockType >

Automatically unlocks and re-locks a mutex object.

This is the reverse of a GenericScopedLock object - instead of locking the mutex for the lifetime of this object, it unlocks it.

Make sure you don't try to unlock mutexes that aren't actually locked!

e.g.

CriticalSection myCriticalSection;
for (;;)
{
const GenericScopedLock<CriticalSection> myScopedLock (myCriticalSection);
// myCriticalSection is now locked
... do some stuff with it locked ..
while (xyz)
{
... do some stuff with it locked ..
const GenericScopedUnlock<CriticalSection> unlocker (myCriticalSection);
// myCriticalSection is now unlocked for the remainder of this block,
// and re-locked at the end.
...do some stuff with it unlocked ...
}
// myCriticalSection gets unlocked here.
}
See also
GenericScopedLock, CriticalSection, ScopedLock, ScopedUnlock

{Core}

Constructor & Destructor Documentation

◆ GenericScopedUnlock()

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

Creates a GenericScopedUnlock.

As soon as it is created, this will unlock the CriticalSection, and when the ScopedLock object is deleted, the CriticalSection will be re-locked.

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.

◆ ~GenericScopedUnlock()

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

Destructor.

The CriticalSection will be unlocked 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::GenericScopedUnlock< LockType >::lock_
private

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