Event.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. void* GetOSHandle();
  21. private:
  22. EventImpl* m_Event;
  23. };
  24. class EventHandle : public Handle
  25. {
  26. public:
  27. EventHandle(Event* event)
  28. : m_Event(event) {}
  29. virtual ~EventHandle() { delete m_Event; }
  30. virtual bool Wait() { m_Event->Wait(true); return true; }
  31. virtual bool Wait(uint32_t ms) { return m_Event->Wait(ms, true) != kWaitStatusTimeout; }
  32. virtual WaitStatus Wait(bool interruptible) { return m_Event->Wait(interruptible); }
  33. virtual WaitStatus Wait(uint32_t ms, bool interruptible) { return m_Event->Wait(ms, interruptible); }
  34. virtual void Signal() { m_Event->Set(); }
  35. virtual void* GetOSHandle() { return m_Event->GetOSHandle(); }
  36. Event& Get() { return *m_Event; }
  37. private:
  38. Event* m_Event;
  39. };
  40. }
  41. }