Automatically locks and unlocks a mutex object. More...
#include <juce_ScopedLock.h>
Public Member Functions | |
GenericScopedTryLock (const LockType &lock) noexcept | |
Creates a GenericScopedTryLock. More... | |
~GenericScopedTryLock () noexcept | |
Destructor. More... | |
bool | isLocked () const noexcept |
Returns true if the mutex was successfully locked. More... | |
Private Attributes | |
const LockType & | lock_ |
const bool | lockWasSuccessful |
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.
|
inlineexplicitnoexcept |
Creates a GenericScopedTryLock.
As soon as it is created, this will attempt to acquire the lock, and when the 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.
|
inlinenoexcept |
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!
References GenericScopedLock< LockType >::lock_.
|
inlinenoexcept |
Returns true if the mutex was successfully locked.
|
private |
|
private |