2013-02-06 23:43:28 +08:00
|
|
|
/****************************************************************************
|
2021-03-09 05:39:04 +08:00
|
|
|
* sched/group/group_foreachchild.c
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
2024-09-11 19:45:11 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 23:33:58 +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
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +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.
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2024-03-06 10:13:47 +08:00
|
|
|
#include <nuttx/nuttx.h>
|
2013-02-06 23:43:28 +08:00
|
|
|
#include <nuttx/sched.h>
|
2024-03-06 10:13:47 +08:00
|
|
|
#include <nuttx/queue.h>
|
2013-02-06 23:43:28 +08:00
|
|
|
|
2014-08-09 04:06:42 +08:00
|
|
|
#include "group/group.h"
|
2013-02-06 23:43:28 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: group_foreachchild
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Execute a function for each child of a group.
|
|
|
|
*
|
2018-03-13 23:52:27 +08:00
|
|
|
* Input Parameters:
|
2013-02-06 23:43:28 +08:00
|
|
|
* group - The group containing the children
|
|
|
|
* handler - The function to be called
|
|
|
|
* arg - An additional argument to provide to the handler
|
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Returned Value:
|
2013-02-06 23:43:28 +08:00
|
|
|
* Success (OK) is always returned unless the handler returns a non-zero
|
|
|
|
* value (a negated errno on errors). In that case, the traversal
|
|
|
|
* terminates and that non-zero value is returned.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int group_foreachchild(FAR struct task_group_s *group,
|
|
|
|
foreachchild_t handler, FAR void *arg)
|
|
|
|
{
|
2024-03-06 10:13:47 +08:00
|
|
|
FAR sq_entry_t *curr;
|
|
|
|
FAR sq_entry_t *next;
|
2024-03-04 09:19:27 +08:00
|
|
|
int ret = OK;
|
2013-02-06 23:43:28 +08:00
|
|
|
|
|
|
|
DEBUGASSERT(group);
|
|
|
|
|
2018-11-08 21:03:30 +08:00
|
|
|
/* Visit the main thread last (if present) */
|
|
|
|
|
2024-03-06 10:13:47 +08:00
|
|
|
sq_for_every_safe(&group->tg_members, curr, next)
|
2013-02-06 23:43:28 +08:00
|
|
|
{
|
2024-03-06 10:13:47 +08:00
|
|
|
FAR struct tcb_s *mtcb =
|
|
|
|
container_of(curr, struct tcb_s, member);
|
|
|
|
|
|
|
|
ret = handler(mtcb->pid, arg);
|
|
|
|
if (ret != OK)
|
2015-10-08 09:59:14 +08:00
|
|
|
{
|
2024-03-06 10:13:47 +08:00
|
|
|
break;
|
2015-10-08 09:59:14 +08:00
|
|
|
}
|
2013-02-06 23:43:28 +08:00
|
|
|
}
|
|
|
|
|
2024-03-06 10:13:47 +08:00
|
|
|
return ret;
|
2013-02-06 23:43:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_GROUP_MEMBERS */
|