sys: atomic: Fix includes, create atomic_types.h

This patch fixes the include of `atomic_builtin.h` and `atomic_arch.h`
so that they are IWYU. This mean they compile correctly independent of
other includes at the include-site. It was nessessary to move the
definition of the atomic types out of `atomic.h` to avoid unsatifiable
circular dependencies between `atomic.h` and `atomic_builtin.h`, as well
as definition conflicts between `atomic_arch.h` and `atomic_builtin.h`.
The definition of the type was to moved to a new file `atomic_types.h`.

The include in `atomic.h` has a IWYU pragma which will preserve
backwards compatibility with code expecting the types to be defined in
`atomic.h` if we start linting for IWYU.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
This commit is contained in:
Aleksander Wasaznik 2023-11-16 10:03:06 +01:00 committed by Fabio Baltieri
parent 46bbe052d3
commit 4e976e0d58
4 changed files with 34 additions and 5 deletions

View File

@ -1,6 +1,7 @@
/*
* Copyright (c) 1997-2015, Wind River Systems, Inc.
* Copyright (c) 2021 Intel Corporation
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -12,6 +13,7 @@
#include <zephyr/toolchain.h>
#include <stddef.h>
#include <zephyr/sys/atomic_types.h> /* IWYU pragma: export */
#include <zephyr/types.h>
#include <zephyr/sys/util_macro.h>
@ -19,11 +21,6 @@
extern "C" {
#endif
typedef long atomic_t;
typedef atomic_t atomic_val_t;
typedef void *atomic_ptr_t;
typedef atomic_ptr_t atomic_ptr_val_t;
/* Low-level primitives come in several styles: */
#if defined(CONFIG_ATOMIC_OPERATIONS_C)

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021 Demant A/S
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -7,6 +8,9 @@
#ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_ARCH_H_
#define ZEPHYR_INCLUDE_SYS_ATOMIC_ARCH_H_
#include <stdbool.h>
#include <zephyr/sys/atomic_types.h>
/* Included from <atomic.h> */
/* Arch specific atomic primitives */

View File

@ -2,6 +2,7 @@
/*
* Copyright (c) 1997-2015, Wind River Systems, Inc.
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -9,6 +10,9 @@
#ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_BUILTIN_H_
#define ZEPHYR_INCLUDE_SYS_ATOMIC_BUILTIN_H_
#include <stdbool.h>
#include <zephyr/sys/atomic_types.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -0,0 +1,24 @@
/* Copyright (c) 1997-2015, Wind River Systems, Inc.
* Copyright (c) 2021 Intel Corporation
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_TYPES_H_
#define ZEPHYR_INCLUDE_SYS_ATOMIC_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef long atomic_t;
typedef atomic_t atomic_val_t;
typedef void *atomic_ptr_t;
typedef atomic_ptr_t atomic_ptr_val_t;
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_TYPES_H_ */