1 //===-- sanitizer_atomic_clang_other.h --------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
10 // Not intended for direct inclusion. Include sanitizer_atomic.h.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_ATOMIC_CLANG_OTHER_H
15 #define SANITIZER_ATOMIC_CLANG_OTHER_H
17 namespace __sanitizer
{
20 inline void proc_yield(int cnt
) {
21 __asm__
__volatile__("" ::: "memory");
25 inline typename
T::Type
atomic_load(
26 const volatile T
*a
, memory_order mo
) {
27 DCHECK(mo
& (memory_order_relaxed
| memory_order_consume
28 | memory_order_acquire
| memory_order_seq_cst
));
29 DCHECK(!((uptr
)a
% sizeof(*a
)));
32 if (sizeof(*a
) < 8 || sizeof(void*) == 8) {
33 // Assume that aligned loads are atomic.
34 if (mo
== memory_order_relaxed
) {
36 } else if (mo
== memory_order_consume
) {
37 // Assume that processor respects data dependencies
38 // (and that compiler won't break them).
39 __asm__
__volatile__("" ::: "memory");
41 __asm__
__volatile__("" ::: "memory");
42 } else if (mo
== memory_order_acquire
) {
43 __asm__
__volatile__("" ::: "memory");
47 // E.g. on POWER we need a hw fence even before the store.
53 __atomic_load(const_cast<typename
T::Type
volatile *>(&a
->val_dont_use
), &v
,
60 inline void atomic_store(volatile T
*a
, typename
T::Type v
, memory_order mo
) {
61 DCHECK(mo
& (memory_order_relaxed
| memory_order_release
62 | memory_order_seq_cst
));
63 DCHECK(!((uptr
)a
% sizeof(*a
)));
65 if (sizeof(*a
) < 8 || sizeof(void*) == 8) {
66 // Assume that aligned loads are atomic.
67 if (mo
== memory_order_relaxed
) {
69 } else if (mo
== memory_order_release
) {
72 __asm__
__volatile__("" ::: "memory");
79 __atomic_store(&a
->val_dont_use
, &v
, __ATOMIC_SEQ_CST
);
83 } // namespace __sanitizer
85 #endif // #ifndef SANITIZER_ATOMIC_CLANG_OTHER_H