mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
Revert "tls: Move pthread key destructor to libc"
This reverts commit cc514d7791.
* It introduced a regression.
https://github.com/apache/incubator-nuttx/issues/3868
* It seems conceptually wrong to have per-process data in
the main thread's stack.
This commit is contained in:
committed by
Xiang Xiao
parent
8079d9fac3
commit
b3e8535ad6
@@ -53,6 +53,11 @@ 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
|
||||
CSRCS += group_tlsgetset.c group_tlsgetdtor.c group_tlssetdtor.c
|
||||
endif
|
||||
|
||||
# Include group build support
|
||||
|
||||
DEPPATH += --dep-path group
|
||||
|
||||
@@ -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/spinlock.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(NULL);
|
||||
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(NULL, 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 */
|
||||
@@ -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/spinlock.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(NULL);
|
||||
|
||||
DEBUGASSERT((group->tg_tlsset & mask) != 0);
|
||||
group->tg_tlsset &= ~mask;
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TLS_NELEM > 0 */
|
||||
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
* sched/group/group_tlsgetdtor.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 <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/tls.h>
|
||||
#include <arch/tls.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
|
||||
#if CONFIG_TLS_NELEM > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tls_get_dtor
|
||||
*
|
||||
* Description:
|
||||
* Get the TLS element destructor associated with the 'tlsindex' to 'destr'
|
||||
*
|
||||
* Input Parameters:
|
||||
* tlsindex - Index of TLS data destructor to get
|
||||
*
|
||||
* Returned Value:
|
||||
* A non-null destruct function pointer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
tls_dtor_t tls_get_dtor(int tlsindex)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct task_group_s *group = rtcb->group;
|
||||
irqstate_t flags;
|
||||
tls_dtor_t destr;
|
||||
|
||||
DEBUGASSERT(group != NULL);
|
||||
DEBUGASSERT(tlsindex >= 0 && tlsindex < CONFIG_TLS_NELEM);
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
destr = group->tg_tlsdestr[tlsindex];
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
|
||||
return destr;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TLS_NELEM > 0 */
|
||||
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
* sched/group/group_tlsgetset.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 <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/tls.h>
|
||||
#include <arch/tls.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
|
||||
#if CONFIG_TLS_NELEM > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tls_get_set
|
||||
*
|
||||
* Description:
|
||||
* Get the set map of TLE element index.
|
||||
*
|
||||
* Input Parameters:
|
||||
*
|
||||
* Returned Value:
|
||||
* TLS element index set map.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
tls_ndxset_t tls_get_set(void)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct task_group_s *group = rtcb->group;
|
||||
irqstate_t flags;
|
||||
tls_ndxset_t tlsset;
|
||||
|
||||
DEBUGASSERT(group != NULL);
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
tlsset = group->tg_tlsset;
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
|
||||
return tlsset;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TLS_NELEM > 0 */
|
||||
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* sched/group/group_tlssetdtor.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 <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/tls.h>
|
||||
#include <arch/tls.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
|
||||
#if CONFIG_TLS_NELEM > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tls_set_dtor
|
||||
*
|
||||
* Description:
|
||||
* Set the TLS element destructor associated with the 'tlsindex' to 'destr'
|
||||
*
|
||||
* Input Parameters:
|
||||
* tlsindex - Index of TLS data destructor to set
|
||||
* destr - The destr of TLS data element
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success, a negated errno value is return on
|
||||
* failure:
|
||||
*
|
||||
* EINVAL - tlsindex is not in range.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int tls_set_dtor(int tlsindex, tls_dtor_t destr)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct task_group_s *group = rtcb->group;
|
||||
irqstate_t flags;
|
||||
|
||||
DEBUGASSERT(group != NULL);
|
||||
DEBUGASSERT(tlsindex >= 0 && tlsindex < CONFIG_TLS_NELEM);
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
group->tg_tlsdestr[tlsindex] = destr;
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TLS_NELEM > 0 */
|
||||
@@ -142,14 +142,6 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
|
||||
|
||||
DEBUGASSERT(info == tcb->cmn.stack_alloc_ptr);
|
||||
|
||||
ret = task_setup_info(info);
|
||||
|
||||
if (ret < OK)
|
||||
{
|
||||
ret = -EINVAL;
|
||||
goto errout_with_group;
|
||||
}
|
||||
|
||||
/* Initialize the task control block */
|
||||
|
||||
ret = nxtask_setup_scheduler(tcb, priority, nxtask_start,
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
#include <nuttx/signal.h>
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "pthread/pthread.h"
|
||||
@@ -722,28 +721,3 @@ int nxtask_setup_arguments(FAR struct task_tcb_s *tcb, FAR const char *name,
|
||||
|
||||
return nxtask_setup_stackargs(tcb, argv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: task_setup_info
|
||||
*
|
||||
* Description:
|
||||
* Setup task_info_s for task
|
||||
*
|
||||
* Input Parameters:
|
||||
* info - New created task_info_s
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; ERROR on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int task_setup_info(FAR struct task_info_s *info)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
#if CONFIG_TLS_NELEM > 0
|
||||
ret = _SEM_INIT(&info->ta_tlssem, 0, 1);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user