change(pthread): changed pthread to not pull in init functions if not used

The pthread_init function would always get included in the binary,
even when no pthread functions were used.

This happens due to us using -u linker flags to force the linker to
consider the pthread library, to ensure the weak pthread functions in
the toolchain are overridden.

By restructing the code to rely on lazy inits instead we can avoid using
a init function, and therefor save some space.

Closes https://github.com/espressif/esp-idf/issues/14213
This commit is contained in:
Marius Vikhammer
2024-08-06 12:39:14 +08:00
parent a11aa9ce10
commit 385439213a
3 changed files with 53 additions and 36 deletions

View File

@@ -15,10 +15,21 @@
#include <errno.h>
#include "pthread.h"
static void *exit_task(void *args)
{
pthread_exit(NULL);
}
void setUp(void)
{
esp_pthread_cfg_t config = esp_pthread_get_default_config();
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_set_cfg(&config));
/* Needed to allocate the lazy allocated locks */
pthread_t pthread_object = (pthread_t)NULL;
TEST_ASSERT_EQUAL_INT(0, pthread_create(&pthread_object, NULL, exit_task, NULL));
TEST_ASSERT_EQUAL_INT(0, pthread_join(pthread_object, NULL));
test_utils_record_free_mem();
}