Event.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "os/ErrorCodes.h"
  3. #include "os/Handle.h"
  4. #include "os/WaitStatus.h"
  5. #include "utils/NonCopyable.h"
  6. namespace il2cpp
  7. {
  8. namespace os
  9. {
  10. class EventImpl;
  11. class Event : public il2cpp::utils::NonCopyable
  12. {
  13. public:
  14. Event(bool manualReset = false, bool signaled = false);
  15. ~Event();
  16. ErrorCode Set();
  17. ErrorCode Reset();
  18. WaitStatus Wait(bool interruptible = false);
  19. WaitStatus Wait(uint32_t ms, bool interruptible = false);
  20. private:
  21. EventImpl* m_Event;
  22. };
  23. class EventHandle : public Handle
  24. {
  25. public:
  26. EventHandle(Event* event)
  27. : m_Event(event) {}
  28. virtual ~EventHandle() { delete m_Event; }
  29. virtual bool Wait() { m_Event->Wait(true); return true; }
  30. virtual bool Wait(uint32_t ms) { return m_Event->Wait(ms, true) != kWaitStatusTimeout; }
  31. virtual WaitStatus Wait(bool interruptible) { return m_Event->Wait(interruptible); }
  32. virtual WaitStatus Wait(uint32_t ms, bool interruptible) { return m_Event->Wait(ms, interruptible); }
  33. virtual void Signal() { m_Event->Set(); }
  34. Event& Get() { return *m_Event; }
  35. private:
  36. Event* m_Event;
  37. };
  38. }
  39. }