sched: move POSIX thread specific data from pthread TCB to common TCB structure. This change allows using pthread_getspecific/pthread_setspecific from main thread. Patch also enables using pthread data with config option CONFIG_DISABLE_PTHREAD=y.
This commit is contained in:
parent
6163033439
commit
8eaa587c98
5 changed files with 30 additions and 26 deletions
|
@ -466,6 +466,8 @@ struct task_group_s
|
|||
sem_t tg_joinsem; /* Mutually exclusive access to join data */
|
||||
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
|
||||
uint8_t tg_nkeys; /* Number pthread keys allocated */
|
||||
#endif
|
||||
|
||||
|
@ -633,6 +635,12 @@ 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
|
||||
|
||||
/* Library related fields *****************************************************/
|
||||
|
||||
int pterrno; /* Current per-thread errno */
|
||||
|
@ -713,12 +721,6 @@ struct pthread_tcb_s
|
|||
uint8_t tos;
|
||||
struct pthread_cleanup_s stack[CONFIG_PTHREAD_CLEANUP_STACKSIZE];
|
||||
#endif
|
||||
|
||||
/* POSIX Thread Specific Data *************************************************/
|
||||
|
||||
#if CONFIG_NPTHREAD_KEYS > 0
|
||||
FAR void *pthread_data[CONFIG_NPTHREAD_KEYS];
|
||||
#endif
|
||||
};
|
||||
#endif /* !CONFIG_DISABLE_PTHREAD */
|
||||
|
||||
|
|
|
@ -522,7 +522,15 @@ config SCHED_WAITPID
|
|||
endmenu # Tasks and Scheduling
|
||||
|
||||
menu "Pthread Options"
|
||||
depends on !DISABLE_PTHREAD
|
||||
|
||||
config NPTHREAD_KEYS
|
||||
int "Maximum number of pthread keys"
|
||||
default 4 if !DISABLE_PTHREAD
|
||||
default 0 if DISABLE_PTHREAD
|
||||
---help---
|
||||
The number of items of thread-specific data that can be retained
|
||||
|
||||
if !DISABLE_PTHREAD
|
||||
|
||||
config PTHREAD_MUTEX_TYPES
|
||||
bool "Enable mutex types"
|
||||
|
@ -573,13 +581,6 @@ config PTHREAD_MUTEX_DEFAULT_UNSAFE
|
|||
|
||||
endchoice # Default NORMAL mutex robustness
|
||||
|
||||
config NPTHREAD_KEYS
|
||||
int "Maximum number of pthread keys"
|
||||
default 4
|
||||
---help---
|
||||
The number of items of thread-
|
||||
specific data that can be retained
|
||||
|
||||
config PTHREAD_CLEANUP
|
||||
bool "pthread cleanup stack"
|
||||
default n
|
||||
|
@ -609,6 +610,8 @@ config CANCELLATION_POINTS
|
|||
cancellation points will also used with the () task_delete() API even if
|
||||
pthreads are not enabled.
|
||||
|
||||
endif # !DISABLE_PTHREAD
|
||||
|
||||
endmenu # Pthread Options
|
||||
|
||||
menu "Performance Monitoring"
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#
|
||||
############################################################################
|
||||
|
||||
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
|
||||
|
@ -41,8 +44,6 @@ CSRCS += pthread_mutexinit.c pthread_mutexdestroy.c
|
|||
CSRCS += pthread_mutexlock.c pthread_mutextrylock.c pthread_mutexunlock.c
|
||||
CSRCS += pthread_condwait.c pthread_condsignal.c pthread_condbroadcast.c
|
||||
CSRCS += pthread_cancel.c
|
||||
CSRCS += pthread_keycreate.c pthread_setspecific.c pthread_getspecific.c
|
||||
CSRCS += pthread_keydelete.c
|
||||
CSRCS += pthread_initialize.c pthread_completejoin.c pthread_findjoininfo.c
|
||||
CSRCS += pthread_release.c pthread_setschedprio.c
|
||||
|
||||
|
@ -62,9 +63,9 @@ ifeq ($(CONFIG_PTHREAD_CLEANUP),y)
|
|||
CSRCS += pthread_cleanup.c
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
# Include pthread build support
|
||||
|
||||
DEPPATH += --dep-path pthread
|
||||
VPATH += :pthread
|
||||
|
||||
endif
|
||||
|
|
|
@ -84,12 +84,11 @@
|
|||
FAR void *pthread_getspecific(pthread_key_t key)
|
||||
{
|
||||
#if CONFIG_NPTHREAD_KEYS > 0
|
||||
FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)this_task();
|
||||
FAR struct task_group_s *group = rtcb->cmn.group;
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct task_group_s *group = rtcb->group;
|
||||
FAR void *ret = NULL;
|
||||
|
||||
DEBUGASSERT(group &&
|
||||
(rtcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD);
|
||||
DEBUGASSERT(group);
|
||||
|
||||
/* Check if the key is valid. */
|
||||
|
||||
|
|
|
@ -95,12 +95,11 @@
|
|||
int pthread_setspecific(pthread_key_t key, FAR const void *value)
|
||||
{
|
||||
#if CONFIG_NPTHREAD_KEYS > 0
|
||||
FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)this_task();
|
||||
FAR struct task_group_s *group = rtcb->cmn.group;
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct task_group_s *group = rtcb->group;
|
||||
int ret = EINVAL;
|
||||
|
||||
DEBUGASSERT(group &&
|
||||
(rtcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD);
|
||||
DEBUGASSERT(group);
|
||||
|
||||
/* Check if the key is valid. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue