openshot-audio  0.1.7
juce_Thread.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_THREAD_H_INCLUDED
30 #define JUCE_THREAD_H_INCLUDED
31 
32 
33 //==============================================================================
48 {
49 public:
50  //==============================================================================
57  explicit Thread (const String& threadName);
58 
66  virtual ~Thread();
67 
68  //==============================================================================
77  virtual void run() = 0;
78 
79  //==============================================================================
80  // Thread control functions..
81 
89  void startThread();
90 
98  void startThread (int priority);
99 
120  bool stopThread (int timeOutMilliseconds);
121 
122  //==============================================================================
124  bool isThreadRunning() const;
125 
138  void signalThreadShouldExit();
139 
147  inline bool threadShouldExit() const { return shouldExit; }
148 
157  bool waitForThreadToExit (int timeOutMilliseconds) const;
158 
159  //==============================================================================
166  bool setPriority (int priority);
167 
175  static bool setCurrentThreadPriority (int priority);
176 
177  //==============================================================================
185  void setAffinityMask (uint32 affinityMask);
186 
191  static void JUCE_CALLTYPE setCurrentThreadAffinityMask (uint32 affinityMask);
192 
193  //==============================================================================
194  // this can be called from any thread that needs to pause..
195  static void JUCE_CALLTYPE sleep (int milliseconds);
196 
198  static void JUCE_CALLTYPE yield();
199 
200  //==============================================================================
210  bool wait (int timeOutMilliseconds) const;
211 
218  void notify() const;
219 
220  //==============================================================================
224  typedef void* ThreadID;
225 
233  static ThreadID JUCE_CALLTYPE getCurrentThreadId();
234 
240  static Thread* JUCE_CALLTYPE getCurrentThread();
241 
251  ThreadID getThreadId() const noexcept { return threadId; }
252 
257  const String& getThreadName() const { return threadName; }
258 
262  static void JUCE_CALLTYPE setCurrentThreadName (const String& newThreadName);
263 
264 
265 private:
266  //==============================================================================
267  const String threadName;
268  void* volatile threadHandle;
269  ThreadID threadId;
270  CriticalSection startStopLock;
271  WaitableEvent startSuspensionEvent, defaultEvent;
272  int threadPriority;
273  uint32 affinityMask;
274  bool volatile shouldExit;
275 
276  #ifndef DOXYGEN
277  friend void JUCE_API juce_threadEntryPoint (void*);
278  #endif
279 
280  void launchThread();
281  void closeThreadHandle();
282  void killThread();
283  void threadEntryPoint();
284  static bool setThreadPriority (void*, int);
285 
287 };
288 
289 #endif // JUCE_THREAD_H_INCLUDED
void * ThreadID
Definition: juce_Thread.h:224
#define noexcept
Definition: juce_CompilerSupport.h:141
bool threadShouldExit() const
Definition: juce_Thread.h:147
#define JUCE_CALLTYPE
Definition: juce_PlatformDefs.h:50
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_CriticalSection.h:47
void JUCE_API juce_threadEntryPoint(void *userData)
Definition: juce_core.cpp:112
unsigned int uint32
Definition: juce_MathsFunctions.h:51
ThreadID getThreadId() const noexcept
Definition: juce_Thread.h:251
Definition: juce_WaitableEvent.h:41
const String & getThreadName() const
Definition: juce_Thread.h:257
Definition: juce_Thread.h:47
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198