forked from espressif/esp-idf
Merge branch 'fix/__atomic_test_and_set_v5.0' into 'release/v5.0'
fix(newlib): fix __atomic_test_and_set to ensure atomicity (v5.0) See merge request espressif/esp-idf!37454
This commit is contained in:
24
components/newlib/platform_include/stdatomic.h
Normal file
24
components/newlib/platform_include/stdatomic.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include_next "stdatomic.h"
|
||||||
|
#ifndef __clang__
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline bool __atomic_test_and_set(volatile void *ptr, int memorder)
|
||||||
|
{
|
||||||
|
return __atomic_exchange_1((bool *)ptr, true, memorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "unity_fixture.h"
|
#include "unity_fixture.h"
|
||||||
|
|
||||||
@@ -30,6 +31,18 @@ TEST_TEAR_DOWN(stdatomic)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(stdatomic, test_atomic_flag)
|
||||||
|
{
|
||||||
|
bool x8 = 0;
|
||||||
|
|
||||||
|
x8 = atomic_flag_test_and_set(&g_atomic8);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x00, x8);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x01, g_atomic8);
|
||||||
|
atomic_flag_clear(&g_atomic8);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x00, g_atomic8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(stdatomic, test_64bit_atomics)
|
TEST(stdatomic, test_64bit_atomics)
|
||||||
{
|
{
|
||||||
unsigned long long x64 = 0;
|
unsigned long long x64 = 0;
|
||||||
@@ -128,6 +141,7 @@ static void* exclusion_test_task(void *varg)
|
|||||||
|
|
||||||
TEST_GROUP_RUNNER(stdatomic)
|
TEST_GROUP_RUNNER(stdatomic)
|
||||||
{
|
{
|
||||||
|
RUN_TEST_CASE(stdatomic, test_atomic_flag)
|
||||||
RUN_TEST_CASE(stdatomic, test_64bit_atomics)
|
RUN_TEST_CASE(stdatomic, test_64bit_atomics)
|
||||||
RUN_TEST_CASE(stdatomic, test_32bit_atomics)
|
RUN_TEST_CASE(stdatomic, test_32bit_atomics)
|
||||||
RUN_TEST_CASE(stdatomic, test_16bit_atomics)
|
RUN_TEST_CASE(stdatomic, test_16bit_atomics)
|
||||||
|
Reference in New Issue
Block a user