UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DelegateAccessHandler.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 "HAL/CriticalSection.h" // jira SOL-6812: Remove this.
8#include "Misc/ScopeLock.h"
10#include "AutoRTFM.h"
11
12//#define UE_DETECT_DELEGATES_RACE_CONDITIONS 0
13
14#if !defined(UE_DETECT_DELEGATES_RACE_CONDITIONS)
15#define UE_DETECT_DELEGATES_RACE_CONDITIONS ENABLE_MT_DETECTOR
16#endif
17
24
29template<typename ThreadSafetyMode>
31
32template <typename ThreadSafetyMode>
34
39template<>
58
59template<>
64
70template<>
92
93template<>
98
99#if UE_DETECT_DELEGATES_RACE_CONDITIONS
100
104template<>
106{
108
109protected:
110#if !UE_AUTORTFM
111 class FReadAccessScope
112 {
113 public:
115
117 : DestructionSentinel(FMRSWRecursiveAccessDetector::EAccessType::Reader)
118 {
120 DestructionSentinel.Accessor->AcquireReadAccess(DestructionSentinel);
121 }
122
124 {
125 if (!DestructionSentinel.bDestroyed) // only if `AccessDetector` wasn't destroyed while being accessed
126 {
127 DestructionSentinel.Accessor->ReleaseReadAccess(DestructionSentinel);
128 }
129 }
130
131 private:
132 FMRSWRecursiveAccessDetector::FDestructionSentinel DestructionSentinel;
133 };
134
135 [[nodiscard]] FReadAccessScope GetReadAccessScope() const
136 {
138 }
139
141 {
142 public:
144
147 {
149 InAccessDetector.AcquireWriteAccess(DestructionSentinel);
150 }
151
153 {
154 if (!DestructionSentinel.bDestroyed) // only if `AccessDetector` wasn't destroyed while being accessed
155 {
156 // the `const_cast` doesn't violate constness here as we got a mutable accessor in `FWriteAccessScope` constuctor,
157 // otherwise we'd need to have a redundant ptr to a mutable accessor as a member
159 }
160 }
161
162 private:
163 FMRSWRecursiveAccessDetector::FDestructionSentinel DestructionSentinel;
164 };
165
166 [[nodiscard]] FWriteAccessScope GetWriteAccessScope()
167 {
169 }
170#else
171 struct FReadAccessScope {};
172 struct FWriteAccessScope {};
173
174 [[nodiscard]] FReadAccessScope GetReadAccessScope() const
175 {
176 return {};
177 }
178
179 [[nodiscard]] FWriteAccessScope GetWriteAccessScope()
180 {
181 return {};
182 }
183#endif
184
185private:
187};
188
189#else // UE_DETECT_DELEGATES_RACE_CONDITIONS
190
191template<>
196
197#endif // UE_DETECT_DELEGATES_RACE_CONDITIONS
198
199template<>
#define UE_NONCOPYABLE(TypeName)
Definition CoreMiscDefines.h:457
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
::FCriticalSection FTransactionallySafeCriticalSection
Definition TransactionallySafeCriticalSection.h:16
FWriteAccessScope GetWriteAccessScope()
Definition DelegateAccessHandler.h:53
FReadAccessScope GetReadAccessScope() const
Definition DelegateAccessHandler.h:48
FReadAccessScope GetReadAccessScope() const
Definition DelegateAccessHandler.h:79
FWriteAccessScope GetWriteAccessScope()
Definition DelegateAccessHandler.h:84
Definition DelegateAccessHandler.h:30
Definition ScopeLock.h:21
UE::TScopeLock< FTransactionallySafeCriticalSection > Lock
Definition DelegateAccessHandler.h:76
UE::TScopeLock< FTransactionallySafeCriticalSection > Lock
Definition DelegateAccessHandler.h:77
Definition UnrealTypeTraits.h:172
Definition DelegateBase.h:205