Loading...
Searching...
No Matches
juce_ScopedReadLock.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API ScopedReadLock
{
public:
//==============================================================================
inline explicit ScopedReadLock (const ReadWriteLock& lock) noexcept : lock_ (lock) { lock.enterRead(); }
inline ~ScopedReadLock() noexcept { lock_.exitRead(); }
private:
//==============================================================================
const ReadWriteLock& lock_;
JUCE_DECLARE_NON_COPYABLE (ScopedReadLock)
};
//==============================================================================
class JUCE_API ScopedTryReadLock
{
public:
//==============================================================================
explicit ScopedTryReadLock (ReadWriteLock& lockIn)
: ScopedTryReadLock (lockIn, true) {}
ScopedTryReadLock (ReadWriteLock& lockIn, bool acquireLockOnInitialisation) noexcept
: lock (lockIn), lockWasSuccessful (acquireLockOnInitialisation && lock.tryEnterRead()) {}
~ScopedTryReadLock() noexcept { if (lockWasSuccessful) lock.exitRead(); }
bool isLocked() const noexcept { return lockWasSuccessful; }
bool retryLock() noexcept { return lockWasSuccessful = lock.tryEnterRead(); }
private:
//==============================================================================
ReadWriteLock& lock;
bool lockWasSuccessful;
JUCE_DECLARE_NON_COPYABLE (ScopedTryReadLock)
};
} // namespace juce
juce::ReadWriteLock
Definition juce_ReadWriteLock.h:48
juce::ScopedReadLock
Definition juce_ScopedReadLock.h:52
juce::ScopedReadLock::~ScopedReadLock
~ScopedReadLock() noexcept
Definition juce_ScopedReadLock.h:74
juce::ScopedReadLock::ScopedReadLock
ScopedReadLock(const ReadWriteLock &lock) noexcept
Definition juce_ScopedReadLock.h:65
juce::ScopedTryReadLock
Definition juce_ScopedReadLock.h:120
juce::ScopedTryReadLock::~ScopedTryReadLock
~ScopedTryReadLock() noexcept
Definition juce_ScopedReadLock.h:154
juce::ScopedTryReadLock::ScopedTryReadLock
ScopedTryReadLock(ReadWriteLock &lockIn, bool acquireLockOnInitialisation) noexcept
Definition juce_ScopedReadLock.h:144
juce::ScopedTryReadLock::ScopedTryReadLock
ScopedTryReadLock(ReadWriteLock &lockIn)
Definition juce_ScopedReadLock.h:131
juce::ScopedTryReadLock::isLocked
bool isLocked() const noexcept
Definition juce_ScopedReadLock.h:157
juce::ScopedTryReadLock::retryLock
bool retryLock() noexcept
Definition juce_ScopedReadLock.h:160