Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
PThreadRWLock.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#include "Misc/AssertionMacros.h"
9#include <pthread.h>
10#include <errno.h>
11
12/**
13 * FPThreadsRWLock - Read/Write Mutex
14 * - Provides non-recursive Read/Write (or shared-exclusive) access.
15 */
17{
18public:
21
23 {
24 int Err = pthread_rwlock_init(&Mutex, nullptr);
25 checkf(Err == 0, TEXT("pthread_rwlock_init failed with error: %d"), Err);
26 }
27
29 {
30 int Err = pthread_rwlock_destroy(&Mutex);
31 checkf(Err == 0, TEXT("pthread_rwlock_destroy failed with error: %d"), Err);
32 }
33
34 void ReadLock()
35 {
36 int Err = pthread_rwlock_rdlock(&Mutex);
37 checkf(Err == 0, TEXT("pthread_rwlock_rdlock failed with error: %d"), Err);
38 }
39
40 void WriteLock()
41 {
42 int Err = pthread_rwlock_wrlock(&Mutex);
43 checkf(Err == 0, TEXT("pthread_rwlock_wrlock failed with error: %d"), Err);
44 }
45
47 {
48 int Err = pthread_rwlock_tryrdlock(&Mutex);
49 return Err == 0;
50 }
51
53 {
54 int Err = pthread_rwlock_trywrlock(&Mutex);
55 return Err == 0;
56 }
57
59 {
60 int Err = pthread_rwlock_unlock(&Mutex);
61 checkf(Err == 0, TEXT("pthread_rwlock_unlock failed with error: %d"), Err);
62 }
63
65 {
66 int Err = pthread_rwlock_unlock(&Mutex);
67 checkf(Err == 0, TEXT("pthread_rwlock_unlock failed with error: %d"), Err);
68 }
69
70private:
72};
#define checkf(expr, format,...)
pthread_rwlock_t Mutex
FPThreadsRWLock(const FPThreadsRWLock &)=delete
FPThreadsRWLock & operator=(const FPThreadsRWLock &)=delete