DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
ManualResetEvent.cpp
Go to the documentation of this file.
1#include "pch.h"
6#if defined(_WIN32)
7#include <windows.h>
8#endif
9
10namespace DotNetDupe {
11 namespace System {
12 namespace Threading {
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
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
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
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}
Notifies one or more waiting threads that an event has occurred.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
Utility routines for high-performance UTF-8, UTF-16, and wide-character string conversions.
Exception thrown when an attempt to open a named system wait handle fails.
A unified smart pointer that supports both unique and shared ownership semantics.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
const char * GetRawString() const
Definition String.cpp:230
EventWaitHandle(bool initialState, bool manualReset)
Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initia...
ManualResetEvent(bool initialState)
Initializes a new instance of the ManualResetEvent class with a Boolean value indicating whether to s...
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...
static SmartPointer< ManualResetEvent > OpenExisting(const String &sName)
Opens an existing named system manual-reset event.
WaitHandleCannotBeOpenedException(const String &sMessage)
Initializes a new instance of the WaitHandleCannotBeOpenedException class with a specified error mess...
static std::wstring Utf8ToWChar(const char *pUtf8Str)
Converts a null-terminated UTF-8 char string into a UTF-16 std::wstring.