DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
AutoResetEvent.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, 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
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
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
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}
Notifies a waiting thread 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
AutoResetEvent(bool initialState)
Initializes a new instance of the AutoResetEvent class with a Boolean value indicating whether to set...
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...
static SmartPointer< AutoResetEvent > OpenExisting(const String &sName)
Opens an existing named system auto-reset event.
EventWaitHandle(bool initialState, bool manualReset)
Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initia...
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.