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()
This commit is contained in:
parent
a6c82a27db
commit
9ce03b1660
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,36 +1,20 @@
|
||||
/********************************************************************************
|
||||
* include/sched.h
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011, 2013, 2015-2016, 2020 Gregory Nutt. All
|
||||
* rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
* 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 ****************************************************/
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
63
libs/libc/pthread/pthread_getspecific.c
Normal file
63
libs/libc/pthread/pthread_getspecific.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <nuttx/tls.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)
|
||||
{
|
||||
return (FAR void *)tls_get_value((int)key);
|
||||
}
|
99
libs/libc/pthread/pthread_keycreate.c
Normal file
99
libs/libc/pthread/pthread_keycreate.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
#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 */
|
59
libs/libc/pthread/pthread_keydelete.c
Normal file
59
libs/libc/pthread/pthread_keydelete.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <nuttx/tls.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)
|
||||
{
|
||||
/* Free the TLS index */
|
||||
|
||||
int ret = tls_free((int)key);
|
||||
return ret < 0 ? -ret : 0;
|
||||
}
|
80
libs/libc/pthread/pthread_setspecific.c
Normal file
80
libs/libc/pthread/pthread_setspecific.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
#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 */
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
@ -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 */
|
@ -1,35 +1,20 @@
|
||||
############################################################################
|
||||
# sched/group/Make.defs
|
||||
#
|
||||
# Copyright (C) 2014, 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
# 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
|
||||
|
101
sched/group/group_tlsalloc.c
Normal file
101
sched/group/group_tlsalloc.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
#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 */
|
88
sched/group/group_tlsfree.c
Normal file
88
sched/group/group_tlsfree.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
#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 */
|
@ -1,41 +1,23 @@
|
||||
############################################################################
|
||||
# sched/pthread/Make.defs
|
||||
#
|
||||
# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
# 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
|
||||
|
@ -1,101 +0,0 @@
|
||||
/****************************************************************************
|
||||
* sched/pthread/pthread_getspecific.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2013, 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#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
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
/****************************************************************************
|
||||
* sched/pthread/pthread_keycreate.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2013, 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#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
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/****************************************************************************
|
||||
* sched/pthread/pthread_keydelete.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#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
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/****************************************************************************
|
||||
* sched/pthread/pthread_setspecific.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2013, 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#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
|
||||
}
|
@ -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 *"
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
Loading…
Reference in New Issue
Block a user