Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ThreadSafeBool.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"
6#include "HAL/ThreadSafeCounter.h"
7
8////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9// DEPRECATED. Please use `std::atomic<bool>`
10////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
12/**
13 * Thread safe bool, wraps FThreadSafeCounter
14 */
16 : private FThreadSafeCounter
17{
18public:
19 /**
20 * Constructor optionally takes value to initialize with, otherwise initializes false
21 * @param bValue Value to initialize with
22 */
23 FThreadSafeBool(bool bValue = false)
24 : FThreadSafeCounter(bValue ? 1 : 0)
25 {}
26
27 /**
28 * Operator to use this struct as a bool with thread safety
29 */
30 FORCEINLINE operator bool() const
31 {
32 return GetValue() != 0;
33 }
34
35 /**
36 * Operator to set the bool value with thread safety
37 */
38 FORCEINLINE bool operator=(bool bNewValue)
39 {
40 Set(bNewValue ? 1 : 0);
41 return bNewValue;
42 }
43
44 /**
45 * Sets a new value atomically, and returns the old value.
46 *
47 * @param bNewValue Value to set
48 * @return The old value
49 */
50 FORCEINLINE bool AtomicSet(bool bNewValue)
51 {
52 return Set(bNewValue ? 1 : 0) != 0;
53 }
54};
#define FORCEINLINE
Definition Platform.h:644
FORCEINLINE bool AtomicSet(bool bNewValue)
FORCEINLINE operator bool() const
FThreadSafeBool(bool bValue=false)
FORCEINLINE bool operator=(bool bNewValue)
FThreadSafeCounter(int32 Value)
int32 Set(int32 Value)