feat(freertos): add thread local private "errno"

This commit is contained in:
Dong Heng
2020-03-12 18:55:57 +08:00
parent ba3110798c
commit 99de07db83
11 changed files with 109 additions and 2 deletions

View File

@ -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 */
/*-----------------------------------------------------------*/

View File

@ -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 )
/**

View File

@ -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);
}

View File

@ -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

View File

@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES unity test_utils freertos)

View File

@ -0,0 +1,5 @@
#
#Component Makefile
#
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive

View 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.

View 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