OpenShot Audio Library | OpenShotAudio  0.3.1
juce_CriticalSection.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 //==============================================================================
42 class JUCE_API CriticalSection
43 {
44 public:
45  //==============================================================================
47  CriticalSection() noexcept;
48 
53  ~CriticalSection() noexcept;
54 
55  //==============================================================================
66  void enter() const noexcept;
67 
76  bool tryEnter() const noexcept;
77 
88  void exit() const noexcept;
89 
90 
91  //==============================================================================
94 
97 
100 
101 
102 private:
103  //==============================================================================
104  #if JUCE_WINDOWS
105  // To avoid including windows.h in the public JUCE headers, we'll just allocate
106  // a block of memory here that's big enough to be used internally as a windows
107  // CRITICAL_SECTION structure.
108  #if JUCE_64BIT
109  uint8 lock[44];
110  #else
111  uint8 lock[24];
112  #endif
113  #else
114  mutable pthread_mutex_t lock;
115  #endif
116 
117  JUCE_DECLARE_NON_COPYABLE (CriticalSection)
118 };
119 
120 
121 //==============================================================================
133 class JUCE_API DummyCriticalSection
134 {
135 public:
136  inline DummyCriticalSection() = default;
137  inline ~DummyCriticalSection() = default;
138 
139  inline void enter() const noexcept {}
140  inline bool tryEnter() const noexcept { return true; }
141  inline void exit() const noexcept {}
142 
143  //==============================================================================
146  {
147  ScopedLockType (const DummyCriticalSection&) noexcept {}
148  };
149 
152 
153 private:
154  JUCE_DECLARE_NON_COPYABLE (DummyCriticalSection)
155 };
156 
157 //==============================================================================
187 
188 //==============================================================================
227 
228 //==============================================================================
261 
262 } // namespace juce
GenericScopedTryLock< CriticalSection > ScopedTryLockType
GenericScopedLock< CriticalSection > ScopedLockType
GenericScopedUnlock< CriticalSection > ScopedUnlockType