DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
CriticalSection.cpp
Go to the documentation of this file.
1#include "pch.h"
3#include <mutex>
4
5namespace DotNetDupe {
6 namespace System {
7 namespace Threading {
8
9 struct CriticalSection::Impl {
10 std::recursive_mutex mtx;
11 };
12
13 CriticalSection::CriticalSection() : m_pImpl(new Impl()) {}
14
17 if (m_pImpl) {
18 delete m_pImpl;
19 m_pImpl = nullptr;
20 }
21 }
22
25 if (m_pImpl) {
26 m_pImpl->mtx.lock();
27 }
28 }
29
32 if (m_pImpl) {
33 m_pImpl->mtx.unlock();
34 }
35 }
36
39 return m_pImpl ? m_pImpl->mtx.try_lock() : false;
40 }
41 }
42 }
43}
Provides a re-entrant mutual exclusion primitive for thread synchronization.
bool TryEnter()
Attempts to enter a critical section without blocking.
~CriticalSection() override
Destructor releasing critical section resources.
void Enter()
Waits for ownership of the specified critical section object.
void Leave()
Releases ownership of the critical section object.
CriticalSection()
Initializes a new instance of the CriticalSection class.