OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_ScopedLock.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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
23 namespace juce
24{
25
26//==============================================================================
53 template <class LockType>
54 class GenericScopedLock
55{
56 public:
57 //==============================================================================
67 inline explicit GenericScopedLock (const LockType& lock) noexcept : lock_ (lock) { lock.enter(); }
68
74 inline ~GenericScopedLock() noexcept { lock_.exit(); }
75
76 private:
77 //==============================================================================
78 const LockType& lock_;
79
80 JUCE_DECLARE_NON_COPYABLE (GenericScopedLock)
81};
82
83
84//==============================================================================
124 template <class LockType>
125 class GenericScopedUnlock
126{
127 public:
128 //==============================================================================
139 inline explicit GenericScopedUnlock (const LockType& lock) noexcept : lock_ (lock) { lock.exit(); }
140
148 inline ~GenericScopedUnlock() noexcept { lock_.enter(); }
149
150
151 private:
152 //==============================================================================
153 const LockType& lock_;
154
155 JUCE_DECLARE_NON_COPYABLE (GenericScopedUnlock)
156};
157
158
159//==============================================================================
196 template <class LockType>
197 class GenericScopedTryLock
198{
199 public:
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
236 private:
237 //==============================================================================
238 const LockType& lock_;
239 mutable bool lockWasSuccessful;
240
241 JUCE_DECLARE_NON_COPYABLE (GenericScopedTryLock)
242};
243
244} // 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