From 18227cbeff8bee3f450483c84581ae52ee5caf50 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Sat, 19 Feb 2022 09:39:30 +0800 Subject: [PATCH] libc/tls: Supports up to 64 elements Signed-off-by: Huang Qi --- include/nuttx/tls.h | 4 +++- libs/libc/tls/Kconfig | 1 + libs/libc/tls/tls_alloc.c | 2 +- libs/libc/tls/tls_destruct.c | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index 561b7e9576..1dc2a72b3e 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -67,8 +67,10 @@ */ #if CONFIG_TLS_NELEM > 0 -# if CONFIG_TLS_NELEM > 32 +# if CONFIG_TLS_NELEM > 64 # error Too many TLS elements +# elif CONFIG_TLS_NELEM > 32 + typedef uint64_t tls_ndxset_t; # elif CONFIG_TLS_NELEM > 16 typedef uint32_t tls_ndxset_t; # elif CONFIG_TLS_NELEM > 8 diff --git a/libs/libc/tls/Kconfig b/libs/libc/tls/Kconfig index 8d0dba26bf..5bc41f97e1 100644 --- a/libs/libc/tls/Kconfig +++ b/libs/libc/tls/Kconfig @@ -46,6 +46,7 @@ config TLS_LOG2_MAXSTACK config TLS_NELEM int "Number of TLS elements" default 4 + range 0 64 ---help--- The number of unique TLS elements. These can be accessed with the user library functions tls_get_value() and tls_set_value() diff --git a/libs/libc/tls/tls_alloc.c b/libs/libc/tls/tls_alloc.c index 7563d3834f..46860d0ece 100644 --- a/libs/libc/tls/tls_alloc.c +++ b/libs/libc/tls/tls_alloc.c @@ -80,7 +80,7 @@ int tls_alloc(CODE void (*dtor)(FAR void *)) { /* Is this candidate index available? */ - tls_ndxset_t mask = (1 << candidate); + tls_ndxset_t mask = (tls_ndxset_t)1 << candidate; if ((info->ta_tlsset & mask) == 0) { /* Yes.. allocate the index and break out of the loop */ diff --git a/libs/libc/tls/tls_destruct.c b/libs/libc/tls/tls_destruct.c index abc634ddb9..dfbfff53d5 100644 --- a/libs/libc/tls/tls_destruct.c +++ b/libs/libc/tls/tls_destruct.c @@ -65,7 +65,7 @@ void tls_destruct(void) { /* Is this candidate index available? */ - tls_ndxset_t mask = (1 << candidate); + tls_ndxset_t mask = (tls_ndxset_t)1 << candidate; if (tlsset & mask) { tls_elem_ptr = (FAR void *)tls->tl_elem[candidate];