Nebula
Loading...
Searching...
No Matches
win32event.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "core/types.h"
13
14//------------------------------------------------------------------------------
15namespace Win32
16{
18{
19public:
21 Win32Event(bool manualReset=false);
26
28 void Signal();
30 void Reset();
32 void Wait() const;
34 bool WaitTimeout(int ms) const;
36 bool Peek() const;
38 bool IsManual() const;
39
40private:
41 bool manual;
42 HANDLE event;
43};
44
45//------------------------------------------------------------------------------
48inline
49Win32Event::Win32Event(bool manualReset)
50{
51 this->event = CreateEvent(NULL, manualReset, FALSE, NULL);
52 this->manual = manualReset;
53 n_assert(0 != this->event);
54}
55
56//------------------------------------------------------------------------------
59inline
61{
62 if (this->event)
63 CloseHandle(this->event);
64 this->event = rhs.event;
65 this->manual = rhs.manual;
66 rhs.event = nullptr;
67}
68
69//------------------------------------------------------------------------------
72inline
74{
75 if (this->event != nullptr)
76 {
77 CloseHandle(this->event);
78 this->event = nullptr;
79 }
80}
81
82//------------------------------------------------------------------------------
85inline void
87{
88 SetEvent(this->event);
89}
90
91//------------------------------------------------------------------------------
94inline void
96{
97 ResetEvent(this->event);
98}
99
100//------------------------------------------------------------------------------
103inline void
105{
106 WaitForSingleObject(this->event, INFINITE);
107}
108
109//------------------------------------------------------------------------------
116inline bool
117Win32Event::WaitTimeout(int timeoutInMilliSec) const
118{
119 DWORD res = WaitForSingleObject(this->event, timeoutInMilliSec);
120 return (WAIT_TIMEOUT == res) ? false : true;
121}
122
123//------------------------------------------------------------------------------
127inline bool
129{
130 DWORD res = WaitForSingleObject(this->event, 0);
131 return (WAIT_TIMEOUT == res) ? false : true;
132}
133
134//------------------------------------------------------------------------------
137inline bool
139{
140 return this->manual;
141}
142
143} // namespace Win32
144//------------------------------------------------------------------------------
145
Win32 implementation of an event synchronization object.
Definition win32event.h:18
bool manual
Definition win32event.h:41
~Win32Event()
destructor
Definition win32event.h:73
HANDLE event
Definition win32event.h:42
bool IsManual() const
Returns true if event is manually reset.
Definition win32event.h:138
Win32Event(bool manualReset=false)
constructor
Definition win32event.h:49
void Wait() const
wait for the event to become signalled
Definition win32event.h:104
void Signal()
signal the event
Definition win32event.h:86
bool Peek() const
check if event is signalled
Definition win32event.h:128
void Reset()
reset the event (only if manual reset)
Definition win32event.h:95
bool WaitTimeout(int ms) const
wait for the event with timeout in millisecs
Definition win32event.h:117
#define n_assert(exp)
Definition debug.h:50
EventId CreateEvent(const EventCreateInfo &info)
create new event
Definition vkevent.cc:42
[TODO: Describe Win32 subsystem]