From 9ce03b1660807443d767780d38f4209a968b1fb3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 8 May 2020 07:23:26 -0600 Subject: [PATCH] Move pthread-specific data into TLS 1. Move pthread-specific data files from sched/pthread/ to libs/libc/pthread. 2. Remove pthread-specific data functions from syscalls. 3. Implement tls_alloc() and tls_free() with system calls. 4. Reimplement pthread_key_create() and pthread_key_free() using tls_alloc() and tls_free(). 5. Reimplement pthread_set_specific() and pthread_get_specicif() using tls_set_value() and tls_get_value() --- .../kl/freedom-kl25z/configs/nsh/defconfig | 2 +- .../kl/freedom-kl26z/configs/nsh/defconfig | 2 +- boards/arm/kl/teensy-lc/configs/nsh/defconfig | 2 +- .../arm/lpc31xx/olimex-lpc-h3131/README.txt | 2 +- .../nutiny-nuc120/configs/nsh/defconfig | 2 +- .../s32k1xx/s32k118evb/configs/nsh/defconfig | 2 +- .../stm32/nucleo-l152re/configs/nsh/defconfig | 2 +- .../olimexino-stm32/configs/can/defconfig | 2 +- .../configs/composite/defconfig | 2 +- .../olimexino-stm32/configs/nsh/defconfig | 2 +- .../configs/smallnsh/defconfig | 2 +- .../olimexino-stm32/configs/tiny/defconfig | 2 +- .../stm32ldiscovery/configs/chrono/defconfig | 2 +- .../stm32ldiscovery/configs/nsh/defconfig | 2 +- .../b-l072z-lrwan1/configs/adc/defconfig | 2 +- .../b-l072z-lrwan1/configs/nsh/defconfig | 2 +- .../configs/nxlines_oled/defconfig | 2 +- .../b-l072z-lrwan1/configs/sx127x/defconfig | 2 +- .../nucleo-f072rb/configs/nsh/defconfig | 2 +- .../nucleo-f091rc/configs/nsh/defconfig | 2 +- .../nucleo-f091rc/configs/sx127x/defconfig | 2 +- .../nucleo-g070rb/configs/nsh/defconfig | 2 +- .../nucleo-g071rb/configs/nsh/defconfig | 2 +- .../nucleo-l073rz/configs/nsh/defconfig | 2 +- .../nucleo-l073rz/configs/sx127x/defconfig | 2 +- .../stm32f051-discovery/configs/nsh/defconfig | 2 +- .../stm32f072-discovery/configs/nsh/defconfig | 2 +- .../arm/tiva/eagle100/configs/httpd/defconfig | 2 +- .../teensy-2.0/configs/usbmsc/defconfig | 2 +- .../m16c/skp16c26/configs/ostest/defconfig | 2 +- .../ez80f910200zco/configs/httpd/defconfig | 2 +- .../ez80f910200zco/configs/poll/defconfig | 2 +- include/nuttx/sched.h | 35 +++-- include/nuttx/tls.h | 75 ++++++++-- include/sched.h | 42 ++---- include/sys/syscall_lookup.h | 7 +- libs/libc/pthread/Make.defs | 8 +- libs/libc/pthread/pthread_getspecific.c | 63 ++++++++ libs/libc/pthread/pthread_keycreate.c | 99 +++++++++++++ libs/libc/pthread/pthread_keydelete.c | 59 ++++++++ libs/libc/pthread/pthread_setspecific.c | 80 ++++++++++ libs/libc/tls/Kconfig | 5 +- libs/libc/tls/Make.defs | 2 +- libs/libc/tls/tls_getinfo.c | 2 +- .../tls/{tls_getelem.c => tls_getvalue.c} | 20 +-- .../tls/{tls_setelem.c => tls_setvalue.c} | 27 ++-- sched/group/Make.defs | 43 ++---- sched/group/group_tlsalloc.c | 101 +++++++++++++ sched/group/group_tlsfree.c | 88 +++++++++++ sched/pthread/Make.defs | 46 ++---- sched/pthread/pthread_getspecific.c | 101 ------------- sched/pthread/pthread_keycreate.c | 140 ------------------ sched/pthread/pthread_keydelete.c | 103 ------------- sched/pthread/pthread_setspecific.c | 116 --------------- syscall/syscall.csv | 6 +- 55 files changed, 685 insertions(+), 647 deletions(-) create mode 100644 libs/libc/pthread/pthread_getspecific.c create mode 100644 libs/libc/pthread/pthread_keycreate.c create mode 100644 libs/libc/pthread/pthread_keydelete.c create mode 100644 libs/libc/pthread/pthread_setspecific.c rename libs/libc/tls/{tls_getelem.c => tls_getvalue.c} (81%) rename libs/libc/tls/{tls_setelem.c => tls_setvalue.c} (76%) create mode 100644 sched/group/group_tlsalloc.c create mode 100644 sched/group/group_tlsfree.c delete mode 100644 sched/pthread/pthread_getspecific.c delete mode 100644 sched/pthread/pthread_keycreate.c delete mode 100644 sched/pthread/pthread_keydelete.c delete mode 100644 sched/pthread/pthread_setspecific.c diff --git a/boards/arm/kl/freedom-kl25z/configs/nsh/defconfig b/boards/arm/kl/freedom-kl25z/configs/nsh/defconfig index 820af374bb..9f51239a96 100644 --- a/boards/arm/kl/freedom-kl25z/configs/nsh/defconfig +++ b/boards/arm/kl/freedom-kl25z/configs/nsh/defconfig @@ -35,7 +35,7 @@ CONFIG_MM_SMALL=y CONFIG_MOTOROLA_SREC=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y diff --git a/boards/arm/kl/freedom-kl26z/configs/nsh/defconfig b/boards/arm/kl/freedom-kl26z/configs/nsh/defconfig index af917e497a..7fc54d3695 100644 --- a/boards/arm/kl/freedom-kl26z/configs/nsh/defconfig +++ b/boards/arm/kl/freedom-kl26z/configs/nsh/defconfig @@ -35,7 +35,7 @@ CONFIG_MM_SMALL=y CONFIG_MOTOROLA_SREC=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y diff --git a/boards/arm/kl/teensy-lc/configs/nsh/defconfig b/boards/arm/kl/teensy-lc/configs/nsh/defconfig index 7ec8804df8..16412c9c83 100644 --- a/boards/arm/kl/teensy-lc/configs/nsh/defconfig +++ b/boards/arm/kl/teensy-lc/configs/nsh/defconfig @@ -49,7 +49,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y diff --git a/boards/arm/lpc31xx/olimex-lpc-h3131/README.txt b/boards/arm/lpc31xx/olimex-lpc-h3131/README.txt index cc7ba59963..ee85dd8253 100644 --- a/boards/arm/lpc31xx/olimex-lpc-h3131/README.txt +++ b/boards/arm/lpc31xx/olimex-lpc-h3131/README.txt @@ -836,7 +836,7 @@ Configurations CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_PTHREAD=y CONFIG_MQ_MAXMSGSIZE=0 - CONFIG_NPTHREAD_KEYS=0 + CONFIG_TLS_NELEM=0 CONFIG_NUNGET_CHARS=0 CONFIG_PREALLOC_MQ_MSGS=0 diff --git a/boards/arm/nuc1xx/nutiny-nuc120/configs/nsh/defconfig b/boards/arm/nuc1xx/nutiny-nuc120/configs/nsh/defconfig index ea15a76340..a94389ceb0 100644 --- a/boards/arm/nuc1xx/nutiny-nuc120/configs/nsh/defconfig +++ b/boards/arm/nuc1xx/nutiny-nuc120/configs/nsh/defconfig @@ -32,7 +32,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y CONFIG_NSH_DISABLE_MKDIR=y diff --git a/boards/arm/s32k1xx/s32k118evb/configs/nsh/defconfig b/boards/arm/s32k1xx/s32k118evb/configs/nsh/defconfig index fa43a3d534..07da75c81e 100644 --- a/boards/arm/s32k1xx/s32k118evb/configs/nsh/defconfig +++ b/boards/arm/s32k1xx/s32k118evb/configs/nsh/defconfig @@ -33,7 +33,7 @@ CONFIG_MM_SMALL=y CONFIG_MOTOROLA_SREC=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y diff --git a/boards/arm/stm32/nucleo-l152re/configs/nsh/defconfig b/boards/arm/stm32/nucleo-l152re/configs/nsh/defconfig index e6f31b0ef8..bb70df5023 100644 --- a/boards/arm/stm32/nucleo-l152re/configs/nsh/defconfig +++ b/boards/arm/stm32/nucleo-l152re/configs/nsh/defconfig @@ -29,7 +29,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 CONFIG_NSH_LINELEN=64 diff --git a/boards/arm/stm32/olimexino-stm32/configs/can/defconfig b/boards/arm/stm32/olimexino-stm32/configs/can/defconfig index f39e01c785..989aeb1dbc 100644 --- a/boards/arm/stm32/olimexino-stm32/configs/can/defconfig +++ b/boards/arm/stm32/olimexino-stm32/configs/can/defconfig @@ -60,7 +60,7 @@ CONFIG_MM_SMALL=y CONFIG_NAME_MAX=8 CONFIG_NFILE_DESCRIPTORS=5 CONFIG_NFILE_STREAMS=5 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_CODECS_BUFSIZE=0 diff --git a/boards/arm/stm32/olimexino-stm32/configs/composite/defconfig b/boards/arm/stm32/olimexino-stm32/configs/composite/defconfig index 45984e2cd0..a52b95a6b9 100644 --- a/boards/arm/stm32/olimexino-stm32/configs/composite/defconfig +++ b/boards/arm/stm32/olimexino-stm32/configs/composite/defconfig @@ -79,7 +79,7 @@ CONFIG_MM_SMALL=y CONFIG_NAME_MAX=8 CONFIG_NFILE_DESCRIPTORS=5 CONFIG_NFILE_STREAMS=5 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_CODECS_BUFSIZE=0 diff --git a/boards/arm/stm32/olimexino-stm32/configs/nsh/defconfig b/boards/arm/stm32/olimexino-stm32/configs/nsh/defconfig index 60b9252b3c..d28b000a32 100644 --- a/boards/arm/stm32/olimexino-stm32/configs/nsh/defconfig +++ b/boards/arm/stm32/olimexino-stm32/configs/nsh/defconfig @@ -67,7 +67,7 @@ CONFIG_MM_SMALL=y CONFIG_NAME_MAX=8 CONFIG_NFILE_DESCRIPTORS=5 CONFIG_NFILE_STREAMS=5 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_CODECS_BUFSIZE=0 diff --git a/boards/arm/stm32/olimexino-stm32/configs/smallnsh/defconfig b/boards/arm/stm32/olimexino-stm32/configs/smallnsh/defconfig index 68c246c459..644788c826 100644 --- a/boards/arm/stm32/olimexino-stm32/configs/smallnsh/defconfig +++ b/boards/arm/stm32/olimexino-stm32/configs/smallnsh/defconfig @@ -43,7 +43,7 @@ CONFIG_MM_SMALL=y CONFIG_NAME_MAX=8 CONFIG_NFILE_DESCRIPTORS=5 CONFIG_NFILE_STREAMS=5 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_CODECS_BUFSIZE=0 diff --git a/boards/arm/stm32/olimexino-stm32/configs/tiny/defconfig b/boards/arm/stm32/olimexino-stm32/configs/tiny/defconfig index 767d70b255..1ccd1ed7df 100644 --- a/boards/arm/stm32/olimexino-stm32/configs/tiny/defconfig +++ b/boards/arm/stm32/olimexino-stm32/configs/tiny/defconfig @@ -44,7 +44,7 @@ CONFIG_MM_SMALL=y CONFIG_NAME_MAX=8 CONFIG_NFILE_DESCRIPTORS=5 CONFIG_NFILE_STREAMS=5 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768 CONFIG_PREALLOC_MQ_MSGS=4 CONFIG_PREALLOC_TIMERS=2 diff --git a/boards/arm/stm32/stm32ldiscovery/configs/chrono/defconfig b/boards/arm/stm32/stm32ldiscovery/configs/chrono/defconfig index 0338d2c58d..1e8d2df4f2 100644 --- a/boards/arm/stm32/stm32ldiscovery/configs/chrono/defconfig +++ b/boards/arm/stm32/stm32ldiscovery/configs/chrono/defconfig @@ -40,7 +40,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_CD=y diff --git a/boards/arm/stm32/stm32ldiscovery/configs/nsh/defconfig b/boards/arm/stm32/stm32ldiscovery/configs/nsh/defconfig index 00c1b81ba3..670d816d10 100644 --- a/boards/arm/stm32/stm32ldiscovery/configs/nsh/defconfig +++ b/boards/arm/stm32/stm32ldiscovery/configs/nsh/defconfig @@ -31,7 +31,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y CONFIG_NSH_DISABLE_MKDIR=y diff --git a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/adc/defconfig b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/adc/defconfig index 15a55e50c1..b9d49d2c98 100644 --- a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/adc/defconfig +++ b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/adc/defconfig @@ -32,7 +32,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 diff --git a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nsh/defconfig index 8d2088b75b..15ae1786d6 100644 --- a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nsh/defconfig @@ -29,7 +29,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 CONFIG_NSH_LINELEN=64 diff --git a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nxlines_oled/defconfig b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nxlines_oled/defconfig index 39094dbcce..4064a799e9 100644 --- a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nxlines_oled/defconfig +++ b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/nxlines_oled/defconfig @@ -35,7 +35,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MQ_MAXMSGSIZE=64 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 diff --git a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/sx127x/defconfig b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/sx127x/defconfig index 380b2167a0..2b4609c209 100644 --- a/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/sx127x/defconfig +++ b/boards/arm/stm32f0l0g0/b-l072z-lrwan1/configs/sx127x/defconfig @@ -37,7 +37,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 diff --git a/boards/arm/stm32f0l0g0/nucleo-f072rb/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/nucleo-f072rb/configs/nsh/defconfig index 001de7435f..5b05a6296d 100644 --- a/boards/arm/stm32f0l0g0/nucleo-f072rb/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-f072rb/configs/nsh/defconfig @@ -29,7 +29,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_CP=y diff --git a/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/nsh/defconfig index 0765637d65..074295a631 100644 --- a/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/nsh/defconfig @@ -31,7 +31,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_CP=y diff --git a/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/sx127x/defconfig b/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/sx127x/defconfig index c1e1587cd8..487f332eda 100644 --- a/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/sx127x/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-f091rc/configs/sx127x/defconfig @@ -36,7 +36,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 diff --git a/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig index da26cc3e4c..810f90d501 100644 --- a/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig @@ -43,7 +43,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 CONFIG_NSH_LINELEN=64 diff --git a/boards/arm/stm32f0l0g0/nucleo-g071rb/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/nucleo-g071rb/configs/nsh/defconfig index 9a72415a70..7ead6a70bd 100644 --- a/boards/arm/stm32f0l0g0/nucleo-g071rb/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-g071rb/configs/nsh/defconfig @@ -27,7 +27,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 CONFIG_NSH_LINELEN=64 diff --git a/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/nsh/defconfig index dcdc2f1ba5..7367ad9004 100644 --- a/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/nsh/defconfig @@ -29,7 +29,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 CONFIG_NSH_LINELEN=64 diff --git a/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/sx127x/defconfig b/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/sx127x/defconfig index b9e8de570d..03666111dd 100644 --- a/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/sx127x/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-l073rz/configs/sx127x/defconfig @@ -37,7 +37,7 @@ CONFIG_MAX_TASKS=8 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=64 diff --git a/boards/arm/stm32f0l0g0/stm32f051-discovery/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/stm32f051-discovery/configs/nsh/defconfig index 3093337ef7..0a2d756e91 100644 --- a/boards/arm/stm32f0l0g0/stm32f051-discovery/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/stm32f051-discovery/configs/nsh/defconfig @@ -28,7 +28,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y CONFIG_NSH_DISABLE_MKDIR=y diff --git a/boards/arm/stm32f0l0g0/stm32f072-discovery/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/stm32f072-discovery/configs/nsh/defconfig index a83da402a2..d310dda40f 100644 --- a/boards/arm/stm32f0l0g0/stm32f072-discovery/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/stm32f072-discovery/configs/nsh/defconfig @@ -28,7 +28,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_SMALL=y CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y CONFIG_NSH_DISABLE_MKDIR=y diff --git a/boards/arm/tiva/eagle100/configs/httpd/defconfig b/boards/arm/tiva/eagle100/configs/httpd/defconfig index 9fdef02f53..a0984c12a4 100644 --- a/boards/arm/tiva/eagle100/configs/httpd/defconfig +++ b/boards/arm/tiva/eagle100/configs/httpd/defconfig @@ -34,7 +34,7 @@ CONFIG_NET_TCPBACKLOG=y CONFIG_NET_TCP_CONNS=16 CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSOCKET_DESCRIPTORS=16 CONFIG_NUNGET_CHARS=0 CONFIG_PREALLOC_WDOGS=8 diff --git a/boards/avr/at90usb/teensy-2.0/configs/usbmsc/defconfig b/boards/avr/at90usb/teensy-2.0/configs/usbmsc/defconfig index 5612770165..02fb33760f 100644 --- a/boards/avr/at90usb/teensy-2.0/configs/usbmsc/defconfig +++ b/boards/avr/at90usb/teensy-2.0/configs/usbmsc/defconfig @@ -32,7 +32,7 @@ CONFIG_MMCSD=y CONFIG_MMCSD_SPICLOCK=12500000 CONFIG_NFILE_DESCRIPTORS=6 CONFIG_NFILE_STREAMS=6 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NUNGET_CHARS=0 CONFIG_PREALLOC_TIMERS=0 CONFIG_PREALLOC_WDOGS=6 diff --git a/boards/renesas/m16c/skp16c26/configs/ostest/defconfig b/boards/renesas/m16c/skp16c26/configs/ostest/defconfig index 0220415489..32395f8f76 100644 --- a/boards/renesas/m16c/skp16c26/configs/ostest/defconfig +++ b/boards/renesas/m16c/skp16c26/configs/ostest/defconfig @@ -26,7 +26,7 @@ CONFIG_MAX_WDOGPARMS=2 CONFIG_MOTOROLA_SREC=y CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NUNGET_CHARS=0 CONFIG_PREALLOC_TIMERS=0 CONFIG_PREALLOC_WDOGS=8 diff --git a/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig b/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig index 5909c6967d..a1fab70285 100644 --- a/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig +++ b/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig @@ -37,7 +37,7 @@ CONFIG_NET_TCPBACKLOG=y CONFIG_NET_TCP_CONNS=16 CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NSOCKET_DESCRIPTORS=16 CONFIG_NUNGET_CHARS=0 CONFIG_PREALLOC_WDOGS=8 diff --git a/boards/z80/ez80/ez80f910200zco/configs/poll/defconfig b/boards/z80/ez80/ez80f910200zco/configs/poll/defconfig index 276fef5ec9..af52e22bd5 100644 --- a/boards/z80/ez80/ez80f910200zco/configs/poll/defconfig +++ b/boards/z80/ez80/ez80f910200zco/configs/poll/defconfig @@ -35,7 +35,7 @@ CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 -CONFIG_NPTHREAD_KEYS=0 +CONFIG_TLS_NELEM=0 CONFIG_NUNGET_CHARS=0 CONFIG_PIPES=y CONFIG_PREALLOC_WDOGS=8 diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 37a40f8167..ef0b2c6ed5 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -333,19 +333,21 @@ struct pthread_cleanup_s }; #endif -/* type pthread_keyset_t ********************************************************/ +/* type tls_ndxset_t ************************************************************/ -/* Smallest addressable type that can hold the entire configured number of keys */ +/* Smallest addressable type that can hold the entire configured number of TLS + * data indexes. + */ -#if defined(CONFIG_NPTHREAD_KEYS) && CONFIG_NPTHREAD_KEYS > 0 -# if CONFIG_NPTHREAD_KEYS > 32 -# error Too many pthread keys -# elif CONFIG_NPTHREAD_KEYS > 16 - typedef uint32_t pthread_keyset_t; -# elif CONFIG_NPTHREAD_KEYS > 8 - typedef uint16_t pthread_keyset_t; +#if CONFIG_TLS_NELEM > 0 +# if CONFIG_TLS_NELEM > 32 +# error Too many TLS elements +# elif CONFIG_TLS_NELEM > 16 + typedef uint32_t tls_ndxset_t; +# elif CONFIG_TLS_NELEM > 8 + typedef uint16_t tls_ndxset_t; # else - typedef uint8_t pthread_keyset_t; + typedef uint8_t tls_ndxset_t; # endif #endif @@ -525,8 +527,11 @@ struct task_group_s FAR struct join_s *tg_joinhead; /* Head of a list of join data */ FAR struct join_s *tg_jointail; /* Tail of a list of join data */ #endif -#if CONFIG_NPTHREAD_KEYS > 0 - pthread_keyset_t tg_keyset; /* Set of pthread keys allocated */ + + /* Thread local storage *******************************************************/ + +#if CONFIG_TLS_NELEM > 0 + tls_ndxset_t tg_tlsset; /* Set of TLS data indexes allocated */ #endif /* POSIX Signal Control Fields ************************************************/ @@ -694,12 +699,6 @@ struct tcb_s FAR struct mqueue_inode_s *msgwaitq; /* Waiting for this message queue */ #endif - /* POSIX Thread Specific Data *************************************************/ - -#if CONFIG_NPTHREAD_KEYS > 0 - FAR void *pthread_data[CONFIG_NPTHREAD_KEYS]; -#endif - /* Pre-emption monitor support ************************************************/ #ifdef CONFIG_SCHED_CRITMONITOR diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index 7323a67a1a..c21fd22b9b 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -86,41 +86,86 @@ struct tls_info_s ****************************************************************************/ /**************************************************************************** - * Name: tls_get_element + * Name: tls_alloc * * Description: - * Return an the TLS element associated with the 'elem' index + * Allocate a group-unique TLS data index * * Input Parameters: - * elem - Index of TLS element to return + * None * * Returned Value: - * The value of TLS element associated with 'elem'. Errors are not - * reported. Zero is returned in the event of an error, but zero may also - * be valid value and returned when there is no error. The only possible - * error would be if elem < 0 or elem >=CONFIG_TLS_NELEM. + * A TLS index that is unique for use within this task group. * ****************************************************************************/ -uintptr_t tls_get_element(int elem); +#if CONFIG_TLS_NELEM > 0 +int tls_alloc(void); +#endif /**************************************************************************** - * Name: tls_get_element + * Name: tls_free * * Description: - * Set the TLS element associated with the 'elem' index to 'value' + * Release a group-unique TLS data index previous obtained by tls_alloc() * * Input Parameters: - * elem - Index of TLS element to set - * value - The new value of the TLS element + * tlsindex - The previously allocated TLS index to be freed * * Returned Value: - * None. Errors are not reported. The only possible error would be if - * elem < 0 or elem >=CONFIG_TLS_NELEM. + * OK is returned on success; a negated errno value will be returned on + * failure: + * + * -EINVAL - the index to be freed is out of range. * ****************************************************************************/ -void tls_set_element(int elem, uintptr_t value); +#if CONFIG_TLS_NELEM > 0 +int tls_free(int tlsindex); +#endif + +/**************************************************************************** + * Name: tls_get_value + * + * Description: + * Return an the TLS data value associated with the 'tlsindx' + * + * Input Parameters: + * tlsindex - Index of TLS data element to return + * + * Returned Value: + * The value of TLS element associated with 'tlsindex'. Errors are not + * reported. Zero is returned in the event of an error, but zero may also + * be valid value and returned when there is no error. The only possible + * error would be if tlsindex < 0 or tlsindex >=CONFIG_TLS_NELEM. + * + ****************************************************************************/ + +#if CONFIG_TLS_NELEM > 0 +uintptr_t tls_get_value(int tlsindex); +#endif + +/**************************************************************************** + * Name: tls_set_value + * + * Description: + * Set the TLS element associated with the 'tlsindex' to 'tlsvalue' + * + * Input Parameters: + * tlsindex - Index of TLS data element to set + * tlsvalue - The new value of the TLS data element + * + * Returned Value: + * Zero is returned on success, a negated errno value is return on + * failure: + * + * EINVAL - tlsindex is not in range. + * + ****************************************************************************/ + +#if CONFIG_TLS_NELEM > 0 +int tls_set_value(int tlsindex, uintptr_t tlsvalue); +#endif /**************************************************************************** * Name: tls_get_info diff --git a/include/sched.h b/include/sched.h index 84933ca5c4..362fca88f0 100644 --- a/include/sched.h +++ b/include/sched.h @@ -1,36 +1,20 @@ /******************************************************************************** * include/sched.h * - * Copyright (C) 2007-2009, 2011, 2013, 2015-2016, 2020 Gregory Nutt. All - * rights reserved. - * Author: Gregory Nutt + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * http://www.apache.org/licenses/LICENSE-2.0 * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. * ********************************************************************************/ @@ -80,7 +64,7 @@ /* Pthread definitions **********************************************************/ -#define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS +#define PTHREAD_KEYS_MAX CONFIG_TLS_NELEM /* CPU affinity mask helpers ****************************************************/ diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 13ec91927e..3da60f042f 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -283,6 +283,9 @@ SYSCALL_LOOKUP(telldir, 1) SYSCALL_LOOKUP(shmdt, 1) #endif + SYSCALL_LOOKUP(tls_alloc, 0) + SYSCALL_LOOKUP(tls_free, 1) + /* The following are defined if pthreads are enabled */ #ifndef CONFIG_DISABLE_PTHREAD @@ -294,10 +297,7 @@ SYSCALL_LOOKUP(telldir, 1) SYSCALL_LOOKUP(pthread_detach, 1) SYSCALL_LOOKUP(pthread_exit, 1) SYSCALL_LOOKUP(pthread_getschedparam, 3) - SYSCALL_LOOKUP(pthread_getspecific, 1) SYSCALL_LOOKUP(pthread_join, 2) - SYSCALL_LOOKUP(pthread_key_create, 2) - SYSCALL_LOOKUP(pthread_key_delete, 1) SYSCALL_LOOKUP(pthread_mutex_destroy, 1) SYSCALL_LOOKUP(pthread_mutex_init, 2) SYSCALL_LOOKUP(pthread_mutex_timedlock, 2) @@ -308,7 +308,6 @@ SYSCALL_LOOKUP(telldir, 1) #endif SYSCALL_LOOKUP(pthread_setschedparam, 3) SYSCALL_LOOKUP(pthread_setschedprio, 2) - SYSCALL_LOOKUP(pthread_setspecific, 2) #ifdef CONFIG_SMP SYSCALL_LOOKUP(pthread_setaffinity_np, 3) SYSCALL_LOOKUP(pthread_getaffinity_np, 3) diff --git a/libs/libc/pthread/Make.defs b/libs/libc/pthread/Make.defs index 8523a9fc80..3c03ae0d11 100644 --- a/libs/libc/pthread/Make.defs +++ b/libs/libc/pthread/Make.defs @@ -18,6 +18,11 @@ # ############################################################################ +ifneq ($(CONFIG_TLS_NELEM),0) +CSRCS += pthread_keycreate.c pthread_setspecific.c pthread_getspecific.c +CSRCS += pthread_keydelete.c +endif + ifneq ($(CONFIG_DISABLE_PTHREAD),y) # Add the pthread C files to the build @@ -57,9 +62,10 @@ ifeq ($(CONFIG_BUILD_PROTECTED),y) CSRCS += pthread_startup.c endif +endif # CONFIG_DISABLE_PTHREAD + # Add the pthread directory to the build DEPPATH += --dep-path pthread VPATH += :pthread -endif # CONFIG_DISABLE_PTHREAD diff --git a/libs/libc/pthread/pthread_getspecific.c b/libs/libc/pthread/pthread_getspecific.c new file mode 100644 index 0000000000..def22b9129 --- /dev/null +++ b/libs/libc/pthread/pthread_getspecific.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * libs/libc/pthread/pthread_getspecific.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_getspecific + * + * Description: + * The pthread_getspecific() function returns the value currently + * bound to the specified key on behalf of the calling thread. + * + * The effect of calling pthread_getspecific() with a key value + * not obtained from pthread_key_create() or after a key has been + * deleted with pthread_key_delete() is undefined. + * + * Input Parameters: + * key = The data key to get or set + * + * Returned Value: + * The function pthread_getspecific() returns the thread-specific data + * associated with the given key. If no thread specific data is + * associated with the key, then the value NULL is returned. + * + * POSIX Compatibility: + * - Both pthread_setspecific() and pthread_getspecific() may be + * called from a thread-specific data destructor function. + * + ****************************************************************************/ + +FAR void *pthread_getspecific(pthread_key_t key) +{ + return (FAR void *)tls_get_value((int)key); +} diff --git a/libs/libc/pthread/pthread_keycreate.c b/libs/libc/pthread/pthread_keycreate.c new file mode 100644 index 0000000000..5765fb694d --- /dev/null +++ b/libs/libc/pthread/pthread_keycreate.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * libs/libc/pthread/pthread_keycreate.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#if CONFIG_TLS_NELEM > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_key_create + * + * Description: + * This function creates a thread-specific data key visible to all threads + * in the system. Although the same key value may be used by different + * threads, the values bound to the key by pthread_setspecific() are + * maintained on a per-thread basis and persist for the life of the calling + * thread. + * + * Upon key creation, the value NULL will be associated with the new key + * in all active threads. Upon thread creation, the value NULL will be + * associated with all defined keys in the new thread. + * + * Input Parameters: + * key - A pointer to the key to create. + * destructor - An optional destructor() function that may be associated + * with each key that is invoked when a thread exits. + * However, this argument is ignored in the current + * implementation. + * + * Returned Value: + * If successful, the pthread_key_create() function will store the newly + * created key value at *key and return zero (OK). Otherwise, an error + * number will be returned to indicate the error: + * + * EAGAIN - The system lacked sufficient resources to create another + * thread-specific data key, or the system-imposed limit on + * the total number of keys pers process {PTHREAD_KEYS_MAX} + * has been exceeded + * ENOMEM - Insufficient memory exist to create the key. + * + * POSIX Compatibility: + * - The present implementation ignores the destructor argument. + * + ****************************************************************************/ + +int pthread_key_create(FAR pthread_key_t *key, + CODE void (*destructor)(FAR void *)) +{ + int tlsindex; + + DEBUGASSERT(key != NULL); + + /* Allocate a TLS index */ + + tlsindex = tls_alloc(); + + /* Check if found a TLS index. */ + + if (tlsindex >= 0) + { + /* Yes.. Return the key value and success */ + + *key = (pthread_key_t)tlsindex; + return OK; + } + + return -tlsindex; +} + +#endif /* CONFIG_TLS_NELEM */ diff --git a/libs/libc/pthread/pthread_keydelete.c b/libs/libc/pthread/pthread_keydelete.c new file mode 100644 index 0000000000..ad5ab06af4 --- /dev/null +++ b/libs/libc/pthread/pthread_keydelete.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * libs/libc/pthread/pthread_keydelete.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_key_delete + * + * Description: + * This POSIX function deletes a thread-specific data key + * previously returned by pthread_key_create(). + * + * Input Parameters: + * key - the key to delete + * + * Returned Value: + * Returns zero (OK) on success. EINVAL may be returned if an invalid + * key is received. + * + * POSIX Compatibility: + * + ****************************************************************************/ + +int pthread_key_delete(pthread_key_t key) +{ + /* Free the TLS index */ + + int ret = tls_free((int)key); + return ret < 0 ? -ret : 0; +} diff --git a/libs/libc/pthread/pthread_setspecific.c b/libs/libc/pthread/pthread_setspecific.c new file mode 100644 index 0000000000..40ed44270f --- /dev/null +++ b/libs/libc/pthread/pthread_setspecific.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * libs/libc/pthread/pthread_setspecific.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#if CONFIG_TLS_NELEM > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_setspecific + * + * Description: + * The pthread_setspecific() function associates a thread- + * specific value with a key obtained via a previous call + * to pthread_key_create(). Different threads may bind + * different values to the same key. These values are + * typically pointers to blocks of dynamically allocated + * memory that have been reserved for use by the calling + * thread. + * + * The effect of calling pthread_setspecific() with + * a key value not obtained from pthread_key_create() or + * after a key has been deleted with pthread_key_delete() + * is undefined. + * + * Input Parameters: + * key = The data key to get or set + * value = The value to bind to the key. + * + * Returned Value: + * If successful, pthread_setspecific() will return zero (OK). + * Otherwise, an error number will be returned: + * + * ENOMEM - Insufficient memory exists to associate + * the value with the key. + * EINVAL - The key value is invalid. + * + * POSIX Compatibility: + * - Both pthread_setspecific() and pthread_getspecific() + * may be called from a thread-specific data destructor + * function. + * + ****************************************************************************/ + +int pthread_setspecific(pthread_key_t key, FAR const void *value) +{ + int ret = tls_set_value((int)key, (uintptr_t)value); + return ret < 0 ? -ret : 0; +} + +#endif /* CONFIG_TLS_NELEM */ + diff --git a/libs/libc/tls/Kconfig b/libs/libc/tls/Kconfig index b14abc4341..8d0dba26bf 100644 --- a/libs/libc/tls/Kconfig +++ b/libs/libc/tls/Kconfig @@ -45,10 +45,11 @@ config TLS_LOG2_MAXSTACK config TLS_NELEM int "Number of TLS elements" - default 0 + default 4 ---help--- The number of unique TLS elements. These can be accessed with - the user library functions tls_get_element() and tls_set_element(). + the user library functions tls_get_value() and tls_set_value() + and the OS interfaces tls_alloc() and tls_free(). NOTE that the special value of CONFIG_TLS_NELEM disables these TLS interfaces. diff --git a/libs/libc/tls/Make.defs b/libs/libc/tls/Make.defs index 01fd70edcb..0e125f8ecb 100644 --- a/libs/libc/tls/Make.defs +++ b/libs/libc/tls/Make.defs @@ -19,7 +19,7 @@ ############################################################################ ifneq ($(CONFIG_TLS_NELEM),0) -CSRCS += tls_setelem.c tls_getelem.c +CSRCS += tls_setvalue.c tls_getvalue.c endif ifneq ($(CONFIG_TLS_ALIGNED),y) diff --git a/libs/libc/tls/tls_getinfo.c b/libs/libc/tls/tls_getinfo.c index 79a90705b2..ee00bebd1a 100644 --- a/libs/libc/tls/tls_getinfo.c +++ b/libs/libc/tls/tls_getinfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libs/libc/fixedmath/tls_setelem.c + * libs/libc/tls/tls_getinfo.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/libs/libc/tls/tls_getelem.c b/libs/libc/tls/tls_getvalue.c similarity index 81% rename from libs/libc/tls/tls_getelem.c rename to libs/libc/tls/tls_getvalue.c index af03e220ef..84148961d8 100644 --- a/libs/libc/tls/tls_getelem.c +++ b/libs/libc/tls/tls_getvalue.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libs/libc/fixedmath/tls_getelem.c + * libs/libc/tls/tls_getvalue.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -38,29 +38,29 @@ ****************************************************************************/ /**************************************************************************** - * Name: tls_get_element + * Name: tls_get_value * * Description: - * Return an the TLS element associated with the 'elem' index + * Return an the TLS data value associated with the 'tlsindx' * * Input Parameters: - * elem - Index of TLS element to return + * tlsindex - Index of TLS data element to return * * Returned Value: - * The value of TLS element associated with 'elem'. Errors are not + * The value of TLS element associated with 'tlsindex'. Errors are not * reported. Zero is returned in the event of an error, but zero may also * be valid value and returned when there is no error. The only possible - * error would be if elem < 0 or elem >=CONFIG_TLS_NELEM. + * error would be if tlsindex < 0 or tlsindex >=CONFIG_TLS_NELEM. * ****************************************************************************/ -uintptr_t tls_get_element(int elem) +uintptr_t tls_get_value(int tlsindex) { FAR struct tls_info_s *info; uintptr_t ret = 0; - DEBUGASSERT(elem >= 0 && elem < CONFIG_TLS_NELEM); - if (elem >= 0 && elem < CONFIG_TLS_NELEM) + DEBUGASSERT(tlsindex >= 0 && tlsindex < CONFIG_TLS_NELEM); + if (tlsindex >= 0 && tlsindex < CONFIG_TLS_NELEM) { /* Get the TLS info structure from the current threads stack */ @@ -69,7 +69,7 @@ uintptr_t tls_get_element(int elem) /* Get the element value from the TLS info. */ - ret = info->tl_elem[elem]; + ret = info->tl_elem[tlsindex]; } return ret; diff --git a/libs/libc/tls/tls_setelem.c b/libs/libc/tls/tls_setvalue.c similarity index 76% rename from libs/libc/tls/tls_setelem.c rename to libs/libc/tls/tls_setvalue.c index 6d301b89c6..84cbf93bd5 100644 --- a/libs/libc/tls/tls_setelem.c +++ b/libs/libc/tls/tls_setvalue.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libs/libc/fixedmath/tls_setelem.c + * libs/libc/tls/tls_setvalue.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -38,27 +38,29 @@ ****************************************************************************/ /**************************************************************************** - * Name: tls_get_element + * Name: tls_set_value * * Description: - * Set the TLS element associated with the 'elem' index to 'value' + * Set the TLS element associated with the 'tlsindex' to 'tlsvalue' * * Input Parameters: - * elem - Index of TLS element to set - * value - The new value of the TLS element + * tlsindex - Index of TLS data element to set + * tlsvalue - The new value of the TLS data element * * Returned Value: - * None. Errors are not reported. The only possible error would be if - * elem >=CONFIG_TLS_NELEM. + * Zero is returned on success, a negated errno value is return on + * failure: + * + * EINVAL - tlsindex is not in range. * ****************************************************************************/ -void tls_set_element(int elem, uintptr_t value) +int tls_set_value(int tlsindex, uintptr_t tlsvalue) { FAR struct tls_info_s *info; - DEBUGASSERT(elem >= 0 && elem < CONFIG_TLS_NELEM); - if (elem >= 0 && elem < CONFIG_TLS_NELEM) + DEBUGASSERT(tlsindex >= 0 && tlsindex < CONFIG_TLS_NELEM); + if (tlsindex >= 0 && tlsindex < CONFIG_TLS_NELEM) { /* Get the TLS info structure from the current threads stack */ @@ -67,8 +69,11 @@ void tls_set_element(int elem, uintptr_t value) /* Set the element value int the TLS info. */ - info->tl_elem[elem] = value; + info->tl_elem[tlsindex] = tlsvalue; + return OK; } + + return -EINVAL; } #endif /* CONFIG_TLS_NELEM > 0 */ diff --git a/sched/group/Make.defs b/sched/group/Make.defs index 18c1ba664b..14f1225749 100644 --- a/sched/group/Make.defs +++ b/sched/group/Make.defs @@ -1,35 +1,20 @@ ############################################################################ # sched/group/Make.defs # -# Copyright (C) 2014, 2018 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: +# http://www.apache.org/licenses/LICENSE-2.0 # -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # ############################################################################ @@ -68,6 +53,10 @@ ifneq ($(CONFIG_BUILD_FLAT),y) CSRCS += group_malloc.c group_zalloc.c group_free.c endif +ifneq ($(CONFIG_TLS_NELEM),0) +CSRCS += group_tlsalloc.c group_tlsfree.c +endif + # Include group build support DEPPATH += --dep-path group diff --git a/sched/group/group_tlsalloc.c b/sched/group/group_tlsalloc.c new file mode 100644 index 0000000000..3aff9083cf --- /dev/null +++ b/sched/group/group_tlsalloc.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * sched/group/group_tlsalloc.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "sched/sched.h" +#include "group/group.h" + +#if CONFIG_TLS_NELEM > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tls_alloc + * + * Description: + * Allocate a group-unique TLS data index + * + * Input Parameters: + * None + * + * Returned Value: + * A TLS index that is unique for use within this task group. + * + ****************************************************************************/ + +int tls_alloc(void) +{ + FAR struct tcb_s *rtcb = this_task(); + FAR struct task_group_s *group = rtcb->group; + irqstate_t flags; + int candidate; + int ret = -EAGAIN; + + DEBUGASSERT(group != NULL); + + /* Search for an unused index. This is done in a critical section here to + * avoid concurrent modification of the group TLS index set. + */ + + flags = spin_lock_irqsave(); + for (candidate = 0; candidate < CONFIG_TLS_NELEM; candidate++) + { + /* Is this candidate index available? */ + + tls_ndxset_t mask = (1 << candidate); + if ((group->tg_tlsset & mask) == 0) + { + /* Yes.. allocate the index and break out of the loop */ + + group->tg_tlsset |= mask; + break; + } + } + + spin_unlock_irqrestore(flags); + + /* Check if found a valid TLS data index. */ + + if (candidate < CONFIG_TLS_NELEM) + { + /* Yes.. Return the TLS index and success */ + + ret = candidate; + } + + return ret; +} + +#endif /* CONFIG_TLS_NELEM > 0 */ diff --git a/sched/group/group_tlsfree.c b/sched/group/group_tlsfree.c new file mode 100644 index 0000000000..7f95c30163 --- /dev/null +++ b/sched/group/group_tlsfree.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * sched/group/group_tlsfree.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "sched/sched.h" +#include "group/group.h" + +#if CONFIG_TLS_NELEM > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tls_free + * + * Description: + * Release a group-unique TLS data index previous obtained by tls_alloc() + * + * Input Parameters: + * tlsindex - The previously allocated TLS index to be freed + * + * Returned Value: + * OK is returned on success; a negated errno value will be returned on + * failure: + * + * -EINVAL - the index to be freed is out of range. + * + ****************************************************************************/ + +int tls_free(int tlsindex) +{ + FAR struct tcb_s *rtcb = this_task(); + FAR struct task_group_s *group = rtcb->group; + tls_ndxset_t mask; + irqstate_t flags; + int ret = -EINVAL; + + DEBUGASSERT((unsigned)tlsindex < CONFIG_TLS_NELEM && group != NULL); + if ((unsigned)tlsindex < CONFIG_TLS_NELEM) + { + /* This is done in a critical section here to avoid concurrent + * modification of the group TLS index set. + */ + + mask = (1 << tlsindex); + flags = spin_lock_irqsave(); + + DEBUGASSERT((group->tg_tlsset & mask) != 0); + group->tg_tlsset &= ~mask; + spin_unlock_irqrestore(flags); + + ret = OK; + } + + return ret; +} + +#endif /* CONFIG_TLS_NELEM > 0 */ diff --git a/sched/pthread/Make.defs b/sched/pthread/Make.defs index 90ca64c145..cf9a10a49f 100644 --- a/sched/pthread/Make.defs +++ b/sched/pthread/Make.defs @@ -1,41 +1,23 @@ ############################################################################ # sched/pthread/Make.defs # -# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: +# http://www.apache.org/licenses/LICENSE-2.0 # -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # ############################################################################ -CSRCS += pthread_keycreate.c pthread_setspecific.c pthread_getspecific.c -CSRCS += pthread_keydelete.c - ifneq ($(CONFIG_DISABLE_PTHREAD),y) CSRCS += pthread_create.c pthread_exit.c pthread_join.c pthread_detach.c @@ -60,9 +42,9 @@ ifeq ($(CONFIG_PTHREAD_CLEANUP),y) CSRCS += pthread_cleanup.c endif -endif - # Include pthread build support DEPPATH += --dep-path pthread VPATH += :pthread + +endif # CONFIG_DISABLE_PTHREAD diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c deleted file mode 100644 index 7d87f05d79..0000000000 --- a/sched/pthread/pthread_getspecific.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * sched/pthread/pthread_getspecific.c - * - * Copyright (C) 2007, 2009, 2013, 2018 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "sched/sched.h" -#include "pthread/pthread.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pthread_getspecific - * - * Description: - * The pthread_getspecific() function returns the value currently - * bound to the specified key on behalf of the calling thread. - * - * The effect of calling pthread_getspecific() with a key value - * not obtained from pthread_key_create() or after a key has been - * deleted with pthread_key_delete() is undefined. - * - * Input Parameters: - * key = The data key to get or set - * - * Returned Value: - * The function pthread_getspecific() returns the thread-specific data - * associated with the given key. If no thread specific data is - * associated with the key, then the value NULL is returned. - * - * POSIX Compatibility: - * - Both pthread_setspecific() and pthread_getspecific() may be - * called from a thread-specific data destructor function. - * - ****************************************************************************/ - -FAR void *pthread_getspecific(pthread_key_t key) -{ -#if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = this_task(); - FAR struct task_group_s *group = rtcb->group; - FAR void *ret = NULL; - - DEBUGASSERT(group != NULL && (unsigned)key < CONFIG_NPTHREAD_KEYS); - - /* Check if the key is valid. */ - - if (key < CONFIG_NPTHREAD_KEYS && (group->tg_keyset & (1 << key)) != 0) - { - /* Return the stored value. */ - - ret = rtcb->pthread_data[key]; - } - - return ret; -#else - return NULL; -#endif -} diff --git a/sched/pthread/pthread_keycreate.c b/sched/pthread/pthread_keycreate.c deleted file mode 100644 index 07ecaef665..0000000000 --- a/sched/pthread/pthread_keycreate.c +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** - * sched/pthread/pthread_keycreate.c - * - * Copyright (C) 2007-2009, 2013, 2018 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include - -#include "sched/sched.h" -#include "pthread/pthread.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pthread_key_create - * - * Description: - * This function creates a thread-specific data key visible to all threads - * in the system. Although the same key value may be used by different - * threads, the values bound to the key by pthread_setspecific() are - * maintained on a per-thread basis and persist for the life of the calling - * thread. - * - * Upon key creation, the value NULL will be associated with the new key - * in all active threads. Upon thread creation, the value NULL will be - * associated with all defined keys in the new thread. - * - * Input Parameters: - * key - A pointer to the key to create. - * destructor - An optional destructor() function that may be associated - * with each key that is invoked when a thread exits. - * However, this argument is ignored in the current - * implementation. - * - * Returned Value: - * If successful, the pthread_key_create() function will store the newly - * created key value at *key and return zero (OK). Otherwise, an error - * number will be returned to indicate the error: - * - * EAGAIN - The system lacked sufficient resources to create another - * thread-specific data key, or the system-imposed limit on - * the total number of keys pers process {PTHREAD_KEYS_MAX} - * has been exceeded - * ENOMEM - Insufficient memory exist to create the key. - * - * POSIX Compatibility: - * - The present implementation ignores the destructor argument. - * - ****************************************************************************/ - -int pthread_key_create(FAR pthread_key_t *key, - CODE void (*destructor)(FAR void *)) -{ -#if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = this_task(); - FAR struct task_group_s *group = rtcb->group; - irqstate_t flags; - int candidate; - int ret = EAGAIN; - - DEBUGASSERT(key != NULL && group != NULL); - - /* Search for an unused key. This is done in a critical section here to - * avoid concurrent modification of the group keyset. - */ - - flags = spin_lock_irqsave(); - for (candidate = 0; candidate < PTHREAD_KEYS_MAX; candidate++) - { - /* Is this candidate key available? */ - - pthread_keyset_t mask = (1 << candidate); - if ((group->tg_keyset & mask) == 0) - { - /* Yes.. allocate the key and break out of the loop */ - - group->tg_keyset |= mask; - break; - } - } - - spin_unlock_irqrestore(flags); - - /* Check if found a valid key. */ - - if (candidate < PTHREAD_KEYS_MAX) - { - /* Yes.. Return the key value and success */ - - *key = candidate; - ret = OK; - } - - return ret; -#else - return ENOSYS; -#endif -} diff --git a/sched/pthread/pthread_keydelete.c b/sched/pthread/pthread_keydelete.c deleted file mode 100644 index da961e22d7..0000000000 --- a/sched/pthread/pthread_keydelete.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * sched/pthread/pthread_keydelete.c - * - * Copyright (C) 2007, 2009, 2018 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include - -#include "sched/sched.h" -#include "pthread/pthread.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pthread_key_delete - * - * Description: - * This POSIX function deletes a thread-specific data key - * previously returned by pthread_key_create(). - * - * Input Parameters: - * key - the key to delete - * - * Returned Value: - * Returns zero (OK) on success. EINVAL may be returned if an invalid - * key is received. - * - * POSIX Compatibility: - * - ****************************************************************************/ - -int pthread_key_delete(pthread_key_t key) -{ -#if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = this_task(); - FAR struct task_group_s *group = rtcb->group; - pthread_keyset_t mask; - irqstate_t flags; - int ret = EINVAL; - - DEBUGASSERT((unsigned)key < PTHREAD_KEYS_MAX && group != NULL); - if ((unsigned)key < PTHREAD_KEYS_MAX) - { - /* This is done in a critical section here to avoid concurrent - * modification of the group keyset. - */ - - mask = (1 << key); - flags = spin_lock_irqsave(); - - DEBUGASSERT((group->tg_keyset & mask) != 0); - group->tg_keyset &= ~mask; - spin_unlock_irqrestore(flags); - - ret = OK; - } - - return ret; -#else - return ENOSYS; -#endif -} diff --git a/sched/pthread/pthread_setspecific.c b/sched/pthread/pthread_setspecific.c deleted file mode 100644 index 980243dd57..0000000000 --- a/sched/pthread/pthread_setspecific.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * sched/pthread/pthread_setspecific.c - * - * Copyright (C) 2007-2009, 2013, 2018 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "sched/sched.h" -#include "pthread/pthread.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pthread_setspecific - * - * Description: - * The pthread_setspecific() function associates a thread- - * specific value with a key obtained via a previous call - * to pthread_key_create(). Different threads may bind - * different values to the same key. These values are - * typically pointers to blocks of dynamically allocated - * memory that have been reserved for use by the calling - * thread. - * - * The effect of calling pthread_setspecific() with - * a key value not obtained from pthread_key_create() or - * after a key has been deleted with pthread_key_delete() - * is undefined. - * - * Input Parameters: - * key = The data key to get or set - * value = The value to bind to the key. - * - * Returned Value: - * If successful, pthread_setspecific() will return zero (OK). - * Otherwise, an error number will be returned: - * - * ENOMEM - Insufficient memory exists to associate - * the value with the key. - * EINVAL - The key value is invalid. - * - * POSIX Compatibility: - * - Both pthread_setspecific() and pthread_getspecific() - * may be called from a thread-specific data destructor - * function. - * - ****************************************************************************/ - -int pthread_setspecific(pthread_key_t key, FAR const void *value) -{ -#if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = this_task(); - FAR struct task_group_s *group = rtcb->group; - int ret = EINVAL; - - DEBUGASSERT(group != NULL && (unsigned)key < CONFIG_NPTHREAD_KEYS); - - /* Check if the key is valid. */ - - if (key < CONFIG_NPTHREAD_KEYS && (group->tg_keyset & (1 << key)) != 0) - { - /* Store the data in the TCB. */ - - rtcb->pthread_data[key] = (FAR void *)value; - - /* Return success. */ - - ret = OK; - } - - return ret; -#else - return ENOSYS; -#endif -} diff --git a/syscall/syscall.csv b/syscall/syscall.csv index b28559978a..9f5a50539d 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -87,10 +87,7 @@ "pthread_exit","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void","pthread_addr_t" "pthread_getaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR cpu_set_t*" "pthread_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","FAR int *","FAR struct sched_param *" -"pthread_getspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","FAR void *","pthread_key_t" "pthread_join","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","FAR pthread_addr_t *" -"pthread_key_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_key_t *","CODE void (*)(FAR void*)" -"pthread_key_delete","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_key_t" "pthread_kill","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int" "pthread_mutex_consistent","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)","int","FAR pthread_mutex_t *" "pthread_mutex_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t *" @@ -101,7 +98,6 @@ "pthread_setaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR const cpu_set_t *" "pthread_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int","FAR const struct sched_param *" "pthread_setschedprio","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int" -"pthread_setspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_key_t","FAR const void *" "pthread_sigmask","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","int","FAR const sigset_t *","FAR sigset_t *" "putenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" "pwrite","unistd.h","","ssize_t","int","FAR const void *","size_t","off_t" @@ -175,6 +171,8 @@ "timer_getoverrun","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t" "timer_gettime","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t","FAR struct itimerspec *" "timer_settime","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t","int","FAR const struct itimerspec *","FAR struct itimerspec *" +"tls_alloc","nuttx/tls.h","CONFIG_TLS_NELEM > 0","int" +"tls_free","nuttx/tls.h","CONFIG_TLS_NELEM > 0","int","int" "umount2","sys/mount.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","unsigned int" "uname","sys/utsname.h","","int","FAR struct utsname *" "unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *"