Loading...
Searching...
No Matches
juce::ScopedTryReadLock Class Reference

## 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.

ReadWriteLock myLock;
for (;;)
{
const ScopedTryReadLock myScopedTryLock (myLock);
// Unlike using a ScopedReadLock, 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 a write lock has already been issued...
}
// myLock gets unlocked here (if it was locked)
}
juce::ReadWriteLock
A critical section that allows multiple simultaneous readers.
Definition juce_ReadWriteLock.h:60
juce::ScopedTryReadLock::ScopedTryReadLock
ScopedTryReadLock(ReadWriteLock &lockIn)
Creates a ScopedTryReadLock and calls ReadWriteLock::tryEnterRead() as soon as it is created.
Definition juce_ScopedReadLock.h:143

See also
  ReadWriteLock, ScopedTryWriteLock

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

- juce_core/threads/juce_ScopedReadLock.h

## Public Member Functions

| ScopedTryReadLock (ReadWriteLock &lockIn)
| Creates a ScopedTryReadLock and calls ReadWriteLock::tryEnterRead() as soon as it is created.
| ScopedTryReadLock (ReadWriteLock &lockIn, bool acquireLockOnInitialisation) noexcept
| Creates a ScopedTryReadLock.
| ~ScopedTryReadLock () 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.

## Constructors and Destructors

## ScopedTryReadLock() [1/2]

juce::ScopedTryReadLock::ScopedTryReadLock | ( | ReadWriteLock & | lockIn | ) |

inline explicit

Creates a ScopedTryReadLock and calls ReadWriteLock::tryEnterRead() as soon as it is created.

When the ScopedTryReadLock 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.

References ScopedTryReadLock().

Referenced by ScopedTryReadLock().

## ScopedTryReadLock() [2/2]

juce::ScopedTryReadLock::ScopedTryReadLock | ( | ReadWriteLock & | lockIn,
|  | bool | acquireLockOnInitialisation )

inline noexcept

Creates a ScopedTryReadLock.

If acquireLockOnInitialisation is true then as soon as it is created, this will call ReadWriteLock::tryEnterRead(), and when the ScopedTryReadLock 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.

## ~ScopedTryReadLock()

juce::ScopedTryReadLock::~ScopedTryReadLock | ( |  | ) |

inline noexcept

Destructor.

The ReadWriteLock's exitRead() 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!

## Member Functions

## isLocked()

bool juce::ScopedTryReadLock::isLocked | ( |  | ) | const

inline noexcept

Returns true if the mutex was successfully locked.

## retryLock()

bool juce::ScopedTryReadLock::retryLock | ( |  | ) |

inline noexcept

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

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited