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