From 2ed4486f212c7e5c8ac56c4d506546cf0c4f33b0 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Wed, 29 Jul 2020 10:14:57 +0200 Subject: [PATCH] cpu/esp32: cleanup of C++ hacks Since former ESP32 toolchain versions used POSIX threads, module `pthread` was required. The built-in `cxa_ctor_guards` had to be replaced since they used the `pthread_once` function for singleton objects initialization where the parameter `once` was of incompatible type with that provided by RIOT's `pthread` module. The current ESP32 toolchain version no longer uses POSIX threads. The dependency on module `pthread` as well as according C++ hacks can be removed. --- cpu/esp32/Makefile | 4 -- cpu/esp32/Makefile.dep | 6 -- cpu/esp32/Makefile.include | 1 - cpu/esp32/cxx/Makefile | 3 - cpu/esp32/cxx/cxa_guard.cpp | 111 ------------------------------------ 5 files changed, 125 deletions(-) delete mode 100644 cpu/esp32/cxx/Makefile delete mode 100644 cpu/esp32/cxx/cxa_guard.cpp diff --git a/cpu/esp32/Makefile b/cpu/esp32/Makefile index 15bb780b81..98fabe6378 100644 --- a/cpu/esp32/Makefile +++ b/cpu/esp32/Makefile @@ -6,10 +6,6 @@ DIRS += $(RIOTCPU)/esp_common DIRS += periph DIRS += vendor -ifneq (, $(filter esp_cxx, $(USEMODULE))) - DIRS += cxx -endif - ifneq (, $(filter esp_eth, $(USEMODULE))) DIRS += esp-eth endif diff --git a/cpu/esp32/Makefile.dep b/cpu/esp32/Makefile.dep index 4b9ec33314..e94e666b7f 100644 --- a/cpu/esp32/Makefile.dep +++ b/cpu/esp32/Makefile.dep @@ -8,11 +8,6 @@ USEMODULE += esp_idf_soc USEMODULE += newlib_nano USEMODULE += pm_layered -ifneq (,$(filter cpp,$(FEATURES_USED))) - USEMODULE += pthread - USEMODULE += esp_cxx -endif - ifneq (,$(filter esp_eth,$(USEMODULE))) USEMODULE += esp_freertos USEMODULE += esp_idf_eth @@ -41,7 +36,6 @@ endif ifneq (,$(filter esp_idf_nvs_flash,$(USEMODULE))) # add additional modules required by esp_idf_nvs_flash USEMODULE += mtd - USEMODULE += pthread endif ifneq (,$(filter periph_rtc,$(USEMODULE))) diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index 15030091d4..0e6fa68188 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -71,7 +71,6 @@ ifneq (,$(filter esp_now,$(USEMODULE))) endif ifneq (,$(filter cpp,$(FEATURES_USED))) - UNDEF += $(BINDIR)/esp_cxx/cxa_guard.o BASELIBS += -lstdc++ endif diff --git a/cpu/esp32/cxx/Makefile b/cpu/esp32/cxx/Makefile deleted file mode 100644 index 7593ffc7dd..0000000000 --- a/cpu/esp32/cxx/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE=esp_cxx - -include $(RIOTBASE)/Makefile.base diff --git a/cpu/esp32/cxx/cxa_guard.cpp b/cpu/esp32/cxx/cxa_guard.cpp deleted file mode 100644 index cbe8ed344f..0000000000 --- a/cpu/esp32/cxx/cxa_guard.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2018 Gunar Schorcht - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_esp32_cxx - * @{ - * - * @file - * @brief C++ functions for guarded initialization of static variables - * - * @author Gunar Schorcht - * - * This module implements very basic versions of the glibc++ functions - * `__cxa_guard_acquire` and `__cxa_guard_release`. These functions operate - * on guard variables that are used to realize thread-safe static object - * initialization. - * - * The glibc++ built-in versions of these functions had to be replaced since - * they use the `pthread_once` function from module `pthread` for singleton - * objects initialization where the parameter `once` is of incompatible type. - * - * The functions implemented by this module don't use a global mutex to - * avoid deadlocks. Instead, within the initialization of a static variable, - * creating a thread that in turn tries to initialize the same static variable - * is not allowed and results in an abort. - */ - -#include -#include -#include - -#include "assert.h" -#include "esp_common_log.h" -#include "irq.h" -#include "irq_arch.h" -#include "mutex.h" - -/** - * Structure of guard variable in glibc++ - * ((char*)&__guard)[0] == 1: _GLIBCXX_GUARD_BIT (static variable already initialized) - * ((char*)&__guard)[1] == 1: _GLIBCXX_GUARD_PENDING_BIT (static variable is being initialized) - * ((char*)&__guard)[2] == 1: _GLIBCXX_GUARD_WAITING_BIT (other thread is waiting) - */ -typedef struct { - char done; /* initialization is already done */ - char pending; /* initialization is in progress */ - char waiting; /* another thread is waiting until initialization is finished */ -} guard_t; - -namespace __cxxabiv1 -{ - extern "C" - int __cxa_guard_acquire (__guard *g) - { - guard_t *_gt = (guard_t *)g; - - assert(_gt); - - /* return if the static object is already initialized */ - if (_gt->done) { - return 0; - } - - critical_enter(); - - /* if another thread is already initializing the static object */ - if (_gt->pending) { - critical_exit(); - LOG_ERROR("Recursive static object initialization\n"); - assert(0); - } - - /* mark the initialization in process and acquire */ - _gt->pending = 1; - - critical_exit(); - return 1; - } - - extern "C" - void __cxa_guard_release (__guard *g) - { - guard_t *_gt = (guard_t *)g; - - assert(_gt); - assert(_gt->pending); - - critical_enter(); - - _gt->done = 1; - _gt->pending = 0; - - critical_exit(); - } - - extern "C" - void __cxa_guard_abort (__guard *g) - { - guard_t *_gt = (guard_t *)g; - - assert(_gt); - assert(_gt->pending); - - _gt->pending = 0; - } -}