mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
sched: Implement task local storage
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
+93
-1
@@ -83,6 +83,20 @@ typedef CODE void (*tls_dtor_t)(FAR void *);
|
||||
|
||||
#endif
|
||||
|
||||
#if CONFIG_TLS_TASK_NELEM > 0
|
||||
# if CONFIG_TLS_TASK_NELEM > 64
|
||||
# error Too many TLS elements
|
||||
# elif CONFIG_TLS_TASK_NELEM > 32
|
||||
typedef uint64_t tls_task_ndxset_t;
|
||||
# elif CONFIG_TLS_TASK_NELEM > 16
|
||||
typedef uint32_t tls_task_ndxset_t;
|
||||
# elif CONFIG_TLS_TASK_NELEM > 8
|
||||
typedef uint16_t tls_task_ndxset_t;
|
||||
# else
|
||||
typedef uint8_t tls_task_ndxset_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This structure encapsulates all variables associated with getopt(). */
|
||||
|
||||
struct getopt_s
|
||||
@@ -104,6 +118,9 @@ struct task_info_s
|
||||
{
|
||||
sem_t ta_sem;
|
||||
FAR char **argv; /* Name+start-up parameters */
|
||||
#if CONFIG_TLS_TASK_NELEM > 0
|
||||
uintptr_t ta_telem[CONFIG_TLS_TASK_NELEM]; /* Task local storage elements */
|
||||
#endif
|
||||
#if CONFIG_TLS_NELEM > 0
|
||||
tls_ndxset_t ta_tlsset; /* Set of TLS indexes allocated */
|
||||
tls_dtor_t ta_tlsdtor[CONFIG_TLS_NELEM]; /* List of TLS destructors */
|
||||
@@ -269,6 +286,81 @@ uintptr_t tls_get_value(int tlsindex);
|
||||
int tls_set_value(int tlsindex, uintptr_t tlsvalue);
|
||||
#endif
|
||||
|
||||
#if CONFIG_TLS_TASK_NELEM > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Name: task_tls_allocs
|
||||
*
|
||||
* Description:
|
||||
* Allocate a global-unique task local storage data index
|
||||
*
|
||||
* Input Parameters:
|
||||
* dtor - The destructor of task local storage data element
|
||||
*
|
||||
* Returned Value:
|
||||
* A TLS index that is unique.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int task_tls_alloc(tls_dtor_t dtor);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: task_tls_destruct
|
||||
*
|
||||
* Description:
|
||||
* Destruct all TLS data element associated with allocated key
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void task_tls_destruct(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: task_tls_set_value
|
||||
*
|
||||
* Description:
|
||||
* Set the task local storage element associated with the 'tlsindex' to
|
||||
* 'tlsvalue'
|
||||
*
|
||||
* Input Parameters:
|
||||
* tlsindex - Index of task local storage data element to set
|
||||
* tlsvalue - The new value of the task local storage data element
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success, a negated errno value is return on
|
||||
* failure:
|
||||
*
|
||||
* EINVAL - tlsindex is not in range.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int task_tls_set_value(int tlsindex, uintptr_t tlsvalue);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: task_tls_get_value
|
||||
*
|
||||
* Description:
|
||||
* Return an the task local storage data value associated with 'tlsindx'
|
||||
*
|
||||
* Input Parameters:
|
||||
* tlsindex - Index of task local storage 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_TASK_NELEM.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uintptr_t task_tls_get_value(int tlsindex);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tls_get_info
|
||||
*
|
||||
@@ -300,7 +392,7 @@ FAR struct tls_info_s *tls_get_info(void);
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* A set of allocated TLS index
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
@@ -105,6 +105,10 @@ SYSCALL_LOOKUP(up_assert, 2)
|
||||
SYSCALL_LOOKUP(task_testcancel, 0)
|
||||
#endif
|
||||
|
||||
#if CONFIG_TLS_TASK_NELEM > 0
|
||||
SYSCALL_LOOKUP(task_tls_alloc, 1)
|
||||
#endif
|
||||
|
||||
/* The following can be individually enabled */
|
||||
|
||||
#if defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_ARCH_HAVE_VFORK)
|
||||
|
||||
Reference in New Issue
Block a user