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::ScopedTryWriteLock Class Reference

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

#include "juce_ScopedWriteLock.h"

Public Member Functions

 ScopedTryWriteLock (ReadWriteLock &lockIn) noexcept
 Creates a ScopedTryWriteLock and calls ReadWriteLock::tryEnterWrite() immediately.
 
 ScopedTryWriteLock (ReadWriteLock &lockIn, bool acquireLockOnInitialisation) noexcept
 Creates a ScopedTryWriteLock.
 
 ~ScopedTryWriteLock () noexcept
 Destructor.
 
bool isLocked () const noexcept
 Returns true if the mutex was successfully locked.
 
bool retryLock () noexcept
 Retry gaining the lock by calling tryEnter on the underlying lock.
 

Detailed Description

Automatically locks and unlocks a ReadWriteLock object.

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

e.g.

for (;;)
{
// Unlike using a ScopedWriteLock, 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 some other thread has already locked the object..
}
// myLock gets unlocked here (if it was locked).
}
A critical section that allows multiple simultaneous readers.
Automatically locks and unlocks a ReadWriteLock 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
ReadWriteLock, ScopedTryWriteLock

@tags{Core}

Definition at line 119 of file juce_ScopedWriteLock.h.

Constructor & Destructor Documentation

◆ ScopedTryWriteLock() [1/2]

juce::ScopedTryWriteLock::ScopedTryWriteLock ( ReadWriteLock lockIn)
noexcept

Creates a ScopedTryWriteLock and calls ReadWriteLock::tryEnterWrite() immediately.

When the ScopedTryWriteLock object is destructed, the ReadWriteLock will be unlocked (if it was successfully acquired).

Make sure this object is created and destructed 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.

Definition at line 131 of file juce_ScopedWriteLock.h.

◆ ScopedTryWriteLock() [2/2]

juce::ScopedTryWriteLock::ScopedTryWriteLock ( ReadWriteLock lockIn,
bool  acquireLockOnInitialisation 
)
noexcept

Creates a ScopedTryWriteLock.

If acquireLockOnInitialisation is true then as soon as it is created, this will call ReadWriteLock::tryEnterWrite(), and when the ScopedTryWriteLock object is destructed, the ReadWriteLock will be unlocked (if it was successfully acquired).

Make sure this object is created and destructed 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.

Definition at line 144 of file juce_ScopedWriteLock.h.

◆ ~ScopedTryWriteLock()

juce::ScopedTryWriteLock::~ScopedTryWriteLock ( )
noexcept

Destructor.

The ReadWriteLock's exitWrite() method will be called when the destructor is called.

Make sure this object is created and destructed by the same thread, otherwise there are no guarantees what will happen!

Definition at line 154 of file juce_ScopedWriteLock.h.

Member Function Documentation

◆ isLocked()

bool juce::ScopedTryWriteLock::isLocked ( ) const
noexcept

Returns true if the mutex was successfully locked.

Definition at line 157 of file juce_ScopedWriteLock.h.

◆ retryLock()

bool juce::ScopedTryWriteLock::retryLock ( )
noexcept

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

Definition at line 160 of file juce_ScopedWriteLock.h.


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