DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
Lock.h
Go to the documentation of this file.
1
3
4
#pragma once
5
#include "
Common.h
"
6
#include "
System/Threading/CriticalSection.h
"
7
#include "
System/Threading/Mutex.h
"
8
#include "
System/Threading/Semaphore.h
"
9
#include "
System/Threading/SemaphoreSlim.h
"
10
11
namespace
DotNetDupe
{
12
namespace
System
{
13
namespace
Threading
{
14
20
template
<
typename
T>
21
class
Lock
{
22
public
:
27
Lock
(T& syncObject,
int
millisecondsTimeout = -1,
int
releaseCount = -1)
28
: _syncObject(syncObject), _releaseCount(releaseCount == -1 ? 1 : releaseCount) {
29
30
if
(millisecondsTimeout == -1) {
31
_syncObject.WaitOne();
32
}
else
{
33
_syncObject.WaitOne(millisecondsTimeout);
34
}
35
}
36
38
~Lock
() {
39
_syncObject.Release(_releaseCount);
40
}
41
42
private
:
43
T& _syncObject;
44
int
_releaseCount;
45
};
46
48
template
<>
49
class
Lock
<
CriticalSection
> {
50
public
:
55
Lock
(
CriticalSection
& cs,
int
millisecondsTimeout = -1,
int
releaseCount = -1)
56
: _cs(cs) {
57
_cs.Enter();
58
}
59
61
~Lock
() {
62
_cs.Leave();
63
}
64
65
private
:
66
CriticalSection
& _cs;
67
};
68
71
typedef
Lock<CriticalSection>
CriticalSectionLock
;
72
75
typedef
Lock<Mutex>
MutexLock
;
76
79
typedef
Lock<Semaphore>
SemaphoreLock
;
80
83
typedef
Lock<SemaphoreSlim>
SemaphoreSlimLock
;
84
}
85
}
86
}
Common.h
Defines common cross-platform macros, export decorators, and fundamental types.
CriticalSection.h
Provides a re-entrant mutual exclusion primitive for thread synchronization.
Mutex.h
A synchronization primitive that can also be used for interprocess synchronization.
Semaphore.h
Limits the number of threads that can access a resource or pool of resources concurrently.
SemaphoreSlim.h
Represents a lightweight alternative to Semaphore for intra-process synchronization.
DotNetDupe::System::Threading::CriticalSection
Provides a re-entrant mutual exclusion primitive for thread synchronization.
Definition
CriticalSection.h:19
DotNetDupe::System::Threading::Lock< CriticalSection >::Lock
Lock(CriticalSection &cs, int millisecondsTimeout=-1, int releaseCount=-1)
Enters the critical section upon construction.
Definition
Lock.h:55
DotNetDupe::System::Threading::Lock< CriticalSection >::~Lock
~Lock()
Leaves the critical section upon destruction.
Definition
Lock.h:61
DotNetDupe::System::Threading::Lock
Provides an RAII-style scoped lock wrapper around synchronization primitives.
Definition
Lock.h:21
DotNetDupe::System::Threading::Lock::~Lock
~Lock()
Releases the synchronization lock upon destruction.
Definition
Lock.h:38
DotNetDupe::System::Threading::Lock::Lock
Lock(T &syncObject, int millisecondsTimeout=-1, int releaseCount=-1)
Acquires the synchronization lock on the specified object.
Definition
Lock.h:27
DotNetDupe::System::Threading
Definition
AbandonedMutexException.h:11
DotNetDupe::System::Threading::CriticalSectionLock
Lock< CriticalSection > CriticalSectionLock
Convenience alias for Lock<CriticalSection>.
Definition
Lock.h:71
DotNetDupe::System::Threading::SemaphoreLock
Lock< Semaphore > SemaphoreLock
Convenience alias for Lock<Semaphore>.
Definition
Lock.h:79
DotNetDupe::System::Threading::SemaphoreSlimLock
Lock< SemaphoreSlim > SemaphoreSlimLock
Convenience alias for Lock<SemaphoreSlim>.
Definition
Lock.h:83
DotNetDupe::System::Threading::MutexLock
Lock< Mutex > MutexLock
Convenience alias for Lock<Mutex>.
Definition
Lock.h:75
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
Include
System
Threading
Lock.h
Generated by
1.18.0