openshot-audio  0.1.6
juce_ReadWriteLock.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_READWRITELOCK_H_INCLUDED
30 #define JUCE_READWRITELOCK_H_INCLUDED
31 
32 
33 //==============================================================================
53 {
54 public:
55  //==============================================================================
60 
65 
66  //==============================================================================
74  void enterRead() const noexcept;
75 
84  bool tryEnterRead() const noexcept;
85 
96  void exitRead() const noexcept;
97 
98  //==============================================================================
106  void enterWrite() const noexcept;
107 
116  bool tryEnterWrite() const noexcept;
117 
128  void exitWrite() const noexcept;
129 
130 
131 private:
132  //==============================================================================
133  SpinLock accessLock;
134  WaitableEvent waitEvent;
135  mutable int numWaitingWriters, numWriters;
136  mutable Thread::ThreadID writerThreadId;
137 
138  struct ThreadRecursionCount
139  {
140  Thread::ThreadID threadID;
141  int count;
142  };
143 
144  mutable Array <ThreadRecursionCount> readerThreads;
145 
146  bool tryEnterWriteInternal (Thread::ThreadID) const noexcept;
147 
149 };
150 
151 
152 #endif // JUCE_READWRITELOCK_H_INCLUDED
void * ThreadID
Definition: juce_Thread.h:224
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_SpinLock.h:46
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_ReadWriteLock.h:52
Definition: juce_WaitableEvent.h:41
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191