| * Copyright (c) 2020 Intel Corporation. |
| * SPDX-License-Identifier: Apache-2.0 |
| #include <zephyr/kernel.h> |
| #include <zephyr/sys/atomic.h> |
| #include <zephyr/timing/timing.h> |
| static atomic_val_t started_ref; |
| #if defined(CONFIG_BOARD_HAS_TIMING_FUNCTIONS) |
| #elif defined(CONFIG_SOC_HAS_TIMING_FUNCTIONS) |
| if (atomic_inc(&started_ref) != 0) { |
| #if defined(CONFIG_BOARD_HAS_TIMING_FUNCTIONS) |
| #elif defined(CONFIG_SOC_HAS_TIMING_FUNCTIONS) |
| atomic_t old_value, new_value; |
| /* Make sure this does decrement past zero. */ |
| old_value = atomic_get(&started_ref); |
| new_value = old_value - 1; |
| } while (atomic_cas(&started_ref, old_value, new_value) == 0); |
| * new_value may be uninitialized, so use old_value here. |
| #if defined(CONFIG_BOARD_HAS_TIMING_FUNCTIONS) |
| #elif defined(CONFIG_SOC_HAS_TIMING_FUNCTIONS) |