JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | List of all members
juce::GenericScopedTryLock< LockType > Class Template Reference

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

#include "juce_ScopedLock.h"

Public Member Functions

 GenericScopedTryLock (const LockType &lock, bool acquireLockOnInitialisation=true) noexcept
 Creates a GenericScopedTryLock.
 
 ~GenericScopedTryLock () noexcept
 Destructor.
 
bool isLocked () const noexcept
 Returns true if the mutex was successfully locked.
 
bool retryLock () const noexcept
 Retry gaining the lock by calling tryEnter on the underlying lock.
 

Detailed Description

template<class LockType>
class juce::GenericScopedTryLock< 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.

for (;;)
{
// Unlike using a ScopedLock, this may fail to actually get the lock, so you
// should test this with the isLocked() method before doing your thread-unsafe
// action..
if (myScopedTryLock.isLocked())
{
...do some stuff...
}
else
{
..our attempt at locking failed because another thread had already locked it..
}
// myCriticalSection gets unlocked here (if it was locked)
}
Automatically locks and unlocks a mutex object.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
See also
CriticalSection::tryEnter, GenericScopedLock, GenericScopedUnlock

@tags{Core}

Definition at line 197 of file juce_ScopedLock.h.

Constructor & Destructor Documentation

◆ GenericScopedTryLock()

template<class LockType >
juce::GenericScopedTryLock< LockType >::GenericScopedTryLock ( const LockType &  lock,
bool  acquireLockOnInitialisation = true 
)
explicitnoexcept

Creates a GenericScopedTryLock.

If acquireLockOnInitialisation is true then as soon as this ScopedTryLock is created, it will attempt to acquire the lock with tryEnter.

You can retry acquiring the lock by calling retryLock.

When GenericScopedTryLock is deleted, the lock will be released (if the lock was successfully acquired).

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.

See also
retryLock, isLocked

Definition at line 217 of file juce_ScopedLock.h.

◆ ~GenericScopedTryLock()

template<class LockType >
juce::GenericScopedTryLock< LockType >::~GenericScopedTryLock ( )
noexcept

Destructor.

The mutex will be unlocked (if it had been successfully locked) 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!

Definition at line 228 of file juce_ScopedLock.h.

Member Function Documentation

◆ isLocked()

template<class LockType >
bool juce::GenericScopedTryLock< LockType >::isLocked ( ) const
noexcept

Returns true if the mutex was successfully locked.

Definition at line 231 of file juce_ScopedLock.h.

◆ retryLock()

template<class LockType >
bool juce::GenericScopedTryLock< LockType >::retryLock ( ) const
noexcept

Retry gaining the lock by calling tryEnter on the underlying lock.

Definition at line 234 of file juce_ScopedLock.h.


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