mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-07-15 08:32:42 +08:00
feat(freertos): add thread local private "errno"
This commit is contained in:
@ -3490,6 +3490,24 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
|
||||
return pvReturn;
|
||||
}
|
||||
|
||||
void **pvTaskGetThreadLocalStorageBufferPointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex )
|
||||
{
|
||||
void **pvReturn = NULL;
|
||||
TCB_t *pxTCB;
|
||||
|
||||
if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )
|
||||
{
|
||||
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
|
||||
pvReturn = &pxTCB->pvThreadLocalStoragePointers[ xIndex ];
|
||||
}
|
||||
else
|
||||
{
|
||||
pvReturn = NULL;
|
||||
}
|
||||
|
||||
return pvReturn;
|
||||
}
|
||||
|
||||
#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
@ -1458,6 +1458,7 @@ constant. */
|
||||
used to set and query a pointer respectively. */
|
||||
void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
|
||||
void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
|
||||
void **pvTaskGetThreadLocalStorageBufferPointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
|
||||
|
||||
#if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS )
|
||||
/**
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#define ERRNO_TLS_INDEX (configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1)
|
||||
|
||||
static struct _reent impure_data;
|
||||
struct _reent *_global_impure_ptr = &impure_data;
|
||||
|
||||
@ -44,3 +46,8 @@ struct _reent *__getreent()
|
||||
#endif
|
||||
return _global_impure_ptr;
|
||||
}
|
||||
|
||||
int *__errno(void)
|
||||
{
|
||||
return (int *)pvTaskGetThreadLocalStorageBufferPointer(NULL, ERRNO_TLS_INDEX);
|
||||
}
|
||||
|
@ -128,10 +128,15 @@ NVIC value of 255. */
|
||||
#define configUSE_NEWLIB_REENTRANT 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 0: LwIP
|
||||
* 1: pthread (optional)
|
||||
* 2: errno
|
||||
*/
|
||||
#ifdef CONFIG_ENABLE_PTHREAD
|
||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 2
|
||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 3
|
||||
#else
|
||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 1
|
||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 2
|
||||
#endif
|
||||
#define configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS 1
|
||||
|
||||
|
3
components/freertos/test/CMakeLists.txt
Normal file
3
components/freertos/test/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES unity test_utils freertos)
|
5
components/freertos/test/component.mk
Normal file
5
components/freertos/test/component.mk
Normal file
@ -0,0 +1,5 @@
|
||||
#
|
||||
#Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
57
components/freertos/test/test_errno.c
Normal file
57
components/freertos/test/test_errno.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* mbedTLS AES performance test
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/errno.h>
|
||||
#include "unity.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
void __set_errno(int i)
|
||||
{
|
||||
errno = i;
|
||||
}
|
||||
|
||||
void __get_errno(int *i)
|
||||
{
|
||||
*i = errno;
|
||||
}
|
||||
|
||||
static void errno_check_task(void *p)
|
||||
{
|
||||
SemaphoreHandle_t wait_sem = p;
|
||||
|
||||
for (volatile int i = 0; i < 10 * 1000 * 1000; i++) {
|
||||
int j;
|
||||
|
||||
__set_errno(i);
|
||||
__get_errno(&j);
|
||||
assert(i == j);
|
||||
}
|
||||
|
||||
xSemaphoreGive(wait_sem);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
TEST_CASE("thread local errno", "[reent]")
|
||||
{
|
||||
SemaphoreHandle_t wait1_sem, wait2_sem;
|
||||
|
||||
wait1_sem = xSemaphoreCreateBinary();
|
||||
wait2_sem = xSemaphoreCreateBinary();
|
||||
|
||||
xTaskCreatePinnedToCore(&errno_check_task, "errno1", 2048, wait1_sem, 3, NULL, cpuid_0);
|
||||
xTaskCreatePinnedToCore(&errno_check_task, "errno2", 2048, wait2_sem, 3, NULL, cpuid_1);
|
||||
|
||||
xSemaphoreTake(wait1_sem, portMAX_DELAY);
|
||||
xSemaphoreTake(wait2_sem, portMAX_DELAY);
|
||||
|
||||
vQueueDelete(wait1_sem);
|
||||
vQueueDelete(wait2_sem);
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
components/newlib/newlib/lib/strip_symbols.sh
Executable file
11
components/newlib/newlib/lib/strip_symbols.sh
Executable file
@ -0,0 +1,11 @@
|
||||
|
||||
libs="libc_fnano.a libc.a libc_nano.a"
|
||||
symbols="lib_a-errno.o"
|
||||
|
||||
for symbol in ${symbols}
|
||||
do
|
||||
for lib in ${libs}
|
||||
do
|
||||
xtensa-lx106-elf-ar d ${lib} ${symbol}
|
||||
done
|
||||
done
|
Reference in New Issue
Block a user