MLIB
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1/*
2 Copyright (c) Mircea Neacsu (2014-2025) Licensed under MIT License.
3 This file is part of MLIB project. See LICENSE file for full license terms.
4*/
5
7
8#pragma once
9
10
11#include "syncbase.h"
12
13namespace mlib {
14
15class event : public syncbase
16{
17public:
18 explicit event (bool manual, bool signaled = false, const std::string& name = std::string ());
19
21 void signal ()
22 {
23 SetEvent (handle ());
24 };
25
27 void pulse ()
28 {
29 PulseEvent (handle ());
30 };
31
33 void reset ()
34 {
35 ResetEvent (handle ());
36 };
37};
38
40class manual_event : public event
41{
42public:
43 explicit manual_event (bool signaled = false, const std::string& name = std::string ())
44 : event (true, signaled, name){};
45};
46
48class auto_event : public event
49{
50public:
51 explicit auto_event (bool signaled = false, const std::string& name = std::string ())
52 : event (false, signaled, name){};
53
55 bool is_signaled () override;
56};
57
62{
63 bool result = syncbase::is_signaled ();
64 if (result)
65 signal ();
66 return result;
67}
68
69}; // namespace mlib
bool is_signaled() override
Check if event is signaled.
Definition event.h:61
void signal()
Set event to signaled state.
Definition event.h:21
void pulse()
Pulse event so that only one waiting thread is released.
Definition event.h:27
event(bool manual, bool signaled=false, const std::string &name=std::string())
Constructor for event objects.
Definition event.cpp:26
void reset()
Set event to non-signaled state.
Definition event.h:33
HANDLE handle() const
Return OS handle of this object.
Definition syncbase.h:53
syncbase()
Default constructor.
Definition syncbase.cpp:37
virtual const std::string & name() const
Return object's name.
Definition syncbase.h:59
virtual bool is_signaled()
Try to wait on the object.
Definition syncbase.h:152
Definition of mlib::syncbase class.