Path: blob/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_atomic.h
35233 views
//===-- sanitizer_atomic.h --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of ThreadSanitizer/AddressSanitizer runtime.9//10//===----------------------------------------------------------------------===//1112#ifndef SANITIZER_ATOMIC_H13#define SANITIZER_ATOMIC_H1415#include "sanitizer_internal_defs.h"1617namespace __sanitizer {1819enum memory_order {20// If the __atomic atomic builtins are supported (Clang/GCC), use the21// compiler provided macro values so that we can map the atomic operations22// to __atomic_* directly.23#ifdef __ATOMIC_SEQ_CST24memory_order_relaxed = __ATOMIC_RELAXED,25memory_order_consume = __ATOMIC_CONSUME,26memory_order_acquire = __ATOMIC_ACQUIRE,27memory_order_release = __ATOMIC_RELEASE,28memory_order_acq_rel = __ATOMIC_ACQ_REL,29memory_order_seq_cst = __ATOMIC_SEQ_CST30#else31memory_order_relaxed = 1 << 0,32memory_order_consume = 1 << 1,33memory_order_acquire = 1 << 2,34memory_order_release = 1 << 3,35memory_order_acq_rel = 1 << 4,36memory_order_seq_cst = 1 << 537#endif38};3940struct atomic_uint8_t {41typedef u8 Type;42volatile Type val_dont_use;43};4445struct atomic_uint16_t {46typedef u16 Type;47volatile Type val_dont_use;48};4950struct atomic_sint32_t {51typedef s32 Type;52volatile Type val_dont_use;53};5455struct atomic_uint32_t {56typedef u32 Type;57volatile Type val_dont_use;58};5960struct atomic_uint64_t {61typedef u64 Type;62// On 32-bit platforms u64 is not necessary aligned on 8 bytes.63alignas(8) volatile Type val_dont_use;64};6566struct atomic_uintptr_t {67typedef uptr Type;68volatile Type val_dont_use;69};7071} // namespace __sanitizer7273#if defined(__clang__) || defined(__GNUC__)74# include "sanitizer_atomic_clang.h"75#elif defined(_MSC_VER)76# include "sanitizer_atomic_msvc.h"77#else78# error "Unsupported compiler"79#endif8081namespace __sanitizer {8283// Clutter-reducing helpers.8485template<typename T>86inline typename T::Type atomic_load_relaxed(const volatile T *a) {87return atomic_load(a, memory_order_relaxed);88}8990template<typename T>91inline void atomic_store_relaxed(volatile T *a, typename T::Type v) {92atomic_store(a, v, memory_order_relaxed);93}9495} // namespace __sanitizer9697#endif // SANITIZER_ATOMIC_H9899100