UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PThreadsSharedMutex.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_UNSUPPORTED - Unsupported platform
6
7#include "CoreTypes.h"
8
9#if PLATFORM_USE_PTHREADS
10
12#include <pthread.h>
13#include <errno.h>
14
15namespace UE
16{
17
23class FPThreadsSharedMutex final
24{
25public:
27 FPThreadsSharedMutex& operator=(const FPThreadsSharedMutex&) = delete;
28
30 {
31 int Err = pthread_rwlock_init(&Mutex, nullptr);
32 checkf(Err == 0, TEXT("pthread_rwlock_init failed with error: %d"), Err);
33 }
34
36 {
37 int Err = pthread_rwlock_destroy(&Mutex);
38 checkf(Err == 0, TEXT("pthread_rwlock_destroy failed with error: %d"), Err);
39 }
40
41 bool TryLock()
42 {
43 int Err = pthread_rwlock_trywrlock(&Mutex);
44 return Err == 0;
45 }
46
47 void Lock()
48 {
49 int Err = pthread_rwlock_wrlock(&Mutex);
50 checkf(Err == 0, TEXT("pthread_rwlock_wrlock failed with error: %d"), Err);
51 }
52
53 void Unlock()
54 {
55 int Err = pthread_rwlock_unlock(&Mutex);
56 checkf(Err == 0, TEXT("pthread_rwlock_unlock failed with error: %d"), Err);
57 }
58
59 bool TryLockShared()
60 {
61 int Err = pthread_rwlock_tryrdlock(&Mutex);
62 return Err == 0;
63 }
64
65 void LockShared()
66 {
67 int Err = pthread_rwlock_rdlock(&Mutex);
68 checkf(Err == 0, TEXT("pthread_rwlock_rdlock failed with error: %d"), Err);
69 }
70
71 void UnlockShared()
72 {
73 int Err = pthread_rwlock_unlock(&Mutex);
74 checkf(Err == 0, TEXT("pthread_rwlock_unlock failed with error: %d"), Err);
75 }
76
77private:
79};
80
81} // UE
82
83#endif // PLATFORM_USE_PTHREADS
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
UE::FRecursiveMutex Mutex
Definition MeshPaintVirtualTexture.cpp:164
Definition AdvancedWidgetsModule.cpp:13
void Err()
Definition VerseGrammar.h:63