Loading...
Searching...
No Matches
juce_SpinLock.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 SpinLock
{
public:
inline SpinLock() = default;
inline ~SpinLock() = default;
void enter() const noexcept;
inline bool tryEnter() const noexcept
{
return lock.compareAndSetBool (1, 0);
}
inline void exit() const noexcept
{
jassert (lock.get() == 1); // Agh! Releasing a lock that isn't currently held!
lock = 0;
}
//==============================================================================
using ScopedLockType = GenericScopedLock<SpinLock>;
using ScopedUnlockType = GenericScopedUnlock<SpinLock>;
using ScopedTryLockType = GenericScopedTryLock<SpinLock>;
private:
//==============================================================================
mutable Atomic<int> lock;
JUCE_DECLARE_NON_COPYABLE (SpinLock)
};
} // namespace juce
juce::GenericScopedLock
Definition juce_ScopedLock.h:55
juce::GenericScopedTryLock
Definition juce_ScopedLock.h:198
juce::GenericScopedUnlock
Definition juce_ScopedLock.h:126
juce::SpinLock::exit
void exit() const noexcept
Definition juce_SpinLock.h:65
juce::SpinLock::enter
void enter() const noexcept
Definition juce_Thread.cpp:334
juce::SpinLock::ScopedUnlockType
GenericScopedUnlock< SpinLock > ScopedUnlockType
Definition juce_SpinLock.h:76
juce::SpinLock::tryEnter
bool tryEnter() const noexcept
Definition juce_SpinLock.h:59
juce::SpinLock::ScopedTryLockType
GenericScopedTryLock< SpinLock > ScopedTryLockType
Definition juce_SpinLock.h:79
juce::SpinLock::ScopedLockType
GenericScopedLock< SpinLock > ScopedLockType
Definition juce_SpinLock.h:73
juce::Atomic
Definition juce_Atomic.h:42