Path: blob/master/thirdparty/embree/common/sys/atomic.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include <atomic>6#include "intrinsics.h"78namespace embree9{10/* compiler memory barriers */11#if defined(__INTEL_COMPILER)12//#define __memory_barrier() __memory_barrier()13#elif defined(__GNUC__) || defined(__clang__)14# define __memory_barrier() asm volatile("" ::: "memory")15#elif defined(_MSC_VER)16# define __memory_barrier() _ReadWriteBarrier()17#endif1819template <typename T>20struct atomic : public std::atomic<T>21{22atomic () {}2324atomic (const T& a)25: std::atomic<T>(a) {}2627atomic (const atomic<T>& a) {28this->store(a.load());29}3031atomic& operator=(const atomic<T>& other) {32this->store(other.load());33return *this;34}35};3637template<typename T>38__forceinline void _atomic_min(std::atomic<T>& aref, const T& bref)39{40const T b = bref.load();41while (true) {42T a = aref.load();43if (a <= b) break;44if (aref.compare_exchange_strong(a,b)) break;45}46}4748template<typename T>49__forceinline void _atomic_max(std::atomic<T>& aref, const T& bref)50{51const T b = bref.load();52while (true) {53T a = aref.load();54if (a >= b) break;55if (aref.compare_exchange_strong(a,b)) break;56}57}58}596061