Fix crash when host does not support midi-in; Add missing file
[juce-lv2.git] / juce / source / src / threads / juce_WaitableEvent.h
blob11e146fd898cacba23f330400f1933c1514fb866
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_WAITABLEEVENT_JUCEHEADER__
27 #define __JUCE_WAITABLEEVENT_JUCEHEADER__
29 #include "../text/juce_String.h"
32 //==============================================================================
33 /**
34 Allows threads to wait for events triggered by other threads.
36 A thread can call wait() on a WaitableObject, and this will suspend the
37 calling thread until another thread wakes it up by calling the signal()
38 method.
40 class JUCE_API WaitableEvent
42 public:
43 //==============================================================================
44 /** Creates a WaitableEvent object.
46 @param manualReset If this is false, the event will be reset automatically when the wait()
47 method is called. If manualReset is true, then once the event is signalled,
48 the only way to reset it will be by calling the reset() method.
50 WaitableEvent (bool manualReset = false) noexcept;
52 /** Destructor.
54 If other threads are waiting on this object when it gets deleted, this
55 can cause nasty errors, so be careful!
57 ~WaitableEvent() noexcept;
59 //==============================================================================
60 /** Suspends the calling thread until the event has been signalled.
62 This will wait until the object's signal() method is called by another thread,
63 or until the timeout expires.
65 After the event has been signalled, this method will return true and if manualReset
66 was set to false in the WaitableEvent's constructor, then the event will be reset.
68 @param timeOutMilliseconds the maximum time to wait, in milliseconds. A negative
69 value will cause it to wait forever.
71 @returns true if the object has been signalled, false if the timeout expires first.
72 @see signal, reset
74 bool wait (int timeOutMilliseconds = -1) const noexcept;
76 //==============================================================================
77 /** Wakes up any threads that are currently waiting on this object.
79 If signal() is called when nothing is waiting, the next thread to call wait()
80 will return immediately and reset the signal.
82 If the WaitableEvent is manual reset, all current and future threads that wait upon this
83 object will be woken, until reset() is explicitly called.
85 If the WaitableEvent is automatic reset, and one or more threads is waiting upon the object,
86 then one of them will be woken up. If no threads are currently waiting, then the next thread
87 to call wait() will be woken up. As soon as a thread is woken, the signal is automatically
88 reset.
90 @see wait, reset
92 void signal() const noexcept;
94 //==============================================================================
95 /** Resets the event to an unsignalled state.
97 If it's not already signalled, this does nothing.
99 void reset() const noexcept;
102 private:
103 //==============================================================================
104 void* internal;
106 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WaitableEvent);
110 #endif // __JUCE_WAITABLEEVENT_JUCEHEADER__