DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
ManualResetEvent.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/Threading/ManualResetEvent.h
"
3
#include "
System/Threading/WaitHandleCannotBeOpenedException.h
"
4
#include "
System/Utils/StringConvert.h
"
5
#include "
System/SmartPointer.h
"
6
#if defined(_WIN32)
7
#include <windows.h>
8
#endif
9
10
namespace
DotNetDupe
{
11
namespace
System
{
12
namespace
Threading
{
13
ManualResetEvent::ManualResetEvent
(
bool
initialState)
14
:
EventWaitHandle
(initialState, true) {}
15
16
static
bool
s_manualDummyCreatedNew
=
false
;
17
ManualResetEvent::ManualResetEvent
(
const
String
& sName,
bool
initialState,
bool
openAlways)
18
:
EventWaitHandle
(initialState, true, sName, openAlways,
s_manualDummyCreatedNew
) {}
19
20
ManualResetEvent::ManualResetEvent
(
bool
initialState,
const
String
& sName,
bool
openAlways)
21
:
EventWaitHandle
(initialState, true, sName, openAlways,
s_manualDummyCreatedNew
) {}
22
23
ManualResetEvent::ManualResetEvent
(
bool
initialState,
const
String
& sName,
bool
openAlways,
bool
& bCreatedNew)
24
:
EventWaitHandle
(initialState, true, sName, openAlways, bCreatedNew) {}
25
26
SmartPointer<ManualResetEvent>
ManualResetEvent::OpenExisting
(
const
String
& sName) {
28
SmartPointer<ManualResetEvent>
pResult =
nullptr
;
29
if
(
TryOpenExisting
(sName, pResult)) {
30
return
pResult;
31
}
32
throw
WaitHandleCannotBeOpenedException
(
"No ManualResetEvent handle of the given name exists."
);
33
}
34
35
bool
ManualResetEvent::TryOpenExisting
(
const
String
& sName,
SmartPointer<ManualResetEvent>
& pResult) {
37
pResult =
SmartPointer<ManualResetEvent>
();
38
if
(sName.
IsEmpty
())
return
false
;
39
40
#if defined(_WIN32)
42
std::wstring wsName =
Utils::StringConvert::Utf8ToWChar
(sName.
GetRawString
());
43
HANDLE h = ::OpenEventW(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, wsName.c_str());
44
if
(h == NULL)
return
false
;
45
46
SmartPointer<ManualResetEvent>
spEvt =
SmartPointer<ManualResetEvent>::NewShared
(
false
);
47
spEvt->_name = sName;
48
spEvt->_hHandle = h;
49
pResult = std::move(spEvt);
50
return
true
;
51
#else
52
return
false
;
53
#endif
54
}
55
}
56
}
57
}
ManualResetEvent.h
Notifies one or more waiting threads that an event has occurred.
SmartPointer.h
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
StringConvert.h
Utility routines for high-performance UTF-8, UTF-16, and wide-character string conversions.
WaitHandleCannotBeOpenedException.h
Exception thrown when an attempt to open a named system wait handle fails.
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::SmartPointer::NewShared
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Definition
SmartPointer.h:277
DotNetDupe::System::SmartPointer::SmartPointer
friend class SmartPointer
Definition
SmartPointer.h:74
DotNetDupe::System::String
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition
String.h:74
DotNetDupe::System::String::IsEmpty
bool IsEmpty() const
Definition
String.cpp:398
DotNetDupe::System::String::GetRawString
const char * GetRawString() const
Definition
String.cpp:230
DotNetDupe::System::Threading::EventWaitHandle::EventWaitHandle
EventWaitHandle(bool initialState, bool manualReset)
Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initia...
Definition
EventWaitHandle.cpp:26
DotNetDupe::System::Threading::ManualResetEvent::ManualResetEvent
ManualResetEvent(bool initialState)
Initializes a new instance of the ManualResetEvent class with a Boolean value indicating whether to s...
Definition
ManualResetEvent.cpp:13
DotNetDupe::System::Threading::ManualResetEvent::TryOpenExisting
static bool TryOpenExisting(const String &sName, SmartPointer< ManualResetEvent > &pResult)
Opens an existing named system manual-reset event, and returns a value that indicates whether the ope...
Definition
ManualResetEvent.cpp:35
DotNetDupe::System::Threading::ManualResetEvent::OpenExisting
static SmartPointer< ManualResetEvent > OpenExisting(const String &sName)
Opens an existing named system manual-reset event.
Definition
ManualResetEvent.cpp:26
DotNetDupe::System::Threading::WaitHandleCannotBeOpenedException::WaitHandleCannotBeOpenedException
WaitHandleCannotBeOpenedException(const String &sMessage)
Initializes a new instance of the WaitHandleCannotBeOpenedException class with a specified error mess...
Definition
WaitHandleCannotBeOpenedException.h:21
DotNetDupe::System::Utils::StringConvert::Utf8ToWChar
static std::wstring Utf8ToWChar(const char *pUtf8Str)
Converts a null-terminated UTF-8 char string into a UTF-16 std::wstring.
Definition
StringConvert.h:47
DotNetDupe::System::Threading
Definition
AbandonedMutexException.h:11
DotNetDupe::System::Threading::s_manualDummyCreatedNew
static bool s_manualDummyCreatedNew
Definition
ManualResetEvent.cpp:16
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
ManualResetEvent.cpp
Generated by
1.18.0