The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.4KB

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