UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Context.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if (defined(__AUTORTFM) && __AUTORTFM)
6
7#include "CallNest.h"
8#include "IntrusivePool.h"
9#include "OpenHashThrottler.h"
10#include "Pool.h"
11#include "StackRange.h"
12#include "TaskArray.h"
13#include "ThreadID.h"
14#include "Transaction.h"
15#include "Utils.h"
16
17namespace AutoRTFM
18{
19
20class AUTORTFM_DISABLE FContext final
21{
22 using FTaskPool = typename TTaskArray<TTask<void()>>::FEntryPool;
25
26public:
27 static FContext* Create();
28 static FContext* Get();
29
30 // This is public API
31 ETransactionResult Transact(void (*UninstrumentedFunction)(void*), void (*InstrumentedFunction)(void*), void* Arg);
32
33 EContextStatus CallClosedNest(void (*ClosedFunction)(void* Arg), void* Arg);
34
36
37 // Open API - no throw
39
40 // No throw
42
46 inline bool IsAborting() const { return IsStatusAborting(Status); }
47 bool IsTransactional() const;
48 bool IsCommitting() const;
49 bool IsCommittingOrAborting() const;
50 bool IsRetrying() const;
51
52 // Record that a write is about to occur at the given LogicalAddress of Size bytes.
53 void RecordWrite(void* LogicalAddress, size_t Size);
54 template<unsigned SIZE> void RecordWrite(void* LogicalAddress);
55 template<unsigned SIZE> void RecordWriteSlow(void* LogicalAddress);
56
57 void DidAllocate(void* LogicalAddress, size_t Size);
58 void DidFree(void* LogicalAddress);
59
60 // The rest of this is internalish.
62
64 {
66 }
67 inline bool MustMaterializeDeferredTransactions() const
68 {
70 }
71 inline FTransaction* GetCurrentTransaction()
72 {
74 {
76 }
77 return CurrentTransaction;
78 }
79 inline FTransaction* GetMaterializedTransaction()
80 {
81 return CurrentTransaction;
82 }
83
84 inline FCallNest* GetCurrentNest() const { return CurrentNest; }
85 inline EContextStatus GetStatus() const { return CurrentThreadId == FThreadID::GetCurrent() ? Status : EContextStatus::Idle; }
86 [[noreturn]] void Throw();
87
89
90 void DumpState() const;
91
93 {
94 if (AUTORTFM_LIKELY(GetStatus() == EContextStatus::Idle))
95 {
96 return;
97 }
98
99 if (Status == EContextStatus::OnTrack)
100 {
102 Status = EContextStatus::InStaticLocalInitializer;
104 }
105 else if (Status == EContextStatus::InStaticLocalInitializer)
106 {
108 }
109 }
110
112 {
113 if (AUTORTFM_LIKELY(GetStatus() == EContextStatus::Idle))
114 {
115 return;
116 }
117
118 AUTORTFM_ASSERT(Status != EContextStatus::OnTrack);
119
120 if (Status == EContextStatus::InStaticLocalInitializer)
121 {
123
125 {
126 Status = EContextStatus::OnTrack;
127 }
128 }
129 }
130
131 inline FTaskPool& GetTaskPool() { return TaskPool; }
133
134private:
135 UE_AUTORTFM_API static FContext* Instance;
136
137 FContext() { Reset(); }
138 FContext(const FContext&) = delete;
139
142
144 void PopCallNest();
145
146 FTransaction* PushTransaction(bool bClosed, bool bIsScoped, FStackRange, EMemoryValidationLevel);
147 void PopTransaction();
148
150 bool AttemptToCommitTransaction(FTransaction* const Transaction);
151
152 // All of this other stuff ought to be private?
153 void Reset();
154
156
157 // We defer allocating FTransactions at the top of the transaction stack.
158 // This allows us to make starting a transaction in the open a load, some math, and a store.
160 FTransaction* CurrentTransaction{nullptr};
161 FCallNest* CurrentNest{nullptr};
162
163 FStackRange Stack;
164 EContextStatus Status{EContextStatus::Idle};
165 FThreadID CurrentThreadId;
171 /* LogInterval */ 10, // Log every 10 seconds.
172 /* AdjustThrottleInterval */ 0.5, // Adjust throttling probabilities every 500ms.
173 /* TargetFractionHashing */ 0.1 // At most we want to spent 10% of the time hashing.
174 };
175};
176
177} // namespace AutoRTFM
178
179#endif // (defined(__AUTORTFM) && __AUTORTFM)
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define AUTORTFM_DISABLE
Definition AutoRTFMDefines.h:116
#define UE_AUTORTFM_API
Definition AutoRTFMDefines.h:156
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
Definition API.cpp:57
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426