2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* sched/group/group_join.c
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01: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
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01: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.
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 18:23:38 +01:00
|
|
|
* Included Files
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sched.h>
|
|
|
|
#include <assert.h>
|
2013-01-25 20:15:05 +01:00
|
|
|
#include <errno.h>
|
2013-01-25 18:23:38 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2013-01-25 20:15:05 +01:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
|
2014-08-09 02:39:28 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2014-08-08 21:53:29 +02:00
|
|
|
#include "environ/environ.h"
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2019-02-11 19:09:26 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 18:23:38 +01:00
|
|
|
* Public Functions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 20:15:05 +01:00
|
|
|
* Name: group_bind
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2024-03-06 03:13:47 +01:00
|
|
|
* A thread joins the group when it is created.
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-01-25 18:23:38 +01:00
|
|
|
* tcb - The TCB of the new "child" task that need to join the group.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - The parent task from which the group will be inherited is the task at
|
2017-05-11 21:35:56 +02:00
|
|
|
* the head of the ready to run list.
|
2013-01-25 18:23:38 +01:00
|
|
|
* - Called during thread creation in a safe context. No special precautions
|
|
|
|
* are required here.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2024-06-06 09:03:40 +02:00
|
|
|
void group_bind(FAR struct pthread_tcb_s *tcb)
|
2013-01-25 18:23:38 +01:00
|
|
|
{
|
2016-02-07 00:44:41 +01:00
|
|
|
FAR struct tcb_s *ptcb = this_task();
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2013-02-04 23:38:59 +01:00
|
|
|
DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->cmn.group);
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2013-01-25 20:15:05 +01:00
|
|
|
/* Copy the group reference from the parent to the child */
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2013-02-04 23:38:59 +01:00
|
|
|
tcb->cmn.group = ptcb->group;
|
2013-01-25 20:15:05 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 20:15:05 +01:00
|
|
|
* Name: group_join
|
|
|
|
*
|
|
|
|
* Description:
|
2024-03-06 03:13:47 +01:00
|
|
|
* A thread joins the group when it is created.
|
2013-01-25 20:15:05 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-01-25 20:15:05 +01:00
|
|
|
* tcb - The TCB of the new "child" task that need to join the group.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - The parent task from which the group will be inherited is the task at
|
2017-05-11 21:35:56 +02:00
|
|
|
* the head of the ready to run list.
|
2013-01-25 20:15:05 +01:00
|
|
|
* - Called during thread creation in a safe context. No special precautions
|
|
|
|
* are required here.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 20:15:05 +01:00
|
|
|
|
2024-06-06 09:03:40 +02:00
|
|
|
void group_join(FAR struct pthread_tcb_s *tcb)
|
2013-01-25 20:15:05 +01:00
|
|
|
{
|
|
|
|
FAR struct task_group_s *group;
|
2023-05-08 03:16:32 +02:00
|
|
|
irqstate_t flags;
|
2013-01-25 20:15:05 +01:00
|
|
|
|
2024-03-06 03:13:47 +01:00
|
|
|
DEBUGASSERT(tcb && tcb->cmn.group);
|
2013-01-25 20:15:05 +01:00
|
|
|
|
|
|
|
/* Get the group from the TCB */
|
|
|
|
|
2013-02-04 23:38:59 +01:00
|
|
|
group = tcb->cmn.group;
|
2013-01-26 18:28:20 +01:00
|
|
|
|
|
|
|
/* Add the member to the group */
|
|
|
|
|
2023-05-08 03:16:32 +02:00
|
|
|
flags = spin_lock_irqsave(NULL);
|
2024-03-06 03:13:47 +01:00
|
|
|
sq_addfirst(&tcb->cmn.member, &group->tg_members);
|
2023-05-08 03:16:32 +02:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2013-01-26 18:28:20 +01:00
|
|
|
}
|
|
|
|
|
2019-02-11 19:09:26 +01:00
|
|
|
#endif /* !CONFIG_DISABLE_PTHREAD */
|