initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
44
thirdparty/jolt_physics/Jolt/Core/Atomics.h
vendored
Normal file
44
thirdparty/jolt_physics/Jolt/Core/Atomics.h
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
JPH_SUPPRESS_WARNINGS_STD_BEGIN
|
||||
#include <atomic>
|
||||
JPH_SUPPRESS_WARNINGS_STD_END
|
||||
|
||||
JPH_NAMESPACE_BEGIN
|
||||
|
||||
// Things we're using from STL
|
||||
using std::atomic;
|
||||
using std::memory_order;
|
||||
using std::memory_order_relaxed;
|
||||
using std::memory_order_acquire;
|
||||
using std::memory_order_release;
|
||||
using std::memory_order_acq_rel;
|
||||
using std::memory_order_seq_cst;
|
||||
|
||||
/// Atomically compute the min(ioAtomic, inValue) and store it in ioAtomic, returns true if value was updated
|
||||
template <class T>
|
||||
bool AtomicMin(atomic<T> &ioAtomic, const T inValue, const memory_order inMemoryOrder = memory_order_seq_cst)
|
||||
{
|
||||
T cur_value = ioAtomic.load(memory_order_relaxed);
|
||||
while (cur_value > inValue)
|
||||
if (ioAtomic.compare_exchange_weak(cur_value, inValue, inMemoryOrder))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Atomically compute the max(ioAtomic, inValue) and store it in ioAtomic, returns true if value was updated
|
||||
template <class T>
|
||||
bool AtomicMax(atomic<T> &ioAtomic, const T inValue, const memory_order inMemoryOrder = memory_order_seq_cst)
|
||||
{
|
||||
T cur_value = ioAtomic.load(memory_order_relaxed);
|
||||
while (cur_value < inValue)
|
||||
if (ioAtomic.compare_exchange_weak(cur_value, inValue, inMemoryOrder))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
JPH_NAMESPACE_END
|
Reference in New Issue
Block a user