2016-03-11 09:31:22 +08:00
|
|
|
/****************************************************************************
|
2020-05-08 21:23:26 +08:00
|
|
|
* sched/group/group_tlsfree.c
|
2016-03-11 09:31:22 +08:00
|
|
|
*
|
2020-05-05 23:52:15 +08: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 09:31:22 +08:00
|
|
|
*
|
2020-05-05 23:52:15 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-03-11 09:31:22 +08:00
|
|
|
*
|
2020-05-05 23:52:15 +08: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 09:31:22 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
2016-03-11 09:31:22 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
#include <nuttx/irq.h>
|
2016-03-11 09:31:22 +08:00
|
|
|
#include <nuttx/tls.h>
|
2020-05-08 21:23:26 +08:00
|
|
|
|
|
|
|
#include "sched/sched.h"
|
|
|
|
#include "group/group.h"
|
2016-03-11 09:31:22 +08:00
|
|
|
|
2020-05-07 23:46:47 +08:00
|
|
|
#if CONFIG_TLS_NELEM > 0
|
2016-03-11 09:31:22 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-08 21:23:26 +08:00
|
|
|
* Name: tls_free
|
2016-03-11 09:31:22 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-08 21:23:26 +08:00
|
|
|
* Release a group-unique TLS data index previous obtained by tls_alloc()
|
2016-03-11 09:31:22 +08:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-05-08 21:23:26 +08:00
|
|
|
* tlsindex - The previously allocated TLS index to be freed
|
2016-03-11 09:31:22 +08:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-05-08 21:23:26 +08: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 09:31:22 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
int tls_free(int tlsindex)
|
2016-03-11 09:31:22 +08:00
|
|
|
{
|
2020-05-08 21:23:26 +08: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 09:31:22 +08:00
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
DEBUGASSERT((unsigned)tlsindex < CONFIG_TLS_NELEM && group != NULL);
|
|
|
|
if ((unsigned)tlsindex < CONFIG_TLS_NELEM)
|
2016-03-11 09:31:22 +08:00
|
|
|
{
|
2020-05-08 21:23:26 +08:00
|
|
|
/* This is done in a critical section here to avoid concurrent
|
|
|
|
* modification of the group TLS index set.
|
|
|
|
*/
|
2016-03-11 09:31:22 +08:00
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
mask = (1 << tlsindex);
|
|
|
|
flags = spin_lock_irqsave();
|
2016-03-11 09:31:22 +08:00
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
DEBUGASSERT((group->tg_tlsset & mask) != 0);
|
|
|
|
group->tg_tlsset &= ~mask;
|
|
|
|
spin_unlock_irqrestore(flags);
|
2016-03-11 09:31:22 +08:00
|
|
|
|
2020-05-08 21:23:26 +08:00
|
|
|
ret = OK;
|
2016-03-11 09:31:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-07 23:46:47 +08:00
|
|
|
#endif /* CONFIG_TLS_NELEM > 0 */
|