From d3ab90ba247bb7d484936b869d1f90fc32e9dcc7 Mon Sep 17 00:00:00 2001 From: Cristian Funes Date: Fri, 9 Aug 2024 11:50:01 -0300 Subject: [PATCH] fix(pthread): Fix cxx pthread example build for linux platform Closes https://github.com/espressif/esp-idf/pull/14339 --- components/pthread/CMakeLists.txt | 6 ++- components/pthread/port/linux/pthread.c | 43 +++++++++++++++++++ .../generic_build_test/main/CMakeLists.txt | 3 +- .../main/generic_build_test.c | 5 +++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 components/pthread/port/linux/pthread.c diff --git a/components/pthread/CMakeLists.txt b/components/pthread/CMakeLists.txt index aa1738aa67f9..b6891f2aa888 100644 --- a/components/pthread/CMakeLists.txt +++ b/components/pthread/CMakeLists.txt @@ -1,7 +1,9 @@ idf_build_get_property(target IDF_TARGET) if(${target} STREQUAL "linux") - # Make pthread component an empty interface lib referencing host pthread for Linux target - idf_component_register() + set(sources "port/linux/pthread.c") + idf_component_register( + SRCS ${sources} + INCLUDE_DIRS include) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(${COMPONENT_LIB} INTERFACE Threads::Threads) diff --git a/components/pthread/port/linux/pthread.c b/components/pthread/port/linux/pthread.c new file mode 100644 index 000000000000..e5646da4d5a5 --- /dev/null +++ b/components/pthread/port/linux/pthread.c @@ -0,0 +1,43 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* + * pthread port for Linux build + */ + +#include "esp_pthread.h" +#include + +/** + * @brief Creates a default pthread configuration based + * on the values set via menuconfig. + * + * @return + * A default configuration structure. + */ +esp_pthread_cfg_t esp_pthread_get_default_config(void) +{ + esp_pthread_cfg_t cfg = { + .stack_size = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT, + .prio = CONFIG_PTHREAD_TASK_PRIO_DEFAULT, + .inherit_cfg = false, + .thread_name = NULL, + .pin_to_core = 0, + .stack_alloc_caps = 0, + }; + + return cfg; +} + +esp_err_t esp_pthread_set_cfg(const esp_pthread_cfg_t *cfg) +{ + return ESP_OK; +} + +esp_err_t esp_pthread_get_cfg(esp_pthread_cfg_t *p) +{ + memset(p, 0, sizeof(*p)); + return ESP_ERR_NOT_FOUND; +} diff --git a/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt b/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt index c19f364742ef..9a48d274dc2a 100644 --- a/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt +++ b/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt @@ -1,2 +1,3 @@ idf_component_register(SRCS "generic_build_test.c" - INCLUDE_DIRS ".") + INCLUDE_DIRS "." + PRIV_REQUIRES pthread) diff --git a/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c b/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c index 6177434f3318..ee978ba21164 100644 --- a/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c +++ b/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c @@ -8,8 +8,13 @@ #include #include "inttypes_ext.h" +#include "esp_pthread.h" + void app_main(void) { size_t size = 47; printf("size is: %" PRIuSIZE "\n", size); // test IDF's PRIuSIZE + + esp_pthread_cfg_t pthread_config = esp_pthread_get_default_config(); + (void)pthread_config; }