diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-05 19:50:37 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-05 19:50:37 +0000 |
commit | 0d9fb476ea6f347c48a3ac8c2d98251467421203 (patch) | |
tree | e98b731e1ff4298ed906fde23198fb4d9a9d61a9 /nuttx/sched/group_join.c | |
parent | 70121d6ca8fd0e48f35b3ccb52e3b960e64df6c2 (diff) | |
download | px4-nuttx-0d9fb476ea6f347c48a3ac8c2d98251467421203.tar.gz px4-nuttx-0d9fb476ea6f347c48a3ac8c2d98251467421203.tar.bz2 px4-nuttx-0d9fb476ea6f347c48a3ac8c2d98251467421203.zip |
Moving pending signals to task group; Logic to recover some MQ resources on pthread_cacancel or task_delete; Now obeys rules for delivering signals to a process with threads
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5613 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/group_join.c')
-rw-r--r-- | nuttx/sched/group_join.c | 129 |
1 files changed, 69 insertions, 60 deletions
diff --git a/nuttx/sched/group_join.c b/nuttx/sched/group_join.c index f6babb871..d6ca6d498 100644 --- a/nuttx/sched/group_join.c +++ b/nuttx/sched/group_join.c @@ -71,6 +71,75 @@ *****************************************************************************/ /***************************************************************************** + * Name: group_addmember + * + * Description: + * Add a new member to a group. + * + * Parameters: + * group - The task group to add the new member + * pid - The new member + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * Called during thread creation and during reparenting in a safe context. + * No special precautions are required here. + * + *****************************************************************************/ + +#ifdef HAVE_GROUP_MEMBERS +static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) +{ + irqstate_t flags; + + DEBUGASSERT(group && group->tg_nmembers < UINT8_MAX); + + /* Will we need to extend the size of the array of groups? */ + + if (group->tg_nmembers >= group->tg_mxmembers) + { + FAR pid_t *newmembers; + unsigned int newmax; + + /* Yes... reallocate the array of members */ + + newmax = group->tg_mxmembers + GROUP_REALLOC_MEMBERS; + if (newmax > UINT8_MAX) + { + newmax = UINT8_MAX; + } + + newmembers = (FAR pid_t *) + krealloc(group->tg_members, sizeof(pid_t) * newmax); + + if (!newmembers) + { + return -ENOMEM; + } + + /* Save the new number of members in the reallocated members array. + * We need to make the following atomic because the member list + * may be traversed from an interrupt handler (read-only). + */ + + flags = irqsave(); + group->tg_members = newmembers; + group->tg_mxmembers = newmax; + irqrestore(flags); + } + + /* Assign this new pid to the group; group->tg_nmembers will be incremented + * by the caller. + */ + + group->tg_members[group->tg_nmembers] = pid; + return OK; +} +#endif /* HAVE_GROUP_MEMBERS */ + +/***************************************************************************** * Public Functions *****************************************************************************/ @@ -164,64 +233,4 @@ int group_join(FAR struct pthread_tcb_s *tcb) return OK; } -/***************************************************************************** - * Name: group_addmember - * - * Description: - * Add a new member to a group. - * - * Parameters: - * group - The task group to add the new member - * pid - The new member - * - * Return Value: - * 0 (OK) on success; a negated errno value on failure. - * - * Assumptions: - * Called during thread creation and during reparenting in a safe context. - * No special precautions are required here. - * - *****************************************************************************/ - -#ifdef HAVE_GROUP_MEMBERS -int group_addmember(FAR struct task_group_s *group, pid_t pid) -{ - DEBUGASSERT(group && group->tg_nmembers < UINT8_MAX); - - /* Will we need to extend the size of the array of groups? */ - - if (group->tg_nmembers >= group->tg_mxmembers) - { - FAR pid_t *newmembers; - unsigned int newmax; - - /* Yes... reallocate the array of members */ - - newmax = group->tg_mxmembers + GROUP_REALLOC_MEMBERS; - if (newmax > UINT8_MAX) - { - newmax = UINT8_MAX; - } - - newmembers = (FAR pid_t *) - krealloc(group->tg_members, sizeof(pid_t) * newmax); - - if (!newmembers) - { - return -ENOMEM; - } - - /* Save the new number of members in the reallocated members array */ - - group->tg_members = newmembers; - group->tg_mxmembers = newmax; - } - - /* Assign this new pid to the group. */ - - group->tg_members[group->tg_nmembers] = pid; - return OK; -} -#endif /* HAVE_GROUP_MEMBERS */ - #endif /* HAVE_TASK_GROUP && !CONFIG_DISABLE_PTHREAD */ |