2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2016-08-07 16:25:30 +02:00
|
|
|
* sched/pthread/pthread_findjoininfo.c
|
2007-02-18 00:21:28 +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
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +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.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 20:30:18 +01:00
|
|
|
#include <nuttx/config.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sys/types.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2022-12-16 08:42:18 +01:00
|
|
|
#include <debug.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2014-08-08 20:55:02 +02:00
|
|
|
#include "pthread/pthread.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-12-16 08:42:18 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pthread_createjoininfo
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a detachable structure to support pthread_join logic and add
|
|
|
|
* the joininfo to the thread.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* ptcb
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* joininfo point.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR struct join_s *
|
|
|
|
pthread_createjoininfo(FAR struct pthread_tcb_s *ptcb)
|
|
|
|
{
|
|
|
|
FAR struct join_s *pjoin;
|
|
|
|
|
|
|
|
/* Allocate a detachable structure to support pthread_join logic */
|
|
|
|
|
|
|
|
pjoin = (FAR struct join_s *)kmm_zalloc(sizeof(struct join_s));
|
|
|
|
if (!pjoin)
|
|
|
|
{
|
|
|
|
serr("ERROR: Failed to allocate join\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pjoin->thread = (pthread_t)ptcb->cmn.pid;
|
|
|
|
|
|
|
|
/* Initialize the semaphore in the join structure to zero. */
|
|
|
|
|
|
|
|
if (nxsem_init(&pjoin->exit_sem, 0, 0) < 0)
|
|
|
|
{
|
|
|
|
kmm_free(pjoin);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FAR struct task_group_s *group = ptcb->cmn.group;
|
|
|
|
|
|
|
|
/* Attach the join info to the TCB. */
|
|
|
|
|
|
|
|
ptcb->joininfo = (FAR void *)pjoin;
|
|
|
|
|
|
|
|
pjoin->next = NULL;
|
|
|
|
if (!group->tg_jointail)
|
|
|
|
{
|
|
|
|
group->tg_joinhead = pjoin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
group->tg_jointail->next = pjoin;
|
|
|
|
}
|
|
|
|
|
|
|
|
group->tg_jointail = pjoin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pjoin;
|
|
|
|
}
|
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2022-12-16 08:42:18 +01:00
|
|
|
* Name: pthread_findjoininfo
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2013-02-03 17:43:58 +01:00
|
|
|
* Find a join structure in a local data set.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2020-03-16 20:42:34 +01:00
|
|
|
* group - The group that the pid is (or was) a member of
|
2013-02-03 17:43:58 +01:00
|
|
|
* pid - The ID of the pthread
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-02-18 00:21:28 +01:00
|
|
|
* None or pointer to the found entry.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The caller has provided protection from re-entrancy.
|
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-03 17:43:58 +01:00
|
|
|
FAR struct join_s *pthread_findjoininfo(FAR struct task_group_s *group,
|
|
|
|
pid_t pid)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-02-03 17:43:58 +01:00
|
|
|
FAR struct join_s *pjoin;
|
|
|
|
|
|
|
|
DEBUGASSERT(group);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Find the entry with the matching pid */
|
|
|
|
|
2013-02-03 17:43:58 +01:00
|
|
|
for (pjoin = group->tg_joinhead;
|
2007-02-20 23:39:56 +01:00
|
|
|
(pjoin && (pid_t)pjoin->thread != pid);
|
2007-02-18 00:21:28 +01:00
|
|
|
pjoin = pjoin->next);
|
|
|
|
|
|
|
|
/* and return it */
|
|
|
|
|
2022-12-16 08:42:18 +01:00
|
|
|
if (pjoin == NULL)
|
|
|
|
{
|
2023-02-13 13:38:42 +01:00
|
|
|
FAR struct tcb_s *tcb = nxsched_get_tcb(pid);
|
2022-12-16 08:42:18 +01:00
|
|
|
|
2023-01-13 14:38:00 +01:00
|
|
|
if (tcb != NULL && (tcb->flags & TCB_FLAG_DETACHED) == 0 &&
|
2023-02-10 07:41:36 +01:00
|
|
|
(tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD &&
|
|
|
|
tcb->group == group)
|
2022-12-16 08:42:18 +01:00
|
|
|
{
|
|
|
|
pjoin = pthread_createjoininfo((FAR struct pthread_tcb_s *)tcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
return pjoin;
|
|
|
|
}
|