2024-07-26 19:35:53 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* include/nuttx/atomic.h
|
|
|
|
*
|
2024-10-02 21:59:15 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2024-07-26 19:35:53 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you 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_NUTTX_ATOMIC_H
|
|
|
|
#define __INCLUDE_NUTTX_ATOMIC_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-07-29 21:20:05 +08:00
|
|
|
#ifdef __has_include
|
|
|
|
# if defined(__cplusplus) && __has_include(<atomic>)
|
2024-07-26 19:35:53 +08:00
|
|
|
extern "C++"
|
|
|
|
{
|
2024-07-29 21:20:05 +08:00
|
|
|
# include <atomic>
|
|
|
|
|
|
|
|
# define ATOMIC_VAR_INIT(value) (value)
|
|
|
|
|
2024-08-08 16:04:32 +08:00
|
|
|
using std::memory_order;
|
2024-07-29 21:20:05 +08:00
|
|
|
using std::atomic_bool;
|
|
|
|
using std::atomic_char;
|
|
|
|
using std::atomic_schar;
|
|
|
|
using std::atomic_uchar;
|
|
|
|
using std::atomic_short;
|
|
|
|
using std::atomic_ushort;
|
2024-07-26 19:35:53 +08:00
|
|
|
using std::atomic_int;
|
|
|
|
using std::atomic_uint;
|
2024-07-29 21:20:05 +08:00
|
|
|
using std::atomic_long;
|
|
|
|
using std::atomic_ulong;
|
|
|
|
using std::atomic_llong;
|
|
|
|
using std::atomic_ullong;
|
|
|
|
|
2024-07-26 19:35:53 +08:00
|
|
|
using std::atomic_load;
|
2024-07-29 21:20:05 +08:00
|
|
|
using std::atomic_load_explicit;
|
2024-07-26 19:35:53 +08:00
|
|
|
using std::atomic_store;
|
2024-07-29 21:20:05 +08:00
|
|
|
using std::atomic_store_explicit;
|
|
|
|
using std::atomic_exchange;
|
|
|
|
using std::atomic_exchange_explicit;
|
|
|
|
using std::atomic_compare_exchange_strong;
|
|
|
|
using std::atomic_compare_exchange_strong_explicit;
|
|
|
|
using std::atomic_compare_exchange_weak;
|
|
|
|
using std::atomic_compare_exchange_weak_explicit;
|
2024-08-08 16:04:32 +08:00
|
|
|
using std::atomic_flag_test_and_set;
|
|
|
|
using std::atomic_flag_test_and_set_explicit;
|
|
|
|
using std::atomic_flag_clear;
|
|
|
|
using std::atomic_flag_clear_explicit;
|
2024-07-26 19:35:53 +08:00
|
|
|
using std::atomic_fetch_add;
|
2024-07-29 21:20:05 +08:00
|
|
|
using std::atomic_fetch_add_explicit;
|
2024-07-26 19:35:53 +08:00
|
|
|
using std::atomic_fetch_sub;
|
2024-07-29 21:20:05 +08:00
|
|
|
using std::atomic_fetch_sub_explicit;
|
|
|
|
using std::atomic_fetch_and;
|
|
|
|
using std::atomic_fetch_and_explicit;
|
|
|
|
using std::atomic_fetch_or;
|
|
|
|
using std::atomic_fetch_or_explicit;
|
|
|
|
using std::atomic_fetch_xor;
|
|
|
|
using std::atomic_fetch_xor_explicit;
|
2024-07-26 19:35:53 +08:00
|
|
|
}
|
2024-08-08 16:04:32 +08:00
|
|
|
# elif __has_include(<stdatomic.h>) && \
|
|
|
|
((defined(__cplusplus) && __cplusplus >= 201103L) || \
|
|
|
|
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L))
|
2024-07-29 21:20:05 +08:00
|
|
|
# if !(__clang__) && defined(__cplusplus)
|
|
|
|
# define _Atomic
|
|
|
|
# endif
|
|
|
|
# include <stdbool.h>
|
|
|
|
# include <stdatomic.h>
|
2024-08-09 12:41:22 +08:00
|
|
|
# ifndef ATOMIC_VAR_INIT
|
|
|
|
# define ATOMIC_VAR_INIT(value) (value)
|
|
|
|
# endif
|
2024-07-29 21:20:05 +08:00
|
|
|
# else
|
|
|
|
# include <nuttx/lib/stdatomic.h>
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# include <nuttx/lib/stdatomic.h>
|
2024-07-26 19:35:53 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __INCLUDE_NUTTX_ATOMIC_H */
|