MLIB
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1#pragma once
2/*
3 MLIB Library
4 (c) Mircea Neacsu 2001-2023. Licensed under MIT License.
5 See README file for full license terms.
6*/
8
9#include "syncbase.h"
10
11namespace mlib {
12
13class event : public syncbase
14{
15public:
16 explicit event (bool manual, bool signaled = false, const std::string& name = std::string ());
17
19 void signal ()
20 {
21 SetEvent (handle ());
22 };
23
25 void pulse ()
26 {
27 PulseEvent (handle ());
28 };
29
31 void reset ()
32 {
33 ResetEvent (handle ());
34 };
35};
36
38class manual_event : public event
39{
40public:
41 explicit manual_event (bool signaled = false, const std::string& name = std::string ())
42 : event (true, signaled, name){};
43};
44
46class auto_event : public event
47{
48public:
49 explicit auto_event (bool signaled = false, const std::string& name = std::string ())
50 : event (false, signaled, name){};
51
53 bool is_signaled () override;
54};
55
60{
61 bool result = syncbase::is_signaled ();
62 if (result)
63 signal ();
64 return result;
65}
66
67}; // namespace mlib
Event objects that reset automatically after a successful wait.
Definition event.h:47
bool is_signaled() override
Check if event is signaled.
Definition event.h:59
Events have only two states: signaled and not signaled.
Definition event.h:14
void signal()
Set event to signaled state.
Definition event.h:19
void pulse()
Pulse event so that only one waiting thread is released.
Definition event.h:25
void reset()
Set event to non-signaled state.
Definition event.h:31
Event objects that need manual reset.
Definition event.h:39
Base class for all named synchronization objects.
Definition syncbase.h:27
HANDLE handle() const
Return OS handle of this object.
Definition syncbase.h:54
virtual const std::string & name() const
Return object's name.
Definition syncbase.h:60
virtual bool is_signaled()
Try to wait on the object.
Definition syncbase.h:153
syncbase class definition.