UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ScopeTryLock.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"
7#include "Misc/NotNull.h"
9
10namespace UE
11{
34 template <typename MutexType>
36 {
37 public:
38 [[nodiscard]] explicit TScopeTryLock(MutexType& InMutex)
39 {
40 if (InMutex.TryLock())
41 {
42 HeldMutex = &InMutex;
43 }
44 }
45
47 {
48 if (HeldMutex)
49 {
50 HeldMutex->Unlock();
51 }
52 }
53
55 {
56 return HeldMutex != nullptr;
57 }
58
59 private:
60 TScopeTryLock(const TScopeTryLock&) = delete;
61 TScopeTryLock& operator=(TScopeTryLock&) = delete;
62
63 MutexType* HeldMutex = nullptr;
64 };
65}
66
89class FScopeTryLock : private UE::TScopeTryLock<FCriticalSection>
90{
91public:
92 // Constructor that tries to lock the critical section.
96
97 // You must call IsLocked to test that the lock was acquired.
99};
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
T TNotNull
Definition NotNull.h:307
Definition ScopeTryLock.h:90
FScopeTryLock(TNotNull< FCriticalSection * > InCriticalSection)
Definition ScopeTryLock.h:93
Definition ScopeTryLock.h:36
UE_FORCEINLINE_HINT bool IsLocked()
Definition ScopeTryLock.h:54
~TScopeTryLock()
Definition ScopeTryLock.h:46
TScopeTryLock(MutexType &InMutex)
Definition ScopeTryLock.h:38
Definition AdvancedWidgetsModule.cpp:13