event_wrapper.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_VIDEO_CODING_EVENT_WRAPPER_H_
  11. #define MODULES_VIDEO_CODING_EVENT_WRAPPER_H_
  12. namespace webrtc {
  13. enum EventTypeWrapper { kEventSignaled = 1, kEventTimeout = 2 };
  14. class EventWrapper {
  15. public:
  16. // Factory method. Constructor disabled.
  17. static EventWrapper* Create();
  18. virtual ~EventWrapper() {}
  19. // Releases threads who are calling Wait() and has started waiting. Please
  20. // note that a thread calling Wait() will not start waiting immediately.
  21. // assumptions to the contrary is a very common source of issues in
  22. // multithreaded programming.
  23. // Set is sticky in the sense that it will release at least one thread
  24. // either immediately or some time in the future.
  25. virtual bool Set() = 0;
  26. // Puts the calling thread into a wait state. The thread may be released
  27. // by a Set() call depending on if other threads are waiting and if so on
  28. // timing. The thread that was released will reset the event before leaving
  29. // preventing more threads from being released. If multiple threads
  30. // are waiting for the same Set(), only one (random) thread is guaranteed to
  31. // be released. It is possible that multiple (random) threads are released
  32. // Depending on timing.
  33. //
  34. // |max_time_ms| is the maximum time to wait in milliseconds.
  35. virtual EventTypeWrapper Wait(int max_time_ms) = 0;
  36. };
  37. } // namespace webrtc
  38. #endif // MODULES_VIDEO_CODING_EVENT_WRAPPER_H_