2016-03-11 02:31:22 +01:00
|
|
|
/****************************************************************************
|
2020-05-08 15:23:26 +02:00
|
|
|
* sched/group/group_tlsfree.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 <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_free
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-08 15:23:26 +02:00
|
|
|
* Release a group-unique TLS data index previous obtained by tls_alloc()
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-05-08 15:23:26 +02:00
|
|
|
* tlsindex - The previously allocated TLS index to be freed
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-05-08 15:23:26 +02:00
|
|
|
* OK is returned on success; a negated errno value will be returned on
|
|
|
|
* failure:
|
|
|
|
*
|
|
|
|
* -EINVAL - the index to be freed is out of range.
|
2016-03-11 02:31:22 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
int tls_free(int tlsindex)
|
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;
|
|
|
|
tls_ndxset_t mask;
|
|
|
|
irqstate_t flags;
|
|
|
|
int ret = -EINVAL;
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
DEBUGASSERT((unsigned)tlsindex < CONFIG_TLS_NELEM && group != NULL);
|
|
|
|
if ((unsigned)tlsindex < CONFIG_TLS_NELEM)
|
2016-03-11 02:31:22 +01:00
|
|
|
{
|
2020-05-08 15:23:26 +02:00
|
|
|
/* This is done in a critical section here to avoid concurrent
|
|
|
|
* modification of the group TLS index set.
|
|
|
|
*/
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
mask = (1 << tlsindex);
|
|
|
|
flags = spin_lock_irqsave();
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
DEBUGASSERT((group->tg_tlsset & mask) != 0);
|
|
|
|
group->tg_tlsset &= ~mask;
|
|
|
|
spin_unlock_irqrestore(flags);
|
2016-03-11 02:31:22 +01:00
|
|
|
|
2020-05-08 15:23:26 +02:00
|
|
|
ret = OK;
|
2016-03-11 02:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-07 17:46:47 +02:00
|
|
|
#endif /* CONFIG_TLS_NELEM > 0 */
|