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.
This commit is contained in:
parent
107356ec5d
commit
2ed4486f21
@ -6,10 +6,6 @@ DIRS += $(RIOTCPU)/esp_common
|
|||||||
DIRS += periph
|
DIRS += periph
|
||||||
DIRS += vendor
|
DIRS += vendor
|
||||||
|
|
||||||
ifneq (, $(filter esp_cxx, $(USEMODULE)))
|
|
||||||
DIRS += cxx
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (, $(filter esp_eth, $(USEMODULE)))
|
ifneq (, $(filter esp_eth, $(USEMODULE)))
|
||||||
DIRS += esp-eth
|
DIRS += esp-eth
|
||||||
endif
|
endif
|
||||||
|
|||||||
@ -8,11 +8,6 @@ USEMODULE += esp_idf_soc
|
|||||||
USEMODULE += newlib_nano
|
USEMODULE += newlib_nano
|
||||||
USEMODULE += pm_layered
|
USEMODULE += pm_layered
|
||||||
|
|
||||||
ifneq (,$(filter cpp,$(FEATURES_USED)))
|
|
||||||
USEMODULE += pthread
|
|
||||||
USEMODULE += esp_cxx
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter esp_eth,$(USEMODULE)))
|
ifneq (,$(filter esp_eth,$(USEMODULE)))
|
||||||
USEMODULE += esp_freertos
|
USEMODULE += esp_freertos
|
||||||
USEMODULE += esp_idf_eth
|
USEMODULE += esp_idf_eth
|
||||||
@ -41,7 +36,6 @@ endif
|
|||||||
ifneq (,$(filter esp_idf_nvs_flash,$(USEMODULE)))
|
ifneq (,$(filter esp_idf_nvs_flash,$(USEMODULE)))
|
||||||
# add additional modules required by esp_idf_nvs_flash
|
# add additional modules required by esp_idf_nvs_flash
|
||||||
USEMODULE += mtd
|
USEMODULE += mtd
|
||||||
USEMODULE += pthread
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter periph_rtc,$(USEMODULE)))
|
ifneq (,$(filter periph_rtc,$(USEMODULE)))
|
||||||
|
|||||||
@ -71,7 +71,6 @@ ifneq (,$(filter esp_now,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter cpp,$(FEATURES_USED)))
|
ifneq (,$(filter cpp,$(FEATURES_USED)))
|
||||||
UNDEF += $(BINDIR)/esp_cxx/cxa_guard.o
|
|
||||||
BASELIBS += -lstdc++
|
BASELIBS += -lstdc++
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
MODULE=esp_cxx
|
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.base
|
|
||||||
@ -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 <gunar@schorcht.net>
|
|
||||||
*
|
|
||||||
* 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 <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <cxxabi.h>
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user