This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 01c8bebf585102dad56b64491b3bf2b49f2675c4
Author: Xiang Xiao <xiaoxi...@xiaomi.com>
AuthorDate: Sat May 28 04:58:16 2022 +0800

    sched/tls: Add task_init_info and task_uninit_info
    
    Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
---
 sched/group/group_create.c             | 11 ++-----
 sched/group/group_leave.c              |  4 +--
 sched/tls/Make.defs                    |  2 +-
 sched/tls/{tls.h => task_initinfo.c}   | 54 ++++++++++++++++++----------------
 sched/tls/{tls.h => task_uninitinfo.c} | 44 ++++++++++-----------------
 sched/tls/tls.h                        | 32 ++++++++++++++++++++
 6 files changed, 82 insertions(+), 65 deletions(-)

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 <nuttx/lib/lib.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/sched.h>
-#include <nuttx/tls.h>
 
 #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/tls.h b/sched/tls/task_initinfo.c
similarity index 66%
copy from sched/tls/tls.h
copy to sched/tls/task_initinfo.c
index af04963d11..4ccf1e9f7e 100644
--- a/sched/tls/tls.h
+++ b/sched/tls/task_initinfo.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * sched/tls/tls.h
+ * 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
@@ -18,50 +18,52 @@
  *
  ****************************************************************************/
 
-#ifndef __SCHED_TLS_TLS_H
-#define __SCHED_TLS_TLS_H
-
 /****************************************************************************
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/sched.h>
+#include <errno.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/tls.h>
+
+#include "tls.h"
 
 /****************************************************************************
- * Public Function Prototypes
+ * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: tls_init_info
+ * Name: task_init_info
  *
  * Description:
- *   Allocate and initilize tls_info_s structure.
+ *   Allocate and initilize task_info_s structure.
  *
  * Input Parameters:
- *   - tcb: The TCB of new task
+ *   - group: The group of new task
  *
  * Returned Value:
  *   Zero (OK) on success; a negated errno value on failure.
  *
  ****************************************************************************/
 
-int tls_init_info(FAR struct tcb_s *tcb);
+int task_init_info(FAR struct task_group_s *group)
+{
+  FAR struct task_info_s *info;
 
-/****************************************************************************
- * Name: tls_dup_info
- *
- * Description:
- *   Allocate and duplicate tls_info_s structure.
- *
- * Input Parameters:
- *   - dst: The TCB of new task
- *   - src: The TCB of source task
- *
- * Returned Value:
- *   Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
+  /* Allocate task info for group */
+
+  info = group_zalloc(group, sizeof(struct task_info_s));
+  if (info == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  /* Initialize user space semaphore */
 
-int tls_dup_info(FAR struct tcb_s *dst, FAR struct tcb_s *src);
+  nxsem_init(&info->ta_sem, 0, 1);
+  group->tg_info = info;
 
-#endif /* __SCHED_TLS_TLS_H */
+  return OK;
+}
diff --git a/sched/tls/tls.h b/sched/tls/task_uninitinfo.c
similarity index 64%
copy from sched/tls/tls.h
copy to sched/tls/task_uninitinfo.c
index af04963d11..f4dca8903e 100644
--- a/sched/tls/tls.h
+++ b/sched/tls/task_uninitinfo.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * sched/tls/tls.h
+ * 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
@@ -18,50 +18,38 @@
  *
  ****************************************************************************/
 
-#ifndef __SCHED_TLS_TLS_H
-#define __SCHED_TLS_TLS_H
-
 /****************************************************************************
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/sched.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/tls.h>
 
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
+#include "tls.h"
 
 /****************************************************************************
- * Name: tls_init_info
- *
- * Description:
- *   Allocate and initilize tls_info_s structure.
- *
- * Input Parameters:
- *   - tcb: The TCB of new task
- *
- * Returned Value:
- *   Zero (OK) on success; a negated errno value on failure.
- *
+ * Public Functions
  ****************************************************************************/
 
-int tls_init_info(FAR struct tcb_s *tcb);
-
 /****************************************************************************
- * Name: tls_dup_info
+ * Name: task_uninit_info
  *
  * Description:
- *   Allocate and duplicate tls_info_s structure.
+ *   Uninitilize and free task_info_s structure.
  *
  * Input Parameters:
- *   - dst: The TCB of new task
- *   - src: The TCB of source task
+ *   - group: The group of new task
  *
  * Returned Value:
- *   Zero (OK) on success; a negated errno value on failure.
+ *   None.
  *
  ****************************************************************************/
 
-int tls_dup_info(FAR struct tcb_s *dst, FAR struct tcb_s *src);
+void task_uninit_info(FAR struct task_group_s *group)
+{
+  FAR struct task_info_s *info = group->tg_info;
 
-#endif /* __SCHED_TLS_TLS_H */
+  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
  *

Reply via email to