diff --git a/sched/group/group_create.c b/sched/group/group_create.c index e5347ff541..319eadffe3 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -35,10 +35,10 @@ #include #include #include -#include #include "sched/sched.h" #include "group/group.h" +#include "tls/tls.h" /**************************************************************************** * Pre-processor Definitions @@ -185,9 +185,8 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) /* Alloc task info for group */ - group->tg_info = (FAR struct task_info_s *) - group_zalloc(group, sizeof(struct task_info_s)); - if (!group->tg_info) + ret = task_init_info(group); + if (ret < 0) { goto errout_with_member; } @@ -200,10 +199,6 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) group_inherit_identity(group); - /* Initial user space semaphore */ - - nxsem_init(&group->tg_info->ta_sem, 0, 1); - /* Initialize file descriptors for the TCB */ files_initlist(&group->tg_filelist); diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 935b3cfc91..d4bda7d599 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -44,6 +44,7 @@ #include "pthread/pthread.h" #include "mqueue/mqueue.h" #include "group/group.h" +#include "tls/tls.h" /**************************************************************************** * Private Functions @@ -137,8 +138,7 @@ static inline void group_release(FAR struct task_group_s *group) task_tls_destruct(); #endif - nxsem_destroy(&group->tg_info->ta_sem); - group_free(group, group->tg_info); + task_uninit_info(group); #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) /* Free all un-reaped child exit status */ diff --git a/sched/tls/Make.defs b/sched/tls/Make.defs index 10f81dcdef..a5ea535f4d 100644 --- a/sched/tls/Make.defs +++ b/sched/tls/Make.defs @@ -18,7 +18,7 @@ # ############################################################################ -CSRCS += tls_initinfo.c tls_dupinfo.c +CSRCS += task_initinfo.c task_uninitinfo.c tls_initinfo.c tls_dupinfo.c # Include tls build support diff --git a/sched/tls/task_initinfo.c b/sched/tls/task_initinfo.c new file mode 100644 index 0000000000..4ccf1e9f7e --- /dev/null +++ b/sched/tls/task_initinfo.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * sched/tls/task_initinfo.c + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "tls.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: task_init_info + * + * Description: + * Allocate and initilize task_info_s structure. + * + * Input Parameters: + * - group: The group of new task + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int task_init_info(FAR struct task_group_s *group) +{ + FAR struct task_info_s *info; + + /* Allocate task info for group */ + + info = group_zalloc(group, sizeof(struct task_info_s)); + if (info == NULL) + { + return -ENOMEM; + } + + /* Initialize user space semaphore */ + + nxsem_init(&info->ta_sem, 0, 1); + group->tg_info = info; + + return OK; +} diff --git a/sched/tls/task_uninitinfo.c b/sched/tls/task_uninitinfo.c new file mode 100644 index 0000000000..f4dca8903e --- /dev/null +++ b/sched/tls/task_uninitinfo.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * sched/tls/task_uninitinfo.c + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "tls.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: task_uninit_info + * + * Description: + * Uninitilize and free task_info_s structure. + * + * Input Parameters: + * - group: The group of new task + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void task_uninit_info(FAR struct task_group_s *group) +{ + FAR struct task_info_s *info = group->tg_info; + + nxsem_destroy(&info->ta_sem); + group_free(group, info); +} diff --git a/sched/tls/tls.h b/sched/tls/tls.h index af04963d11..e9adeacda0 100644 --- a/sched/tls/tls.h +++ b/sched/tls/tls.h @@ -31,6 +31,38 @@ * Public Function Prototypes ****************************************************************************/ +/**************************************************************************** + * Name: task_init_info + * + * Description: + * Allocate and initilize task_info_s structure. + * + * Input Parameters: + * - group: The group of new task + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int task_init_info(FAR struct task_group_s *group); + +/**************************************************************************** + * Name: task_uninit_info + * + * Description: + * Uninitilize and free task_info_s structure. + * + * Input Parameters: + * - group: The group of new task + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void task_uninit_info(FAR struct task_group_s *group); + /**************************************************************************** * Name: tls_init_info *