diff --git a/components/pthread/CMakeLists.txt b/components/pthread/CMakeLists.txt index d488c92a9d..136bf9cf1c 100644 --- a/components/pthread/CMakeLists.txt +++ b/components/pthread/CMakeLists.txt @@ -3,6 +3,16 @@ idf_component_register(SRCS "pthread.c" "pthread_local_storage.c" INCLUDE_DIRS include) +if(GCC_NOT_5_2_0) + set(extra_link_flags "-u pthread_include_pthread_impl") + list(APPEND extra_link_flags "-u pthread_include_pthread_cond_impl") + list(APPEND extra_link_flags "-u pthread_include_pthread_local_storage_impl") +endif() + if(CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP) target_link_libraries(${COMPONENT_LIB} "-Wl,--wrap=vPortCleanUpTCB") endif() + +if(extra_link_flags) + target_link_libraries(${COMPONENT_LIB} INTERFACE "${extra_link_flags}") +endif() diff --git a/components/pthread/Kconfig b/components/pthread/Kconfig index 61fa8a33e6..20e3f6123f 100644 --- a/components/pthread/Kconfig +++ b/components/pthread/Kconfig @@ -1,46 +1,46 @@ menu "PThreads" - config ESP32_PTHREAD_TASK_PRIO_DEFAULT + config PTHREAD_TASK_PRIO_DEFAULT int "Default task priority" range 0 255 default 5 help Priority used to create new tasks with default pthread parameters. - config ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT + config PTHREAD_TASK_STACK_SIZE_DEFAULT int "Default task stack size" default 3072 help Stack size used to create new tasks with default pthread parameters. - config ESP32_PTHREAD_STACK_MIN + config PTHREAD_STACK_MIN int "Minimum allowed pthread stack size" default 768 help Minimum allowed pthread stack size set in attributes passed to pthread_create - choice ESP32_PTHREAD_TASK_CORE_DEFAULT + choice PTHREAD_TASK_CORE_DEFAULT bool "Default pthread core affinity" - default ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY + default PTHREAD_DEFAULT_CORE_NO_AFFINITY depends on !FREERTOS_UNICORE help The default core to which pthreads are pinned. - config ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY + config PTHREAD_DEFAULT_CORE_NO_AFFINITY bool "No affinity" - config ESP32_DEFAULT_PTHREAD_CORE_0 + config PTHREAD_DEFAULT_CORE_0 bool "Core 0" - config ESP32_DEFAULT_PTHREAD_CORE_1 + config PTHREAD_DEFAULT_CORE_1 bool "Core 1" endchoice - config ESP32_PTHREAD_TASK_CORE_DEFAULT + config PTHREAD_TASK_CORE_DEFAULT int - default -1 if ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY || FREERTOS_UNICORE - default 0 if ESP32_DEFAULT_PTHREAD_CORE_0 - default 1 if ESP32_DEFAULT_PTHREAD_CORE_1 + default -1 if PTHREAD_DEFAULT_CORE_NO_AFFINITY || FREERTOS_UNICORE + default 0 if PTHREAD_DEFAULT_CORE_0 + default 1 if PTHREAD_DEFAULT_CORE_1 - config ESP32_PTHREAD_TASK_NAME_DEFAULT + config PTHREAD_TASK_NAME_DEFAULT string "Default name of pthreads" default "pthread" help diff --git a/components/pthread/component.mk b/components/pthread/component.mk index 9c3eececf5..c5793fded6 100644 --- a/components/pthread/component.mk +++ b/components/pthread/component.mk @@ -11,3 +11,11 @@ COMPONENT_ADD_LDFLAGS := -lpthread ifdef CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP COMPONENT_ADD_LDFLAGS += -Wl,--wrap=vPortCleanUpTCB endif + +ifeq ($(GCC_NOT_5_2_0), 1) +# Forces the linker to include pthread implementation from this component, +# instead of the weak implementations provided by libgcc. +COMPONENT_ADD_LDFLAGS += -u pthread_include_pthread_impl +COMPONENT_ADD_LDFLAGS += -u pthread_include_pthread_cond_impl +COMPONENT_ADD_LDFLAGS += -u pthread_include_pthread_local_storage_impl +endif # GCC_NOT_5_2_0 diff --git a/components/pthread/include/esp_pthread.h b/components/pthread/include/esp_pthread.h index ca93c9c380..76f45a32ab 100644 --- a/components/pthread/include/esp_pthread.h +++ b/components/pthread/include/esp_pthread.h @@ -22,7 +22,7 @@ extern "C" { #endif #ifndef PTHREAD_STACK_MIN -#define PTHREAD_STACK_MIN CONFIG_ESP32_PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN #endif /** pthread configuration structure that influences pthread creation */ diff --git a/components/pthread/pthread.c b/components/pthread/pthread.c index 84997c9aad..ce0c064ce3 100644 --- a/components/pthread/pthread.c +++ b/components/pthread/pthread.c @@ -170,14 +170,14 @@ esp_err_t esp_pthread_get_cfg(esp_pthread_cfg_t *p) static int get_default_pthread_core() { - return CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT == -1 ? tskNO_AFFINITY : CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT; + return CONFIG_PTHREAD_TASK_CORE_DEFAULT == -1 ? tskNO_AFFINITY : CONFIG_PTHREAD_TASK_CORE_DEFAULT; } esp_pthread_cfg_t esp_pthread_get_default_config() { esp_pthread_cfg_t cfg = { - .stack_size = CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT, - .prio = CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT, + .stack_size = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT, + .prio = CONFIG_PTHREAD_TASK_PRIO_DEFAULT, .inherit_cfg = false, .thread_name = NULL, .pin_to_core = get_default_pthread_core() @@ -233,10 +233,10 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, return ENOMEM; } - uint32_t stack_size = CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT; - BaseType_t prio = CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT; + uint32_t stack_size = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT; + BaseType_t prio = CONFIG_PTHREAD_TASK_PRIO_DEFAULT; BaseType_t core_id = get_default_pthread_core(); - const char *task_name = CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT; + const char *task_name = CONFIG_PTHREAD_TASK_NAME_DEFAULT; esp_pthread_cfg_t *pthread_cfg = pthread_getspecific(s_pthread_cfg_key); if (pthread_cfg) { @@ -256,7 +256,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, task_name = pthread_cfg->thread_name; } } else if (pthread_cfg->thread_name == NULL) { - task_name = CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT; + task_name = CONFIG_PTHREAD_TASK_NAME_DEFAULT; } else { task_name = pthread_cfg->thread_name; } @@ -758,7 +758,7 @@ int pthread_attr_init(pthread_attr_t *attr) { if (attr) { /* Nothing to allocate. Set everything to default */ - attr->stacksize = CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT; + attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT; attr->detachstate = PTHREAD_CREATE_JOINABLE; return 0; } @@ -769,7 +769,7 @@ int pthread_attr_destroy(pthread_attr_t *attr) { if (attr) { /* Nothing to deallocate. Reset everything to default */ - attr->stacksize = CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT; + attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT; attr->detachstate = PTHREAD_CREATE_JOINABLE; return 0; } @@ -820,3 +820,8 @@ int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) } return EINVAL; } + +/* Hook function to force linking this file */ +void pthread_include_pthread_impl() +{ +} diff --git a/components/pthread/pthread_cond_var.c b/components/pthread/pthread_cond_var.c index fe3144512d..8db28ae5e1 100644 --- a/components/pthread/pthread_cond_var.c +++ b/components/pthread/pthread_cond_var.c @@ -198,3 +198,8 @@ int pthread_cond_destroy(pthread_cond_t *cv) return ret; } + +/* Hook function to force linking this file */ +void pthread_include_pthread_cond_var_impl() +{ +} diff --git a/components/pthread/pthread_local_storage.c b/components/pthread/pthread_local_storage.c index 5e2dbafd21..ecf252e4cc 100644 --- a/components/pthread/pthread_local_storage.c +++ b/components/pthread/pthread_local_storage.c @@ -255,3 +255,8 @@ int pthread_setspecific(pthread_key_t key, const void *value) return 0; } + +/* Hook function to force linking this file */ +void pthread_include_pthread_local_storage_impl() +{ +} diff --git a/components/pthread/sdkconfig.rename b/components/pthread/sdkconfig.rename index b72b647076..fb5c0ff34c 100644 --- a/components/pthread/sdkconfig.rename +++ b/components/pthread/sdkconfig.rename @@ -1,4 +1,11 @@ # sdkconfig replacement configurations for deprecated options formatted as # CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION -CONFIG_PTHREAD_STACK_MIN CONFIG_ESP32_PTHREAD_STACK_MIN +CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT CONFIG_PTHREAD_TASK_PRIO_DEFAULT +CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT +CONFIG_ESP32_PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN +CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT CONFIG_PTHREAD_TASK_CORE_DEFAULT +CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY +CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0 CONFIG_PTHREAD_DEFAULT_CORE_0 +CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1 CONFIG_PTHREAD_DEFAULT_CORE_1 +CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT CONFIG_PTHREAD_TASK_NAME_DEFAULT diff --git a/tools/ldgen/samples/sdkconfig b/tools/ldgen/samples/sdkconfig index 075841ea81..43c81dd18a 100644 --- a/tools/ldgen/samples/sdkconfig +++ b/tools/ldgen/samples/sdkconfig @@ -483,8 +483,8 @@ CONFIG_OPENSSL_ASSERT_EXIT= # # PThreads # -CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5 -CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 +CONFIG_PTHREAD_TASK_PRIO_DEFAULT=5 +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 # # SPI Flash driver