Loading...
Searching...
No Matches
juce_ScopedWriteLock.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 ScopedWriteLock
{
public:
//==============================================================================
inline explicit ScopedWriteLock (const ReadWriteLock& lock) noexcept : lock_ (lock) { lock.enterWrite(); }
inline ~ScopedWriteLock() noexcept { lock_.exitWrite(); }
private:
//==============================================================================
const ReadWriteLock& lock_;
JUCE_DECLARE_NON_COPYABLE (ScopedWriteLock)
};
//==============================================================================
class JUCE_API ScopedTryWriteLock
{
public:
//==============================================================================
ScopedTryWriteLock (ReadWriteLock& lockIn) noexcept
: ScopedTryWriteLock (lockIn, true) {}
ScopedTryWriteLock (ReadWriteLock& lockIn, bool acquireLockOnInitialisation) noexcept
: lock (lockIn), lockWasSuccessful (acquireLockOnInitialisation && lock.tryEnterWrite()) {}
~ScopedTryWriteLock() noexcept { if (lockWasSuccessful) lock.exitWrite(); }
bool isLocked() const noexcept { return lockWasSuccessful; }
bool retryLock() noexcept { return lockWasSuccessful = lock.tryEnterWrite(); }
private:
//==============================================================================
ReadWriteLock& lock;
bool lockWasSuccessful;
JUCE_DECLARE_NON_COPYABLE (ScopedTryWriteLock)
};
}
juce::ReadWriteLock
Definition juce_ReadWriteLock.h:48
juce::ScopedTryWriteLock
Definition juce_ScopedWriteLock.h:120
juce::ScopedTryWriteLock::retryLock
bool retryLock() noexcept
Definition juce_ScopedWriteLock.h:160
juce::ScopedTryWriteLock::ScopedTryWriteLock
ScopedTryWriteLock(ReadWriteLock &lockIn, bool acquireLockOnInitialisation) noexcept
Definition juce_ScopedWriteLock.h:144
juce::ScopedTryWriteLock::ScopedTryWriteLock
ScopedTryWriteLock(ReadWriteLock &lockIn) noexcept
Definition juce_ScopedWriteLock.h:131
juce::ScopedTryWriteLock::~ScopedTryWriteLock
~ScopedTryWriteLock() noexcept
Definition juce_ScopedWriteLock.h:154
juce::ScopedTryWriteLock::isLocked
bool isLocked() const noexcept
Definition juce_ScopedWriteLock.h:157
juce::ScopedWriteLock
Definition juce_ScopedWriteLock.h:52
juce::ScopedWriteLock::ScopedWriteLock
ScopedWriteLock(const ReadWriteLock &lock) noexcept
Definition juce_ScopedWriteLock.h:65
juce::ScopedWriteLock::~ScopedWriteLock
~ScopedWriteLock() noexcept
Definition juce_ScopedWriteLock.h:74