Loading...
Searching...
No Matches
juce_ScopedLock.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
{
//==============================================================================
template <class LockType>
class GenericScopedLock
{
public:
//==============================================================================
inline explicit GenericScopedLock (const LockType& lock) noexcept : lock_ (lock) { lock.enter(); }
inline ~GenericScopedLock() noexcept { lock_.exit(); }
private:
//==============================================================================
const LockType& lock_;
JUCE_DECLARE_NON_COPYABLE (GenericScopedLock)
};
//==============================================================================
template <class LockType>
class GenericScopedUnlock
{
public:
//==============================================================================
inline explicit GenericScopedUnlock (const LockType& lock) noexcept : lock_ (lock) { lock.exit(); }
inline ~GenericScopedUnlock() noexcept { lock_.enter(); }
private:
//==============================================================================
const LockType& lock_;
JUCE_DECLARE_NON_COPYABLE (GenericScopedUnlock)
};
//==============================================================================
template <class LockType>
class GenericScopedTryLock
{
public:
//==============================================================================
inline explicit GenericScopedTryLock (const LockType& lock, bool acquireLockOnInitialisation = true) noexcept
: lock_ (lock), lockWasSuccessful (acquireLockOnInitialisation && lock.tryEnter()) {}
inline ~GenericScopedTryLock() noexcept { if (lockWasSuccessful) lock_.exit(); }
bool isLocked() const noexcept { return lockWasSuccessful; }
bool retryLock() const noexcept { lockWasSuccessful = lock_.tryEnter(); return lockWasSuccessful; }
private:
//==============================================================================
const LockType& lock_;
mutable bool lockWasSuccessful;
JUCE_DECLARE_NON_COPYABLE (GenericScopedTryLock)
};
} // namespace juce
juce::GenericScopedLock
Definition juce_ScopedLock.h:55
juce::GenericScopedLock::GenericScopedLock
GenericScopedLock(const LockType &lock) noexcept
Definition juce_ScopedLock.h:67
juce::GenericScopedLock::~GenericScopedLock
~GenericScopedLock() noexcept
Definition juce_ScopedLock.h:74
juce::GenericScopedTryLock
Definition juce_ScopedLock.h:198
juce::GenericScopedTryLock::GenericScopedTryLock
GenericScopedTryLock(const LockType &lock, bool acquireLockOnInitialisation=true) noexcept
Definition juce_ScopedLock.h:217
juce::GenericScopedTryLock::isLocked
bool isLocked() const noexcept
Definition juce_ScopedLock.h:231
juce::GenericScopedTryLock::retryLock
bool retryLock() const noexcept
Definition juce_ScopedLock.h:234
juce::GenericScopedTryLock::~GenericScopedTryLock
~GenericScopedTryLock() noexcept
Definition juce_ScopedLock.h:228
juce::GenericScopedUnlock
Definition juce_ScopedLock.h:126
juce::GenericScopedUnlock::~GenericScopedUnlock
~GenericScopedUnlock() noexcept
Definition juce_ScopedLock.h:148
juce::GenericScopedUnlock::GenericScopedUnlock
GenericScopedUnlock(const LockType &lock) noexcept
Definition juce_ScopedLock.h:139