LMMS
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
229
232
235
236private:
237 //==============================================================================
238 const LockType& lock_;
239 mutable bool lockWasSuccessful;
240
242};
243
244} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
GenericScopedLock(const LockType &lock) noexcept
Definition juce_ScopedLock.h:67
~GenericScopedLock() noexcept
Definition juce_ScopedLock.h:74
const CriticalSection & lock_
Definition juce_ScopedLock.h:78
const CriticalSection & lock_
Definition juce_ScopedLock.h:238
GenericScopedTryLock(const LockType &lock, bool acquireLockOnInitialisation=true) noexcept
Definition juce_ScopedLock.h:217
bool isLocked() const noexcept
Definition juce_ScopedLock.h:231
bool lockWasSuccessful
Definition juce_ScopedLock.h:239
bool retryLock() const noexcept
Definition juce_ScopedLock.h:234
~GenericScopedTryLock() noexcept
Definition juce_ScopedLock.h:228
const CriticalSection & lock_
Definition juce_ScopedLock.h:153
~GenericScopedUnlock() noexcept
Definition juce_ScopedLock.h:148
GenericScopedUnlock(const LockType &lock) noexcept
Definition juce_ScopedLock.h:139
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition carla_juce.cpp:31
#define const
Definition zconf.h:137