2016-03-11 02:31:22 +01:00
|
|
|
/****************************************************************************
|
2020-05-08 15:23:26 +02:00
|
|
|
* sched/group/group_tlsalloc.c
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
2020-05-05 17:52:15 +02:00
|
|
|
* 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
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
2020-05-05 17:52:15 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
2020-05-05 17:52:15 +02:00
|
|
|
* 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.
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
2016-03-11 02:31:22 +01:00
|
|
|
#include <assert.h>
|
2020-05-08 15:23:26 +02:00
|
|
|
#include <debug.h>
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
#include <nuttx/irq.h>
|
2016-03-11 02:31:22 +01:00
|
|
|
#include <nuttx/tls.h>
|
2020-05-08 15:23:26 +02:00
|
|
|
|
|
|
|
#include "sched/sched.h"
|
|
|
|
#include "group/group.h"
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-07 17:46:47 +02:00
|
|
|
#if CONFIG_TLS_NELEM > 0
|
2016-03-11 02:31:22 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-08 15:23:26 +02:00
|
|
|
* Name: tls_alloc
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-08 15:23:26 +02:00
|
|
|
* Allocate a group-unique TLS data index
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-05-08 15:23:26 +02:00
|
|
|
* None
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-05-08 15:23:26 +02:00
|
|
|
* A TLS index that is unique for use within this task group.
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
int tls_alloc(void)
|
2016-03-11 02:31:22 +01:00
|
|
|
{
|
2020-05-08 15:23:26 +02:00
|
|
|
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);
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
/* Search for an unused index. This is done in a critical section here to
|
|
|
|
* avoid concurrent modification of the group TLS index set.
|
|
|
|
*/
|
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
flags = spin_lock_irqsave(NULL);
|
2020-05-08 15:23:26 +02:00
|
|
|
for (candidate = 0; candidate < CONFIG_TLS_NELEM; candidate++)
|
2016-03-11 02:31:22 +01:00
|
|
|
{
|
2020-05-08 15:23:26 +02:00
|
|
|
/* 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 */
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
group->tg_tlsset |= mask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
/* Check if found a valid TLS data index. */
|
|
|
|
|
|
|
|
if (candidate < CONFIG_TLS_NELEM)
|
|
|
|
{
|
|
|
|
/* Yes.. Return the TLS index and success */
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
ret = candidate;
|
2016-03-11 02:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-07 17:46:47 +02:00
|
|
|
#endif /* CONFIG_TLS_NELEM > 0 */
|