JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ScopedLock.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
53template <class LockType>
55{
56public:
57 //==============================================================================
67 inline explicit GenericScopedLock (const LockType& lock) noexcept : lock_ (lock) { lock.enter(); }
68
74 inline ~GenericScopedLock() noexcept { lock_.exit(); }
75
76private:
77 //==============================================================================
78 const LockType& lock_;
79
81};
82
83
84//==============================================================================
124template <class LockType>
126{
127public:
128 //==============================================================================
139 inline explicit GenericScopedUnlock (const LockType& lock) noexcept : lock_ (lock) { lock.exit(); }
140
148 inline ~GenericScopedUnlock() noexcept { lock_.enter(); }
149
150
151private:
152 //==============================================================================
153 const LockType& lock_;
154
156};
157
158
159//==============================================================================
196template <class LockType>
198{
199public:
200 //==============================================================================
217 inline explicit GenericScopedTryLock (const LockType& lock, bool acquireLockOnInitialisation = true) noexcept
218 : lock_ (lock), lockWasSuccessful (acquireLockOnInitialisation && lock.tryEnter()) {}
219
228 inline ~GenericScopedTryLock() noexcept { if (lockWasSuccessful) lock_.exit(); }
229
231 bool isLocked() const noexcept { return lockWasSuccessful; }
232
234 bool retryLock() const noexcept { lockWasSuccessful = lock_.tryEnter(); return lockWasSuccessful; }
235
236private:
237 //==============================================================================
238 const LockType& lock_;
239 mutable bool lockWasSuccessful;
240
242};
243
244} // namespace juce
Automatically locks and unlocks a mutex object.
GenericScopedLock(const LockType &lock) noexcept
Creates a GenericScopedLock.
~GenericScopedLock() noexcept
Destructor.
Automatically locks and unlocks a mutex object.
GenericScopedTryLock(const LockType &lock, bool acquireLockOnInitialisation=true) noexcept
Creates a GenericScopedTryLock.
bool isLocked() const noexcept
Returns true if the mutex was successfully locked.
bool retryLock() const noexcept
Retry gaining the lock by calling tryEnter on the underlying lock.
~GenericScopedTryLock() noexcept
Destructor.
Automatically unlocks and re-locks a mutex object.
~GenericScopedUnlock() noexcept
Destructor.
GenericScopedUnlock(const LockType &lock) noexcept
Creates a GenericScopedUnlock.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88