Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
PThreadCriticalSection.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 <pthread.h>
9#include <errno.h>
10
11
12/**
13 * This is the PThreads version of a critical section. It uses pthreads
14 * to implement its locking.
15 */
17{
18 /**
19 * The pthread-specific critical section
20 */
22
23public:
24
25 /**
26 * Constructor that initializes the aggregated critical section
27 */
29 {
30 // make a recursive mutex
31 pthread_mutexattr_t MutexAttributes;
32 pthread_mutexattr_init(&MutexAttributes);
33 pthread_mutexattr_settype(&MutexAttributes, PTHREAD_MUTEX_RECURSIVE);
34 pthread_mutex_init(&Mutex, &MutexAttributes);
35 pthread_mutexattr_destroy(&MutexAttributes);
36 }
37
38 /**
39 * Destructor cleaning up the critical section
40 */
42 {
43 pthread_mutex_destroy(&Mutex);
44 }
45
46 /**
47 * Locks the critical section
48 */
49 FORCEINLINE void Lock(void)
50 {
51 pthread_mutex_lock(&Mutex);
52 }
53
54 /**
55 * Attempt to take a lock and returns whether or not a lock was taken.
56 *
57 * @return true if a lock was taken, false otherwise.
58 */
60 {
61 return 0 == pthread_mutex_trylock(&Mutex);
62 }
63
64 /**
65 * Releases the lock on the critical seciton
66 */
68 {
69 pthread_mutex_unlock(&Mutex);
70 }
71
72private:
75};
#define FORCEINLINE
Definition Platform.h:644
FORCEINLINE void Lock(void)
FORCEINLINE ~FPThreadsCriticalSection(void)
FORCEINLINE void Unlock(void)
FORCEINLINE FPThreadsCriticalSection(void)
FPThreadsCriticalSection & operator=(const FPThreadsCriticalSection &)
FPThreadsCriticalSection(const FPThreadsCriticalSection &)