JUCE
Typedefs
threads

Typedefs

using ScopedLock = CriticalSection::ScopedLockType
 Automatically locks and unlocks a CriticalSection object. More...
 
using ScopedUnlock = CriticalSection::ScopedUnlockType
 Automatically unlocks and re-locks a CriticalSection object. More...
 
using ScopedTryLock = CriticalSection::ScopedTryLockType
 Automatically tries to lock and unlock a CriticalSection object. More...
 

Detailed Description

Typedef Documentation

◆ ScopedLock

Automatically locks and unlocks a CriticalSection object.

You can use a ScopedLock as a local variable to provide RAII-based locking of a CriticalSection.

e.g.

struct MyObject
{
CriticalSection objectLock;
// assuming that this example function will be called by multiple threads
void foo()
{
const ScopedLock myScopedLock (objectLock);
// objectLock is now locked..
...do some thread-safe work here...
// ..and objectLock gets unlocked here, as myScopedLock goes out of
// scope at the end of the block
}
};
A re-entrant mutex.
Definition: juce_CriticalSection.h:44
Automatically locks and unlocks a mutex object.
Definition: juce_ScopedLock.h:56
See also
CriticalSection, ScopedUnlock

◆ ScopedUnlock

Automatically unlocks and re-locks a CriticalSection object.

This is the reverse of a ScopedLock object - instead of locking the critical section for the lifetime of this object, it unlocks it.

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

e.g.

struct MyObject
{
CriticalSection objectLock;
void foo()
{
{
const ScopedLock myScopedLock (objectLock);
// objectLock is now locked..
{
ScopedUnlock myUnlocker (objectLock);
// ..and now unlocked..
}
// ..and now locked again..
}
// ..and finally unlocked.
}
};
Automatically unlocks and re-locks a mutex object.
Definition: juce_ScopedLock.h:127
See also
CriticalSection, ScopedLock

◆ ScopedTryLock

Automatically tries to lock and unlock a CriticalSection object.

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

e.g.

struct MyObject
{
CriticalSection objectLock;
void foo()
{
const ScopedTryLock myScopedTryLock (objectLock);
// Unlike using a ScopedLock, this may fail to actually get the lock, so you
// must call the isLocked() method before making any assumptions..
if (myScopedTryLock.isLocked())
{
...safely do some work...
}
else
{
// If we get here, then our attempt at locking failed because another thread had already locked it..
}
}
};
Automatically locks and unlocks a mutex object.
Definition: juce_ScopedLock.h:199
See also
CriticalSection::tryEnter, ScopedLock, ScopedUnlock, ScopedReadLock