DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
AutoResetEvent.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/Threading/AutoResetEvent.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
AutoResetEvent::AutoResetEvent
(
bool
initialState)
14
:
EventWaitHandle
(initialState, false) {
16
}
17
18
static
bool
s_autoDummyCreatedNew
=
false
;
19
AutoResetEvent::AutoResetEvent
(
const
String
& sName,
bool
initialState,
bool
openAlways)
20
:
EventWaitHandle
(initialState, false, sName, openAlways,
s_autoDummyCreatedNew
) {
22
}
23
24
AutoResetEvent::AutoResetEvent
(
bool
initialState,
const
String
& sName,
bool
openAlways)
25
:
EventWaitHandle
(initialState, false, sName, openAlways,
s_autoDummyCreatedNew
) {
27
}
28
29
AutoResetEvent::AutoResetEvent
(
bool
initialState,
const
String
& sName,
bool
openAlways,
bool
& bCreatedNew)
30
:
EventWaitHandle
(initialState, false, sName, openAlways, bCreatedNew) {
32
}
33
34
SmartPointer<AutoResetEvent>
AutoResetEvent::OpenExisting
(
const
String
& sName) {
36
SmartPointer<AutoResetEvent>
pResult =
nullptr
;
37
if
(
TryOpenExisting
(sName, pResult)) {
38
return
pResult;
39
}
40
throw
WaitHandleCannotBeOpenedException
(
"No AutoResetEvent handle of the given name exists."
);
41
}
42
43
bool
AutoResetEvent::TryOpenExisting
(
const
String
& sName,
SmartPointer<AutoResetEvent>
& pResult) {
45
pResult =
nullptr
;
46
if
(sName.
IsEmpty
())
return
false
;
47
48
#if defined(_WIN32)
50
std::wstring wsName =
Utils::StringConvert::Utf8ToWChar
(sName.
GetRawString
());
51
HANDLE h = ::OpenEventW(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, wsName.c_str());
52
if
(!h)
return
false
;
53
54
auto
spEvt =
SmartPointer<AutoResetEvent>::NewShared
(
false
);
55
spEvt->_name = sName;
56
spEvt->_hHandle = h;
57
pResult = std::move(spEvt);
58
return
true
;
59
#else
60
return
false
;
61
#endif
62
}
63
}
64
}
65
}
AutoResetEvent.h
Notifies a waiting thread 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::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::AutoResetEvent::AutoResetEvent
AutoResetEvent(bool initialState)
Initializes a new instance of the AutoResetEvent class with a Boolean value indicating whether to set...
Definition
AutoResetEvent.cpp:13
DotNetDupe::System::Threading::AutoResetEvent::TryOpenExisting
static bool TryOpenExisting(const String &sName, SmartPointer< AutoResetEvent > &pResult)
Opens an existing named system auto-reset event, and returns a value that indicates whether the opera...
Definition
AutoResetEvent.cpp:43
DotNetDupe::System::Threading::AutoResetEvent::OpenExisting
static SmartPointer< AutoResetEvent > OpenExisting(const String &sName)
Opens an existing named system auto-reset event.
Definition
AutoResetEvent.cpp:34
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::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_autoDummyCreatedNew
static bool s_autoDummyCreatedNew
Definition
AutoResetEvent.cpp:18
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
AutoResetEvent.cpp
Generated by
1.18.0