mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
fix(cxx): fix TLS classes destructor call
Closes https://github.com/espressif/esp-idf/issues/14360
This commit is contained in:
@@ -197,7 +197,7 @@ struct PriorityInitTest {
|
||||
|
||||
int PriorityInitTest::order = 0;
|
||||
|
||||
// init_priority objects are initialized from the lowest to the heighest priority number
|
||||
// init_priority objects are initialized from the lowest to the highest priority number
|
||||
// Default init_priority is always the lowest (highest priority number)
|
||||
PriorityInitTest g_static_init_priority_test2;
|
||||
PriorityInitTest g_static_init_priority_test1 __attribute__((init_priority(1000)));
|
||||
@@ -243,6 +243,36 @@ TEST_CASE("can use std::vector", "[misc]")
|
||||
TEST_ASSERT_EQUAL(51, std::accumulate(std::begin(v), std::end(v), 0));
|
||||
}
|
||||
|
||||
static volatile bool is_tls_class_destructor_called;
|
||||
struct TestTLS {
|
||||
TestTLS() { }
|
||||
~TestTLS()
|
||||
{
|
||||
is_tls_class_destructor_called = true;
|
||||
}
|
||||
void foo() { }
|
||||
};
|
||||
|
||||
thread_local TestTLS s_testTLS;
|
||||
|
||||
void test_thread_local_destructors(void * arg)
|
||||
{
|
||||
s_testTLS.foo();
|
||||
xSemaphoreGive(s_slow_init_sem);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
TEST_CASE("call destructors for thread_local classes CXX", "[misc]")
|
||||
{
|
||||
is_tls_class_destructor_called = false;
|
||||
s_slow_init_sem = xSemaphoreCreateCounting(1, 0);
|
||||
xTaskCreate(test_thread_local_destructors, "test_thread_local_destructors", 2048, NULL, 10, NULL);
|
||||
vTaskDelay(1); /* Triggers IDLE task to call prvCheckTasksWaitingTermination() which cleans task-specific data */
|
||||
TEST_ASSERT_TRUE(xSemaphoreTake(s_slow_init_sem, 500 / portTICK_PERIOD_MS));
|
||||
vSemaphoreDelete(s_slow_init_sem);
|
||||
TEST_ASSERT_TRUE(is_tls_class_destructor_called);
|
||||
}
|
||||
|
||||
/* These test cases pull a lot of code from libstdc++ and are disabled for now
|
||||
*/
|
||||
#if 0
|
||||
@@ -291,6 +321,7 @@ TEST_CASE("stack smashing protection CXX", "[stack_smash]")
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
s_testTLS.foo(); /* allocates memory that will be reused */
|
||||
printf("CXX GENERAL TEST\n");
|
||||
unity_run_menu();
|
||||
}
|
||||
|
Reference in New Issue
Block a user