Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
WindowsCriticalSection.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Misc/Timespan.h"
7#include "HAL/PlatformMemory.h"
8
9class FString;
10
11/**
12 * This is the Windows version of a critical section. It uses an aggregate
13 * CRITICAL_SECTION to implement its locking.
14 */
16{
17public:
20
21 /**
22 * Constructor that initializes the aggregated critical section
23 */
25 {
26 CA_SUPPRESS(28125);
29 }
30
31 /**
32 * Destructor cleaning up the critical section
33 */
35 {
37 }
38
39 /**
40 * Locks the critical section
41 */
43 {
45 }
46
47 /**
48 * Attempt to take a lock and returns whether or not a lock was taken.
49 *
50 * @return true if a lock was taken, false otherwise.
51 */
53 {
55 {
56 return true;
57 }
58 return false;
59 }
60
61 /**
62 * Releases the lock on the critical section
63 */
65 {
67 }
68
69private:
70 /**
71 * The windows specific critical section
72 */
74};
75
76/** System-Wide Critical Section for windows using mutex */
78{
79public:
80 /** Construct a named, system-wide critical section and attempt to get access/ownership of it */
81 explicit FWindowsSystemWideCriticalSection(const class FString& InName, FTimespan InTimeout = FTimespan::Zero());
82
83 /** Destructor releases system-wide critical section if it is currently owned */
85
86 /**
87 * Does the calling thread have ownership of the system-wide critical section?
88 *
89 * @return True if obtained. WARNING: Returns true for an owned but previously abandoned locks so shared resources can be in undetermined states. You must handle shared data robustly.
90 */
91 bool IsValid() const;
92
93 /** Releases system-wide critical section if it is currently owned */
94 void Release();
95
96private:
99
100private:
102};
103
104/**
105 * FWindowsRWLock - Read/Write Mutex
106 * - Provides non-recursive Read/Write (or shared-exclusive) access.
107 * - Windows specific lock structures/calls Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/aa904937(v=vs.85).aspx
108 */
110{
111public:
114
115 FORCEINLINE FWindowsRWLock(uint32 Level = 0)
116 {
118 }
119
121 {
122 checkf(!IsLocked(), TEXT("Destroying a lock that is still held!"));
123 }
124
126 {
128 }
129
131 {
133 }
134
136 {
138 }
139
141 {
143 }
144
146 {
148 }
149
151 {
153 }
154
155private:
156
157 bool IsLocked()
158 {
160 {
162 return false;
163 }
164 else
165 {
166 return true;
167 }
168 }
169
171};
172
#define checkf(expr, format,...)
#define CA_SUPPRESS(WarningNumber)
#define FORCEINLINE
Definition Platform.h:644
FWindowsCriticalSection FCriticalSection
FWindowsRWLock FRWLock
FWindowsSystemWideCriticalSection FSystemWideCriticalSection
Windows::CRITICAL_SECTION CriticalSection
FWindowsCriticalSection & operator=(const FWindowsCriticalSection &)=delete
FWindowsCriticalSection(const FWindowsCriticalSection &)=delete
FWindowsRWLock & operator=(const FWindowsRWLock &)=delete
FORCEINLINE void WriteLock()
Windows::SRWLOCK Mutex
FORCEINLINE void ReadLock()
FORCEINLINE bool TryWriteLock()
FWindowsRWLock(const FWindowsRWLock &)=delete
FORCEINLINE void WriteUnlock()
FORCEINLINE void ReadUnlock()
FORCEINLINE bool TryReadLock()
FORCEINLINE FWindowsRWLock(uint32 Level=0)
FWindowsSystemWideCriticalSection & operator=(const FWindowsSystemWideCriticalSection &)
FWindowsSystemWideCriticalSection(const FWindowsSystemWideCriticalSection &)
FWindowsSystemWideCriticalSection(const class FString &InName, FTimespan InTimeout=FTimespan::Zero())
FORCEINLINE void WINAPI ReleaseSRWLockExclusive(SRWLOCK *SRWLock)
FORCEINLINE BOOLEAN WINAPI TryAcquireSRWLockExclusive(SRWLOCK *SRWLock)
FORCEINLINE void WINAPI AcquireSRWLockShared(SRWLOCK *SRWLock)
FORCEINLINE void WINAPI LeaveCriticalSection(CRITICAL_SECTION *lpCriticalSection)
FORCEINLINE BOOLEAN WINAPI TryAcquireSRWLockShared(SRWLOCK *SRWLock)
FORCEINLINE void WINAPI InitializeSRWLock(SRWLOCK *SRWLock)
FORCEINLINE void WINAPI ReleaseSRWLockShared(SRWLOCK *SRWLock)
FORCEINLINE void WINAPI AcquireSRWLockExclusive(SRWLOCK *SRWLock)
FORCEINLINE DWORD WINAPI SetCriticalSectionSpinCount(CRITICAL_SECTION *lpCriticalSection, DWORD dwSpinCount)
FORCEINLINE BOOL WINAPI TryEnterCriticalSection(CRITICAL_SECTION *lpCriticalSection)
FORCEINLINE void WINAPI InitializeCriticalSection(CRITICAL_SECTION *lpCriticalSection)
FORCEINLINE void WINAPI EnterCriticalSection(CRITICAL_SECTION *lpCriticalSection)
FORCEINLINE void WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCriticalSection)
static FTimespan Zero()
Definition Timespan.h:747