Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ScopeRWLock.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/AssertionMacros.h"
7#include "HAL/CriticalSection.h"
8
9
10/** Keeps a FRWLock read-locked while this scope lives */
12{
13public:
15 : Lock(InLock)
16 {
18 }
19
21 {
23 }
24
25private:
27
29};
30
31/** Keeps a FRWLock write-locked while this scope lives */
33{
34public:
36 : Lock(InLock)
37 {
39 }
40
42 {
44 }
45
46private:
48
50};
51
52//
53// A scope lifetime controlled Read or Write lock of referenced mutex object
54//
56{
59};
60
61/**
62 * Keeps a FRWLock read- or write-locked while this scope lives
63 *
64 * Notes:
65 * - PThreads and Win32 API's don't provide a mechanism for upgrading a ownership of a read lock to a write lock - to get round that this system unlocks then acquires a write lock so it can race between.
66 */
68{
69public:
70 UE_NODISCARD_CTOR explicit FRWScopeLock(FRWLock& InLockObject,FRWScopeLockType InLockType)
71 : LockObject(InLockObject)
72 , LockType(InLockType)
73 {
75 {
77 }
78 else
79 {
81 }
82 }
83
84 // NOTE: As the name suggests, this function should be used with caution.
85 // It releases the read lock _before_ acquiring a new write lock. This is not an atomic operation and the caller should
86 // not treat it as such.
87 // E.g. Pointers read from protected data structures prior to this call may be invalid after the function is called.
89 {
91 {
95 }
96 }
97
99 {
101 {
103 }
104 else
105 {
107 }
108 }
109
110private:
112
115};
#define UE_NONCOPYABLE(TypeName)
FRWScopeLockType
Definition Enums.h:5910
#define UE_NODISCARD_CTOR
Definition Platform.h:674
@ SLT_ReadOnly
Definition ScopeRWLock.h:57
@ SLT_Write
Definition ScopeRWLock.h:58
FWindowsRWLock FRWLock
void ReleaseReadOnlyLockAndAcquireWriteLock_USE_WITH_CAUTION()
Definition ScopeRWLock.h:88
FRWLock & LockObject
UE_NODISCARD_CTOR FRWScopeLock(FRWLock &InLockObject, FRWScopeLockType InLockType)
Definition ScopeRWLock.h:70
FRWScopeLockType LockType
UE_NODISCARD_CTOR FReadScopeLock(FRWLock &InLock)
Definition ScopeRWLock.h:14
FRWLock & Lock
Definition ScopeRWLock.h:26
FORCEINLINE void WriteLock()
FORCEINLINE void ReadLock()
FORCEINLINE void WriteUnlock()
FORCEINLINE void ReadUnlock()
UE_NODISCARD_CTOR FWriteScopeLock(FRWLock &InLock)
Definition ScopeRWLock.h:35
FRWLock & Lock
Definition ScopeRWLock.h:47