libc: Move pthread_key_destructor to task_info_s

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi
2021-06-29 16:01:02 +08:00
committed by Xiang Xiao
parent ece224a7e3
commit 50c08bf45b
13 changed files with 66 additions and 354 deletions
-5
View File
@@ -53,11 +53,6 @@ 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
+5
View File
@@ -180,6 +180,10 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype)
goto errout_with_stream;
}
/* Initial user space semaphore */
nxsem_init(&group->tg_info->ta_sem, 0, 1);
/* Attach the group to the TCB */
tcb->cmn.group = group;
@@ -242,6 +246,7 @@ void group_deallocate(FAR struct task_group_s *group)
{
if (group->tg_info)
{
nxsem_destroy(&group->tg_info->ta_sem);
group_free(group, group->tg_info);
}
-101
View File
@@ -1,101 +0,0 @@
/****************************************************************************
* 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 */
-88
View File
@@ -1,88 +0,0 @@
/****************************************************************************
* 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 */
-75
View File
@@ -1,75 +0,0 @@
/****************************************************************************
* 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 */
-73
View File
@@ -1,73 +0,0 @@
/****************************************************************************
* 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 */
-78
View File
@@ -1,78 +0,0 @@
/****************************************************************************
* 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 */