chromium/third_party/perfetto/include/perfetto/public/abi/atomic.h

/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef INCLUDE_PERFETTO_PUBLIC_ABI_ATOMIC_H_
#define INCLUDE_PERFETTO_PUBLIC_ABI_ATOMIC_H_

// Problem: C++11 and C11 use a different syntax for atomics and the C11 syntax
// is not supported in C++11.
//
// This header bridges the gap.
//
// This assumes that C++11 atomics are binary compatible with C11 atomics. While
// this is technically not required by the standards, reasonable compilers
// appear to guarantee this.

#ifdef __cplusplus
#include <atomic>
#else
#include <stdatomic.h>
#endif

#ifdef __cplusplus
#define PERFETTO_ATOMIC(TYPE)
#else
#define PERFETTO_ATOMIC
#endif

#ifdef __cplusplus
#define PERFETTO_ATOMIC_LOAD
#define PERFETTO_ATOMIC_LOAD_EXPLICIT
#define PERFETTO_ATOMIC_STORE
#define PERFETTO_ATOMIC_STORE_EXPLICIT

#define PERFETTO_MEMORY_ORDER_ACQ_REL
#define PERFETTO_MEMORY_ORDER_ACQUIRE
#define PERFETTO_MEMORY_ORDER_CONSUME
#define PERFETTO_MEMORY_ORDER_RELAXED
#define PERFETTO_MEMORY_ORDER_RELEASE
#define PERFETTO_MEMORY_ORDER_SEQ_CST
#else
#define PERFETTO_ATOMIC_LOAD
#define PERFETTO_ATOMIC_LOAD_EXPLICIT
#define PERFETTO_ATOMIC_STORE
#define PERFETTO_ATOMIC_STORE_EXPLICIT

#define PERFETTO_MEMORY_ORDER_ACQ_REL
#define PERFETTO_MEMORY_ORDER_ACQUIRE
#define PERFETTO_MEMORY_ORDER_CONSUME
#define PERFETTO_MEMORY_ORDER_RELAXED
#define PERFETTO_MEMORY_ORDER_RELEASE
#define PERFETTO_MEMORY_ORDER_SEQ_CST
#endif

#endif  // INCLUDE_PERFETTO_PUBLIC_ABI_ATOMIC_H_