xiaoxiang781216 commented on code in PR #8556:
URL: https://github.com/apache/nuttx/pull/8556#discussion_r1109554503


##########
sched/misc/assert.c:
##########
@@ -221,6 +234,9 @@ static void show_stacks(FAR struct tcb_s *rtcb)
 static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
 {
   char args[64] = "";
+  char state[32];
+  char str[64];

Review Comment:
   why use the different size for str and state?



##########
sched/sched/sched_get_stateinfo.c:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * sched/sched/sched_get_stateinfo.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 <nuttx/config.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <semaphore.h>
+#include <nuttx/mutex.h>
+#include "nuttx/sched.h"
+
+/****************************************************************************
+ * Pre-processor types
+ ****************************************************************************/
+
+/* This is the state info of the task_state field of the TCB */
+
+static FAR const char * const g_statenames[] =
+{
+  "Invalid",
+  "Waiting,Unlock",
+  "Ready",
+#ifdef CONFIG_SMP
+  "Assigned",
+#endif
+  "Running",
+  "Inactive",
+  "Waiting,Semaphore",
+  "Waiting,Signal"
+#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)
+  , "Waiting,MQ empty"
+  , "Waiting,MQ full"
+#endif
+#ifdef CONFIG_PAGING
+  , "Waiting,Paging fill"
+#endif
+#ifdef CONFIG_SIG_SIGSTOP_ACTION
+  , "Stopped"
+#endif
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_get_stateinfo
+ *
+ * Description:
+ *   Report information about a thread's state
+ *
+ * Input Parameters:
+ *   tcb    - The TCB for the task (same as the nxtask_init argument).
+ *   state  - User-provided location to return the state information.
+ *   length - The size of the state
+ *
+ ****************************************************************************/
+
+void nxsched_get_stateinfo(FAR struct tcb_s *tcb, FAR char *state,
+                           size_t length)
+{
+  /* if the state is waiting mutex */
+
+  if (tcb->task_state == TSTATE_WAIT_SEM &&
+      ((FAR sem_t *)(tcb->waitobj))->flags & SEM_TYPE_MUTEX)
+    {
+      snprintf(state, length, "Waiting,Mutexholder:%d",

Review Comment:
   ```suggestion
         snprintf(state, length, "Waiting,Mutex:%d",
   ```



##########
sched/misc/assert.c:
##########
@@ -255,13 +271,29 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void 
*arg)
 
   group_argvstr(tcb, args, sizeof(args));
 
+  /* get the task_state */
+
+  nxsched_get_stateinfo(tcb, state, sizeof(state));
+  if ((s = strchr(state, ',')) != NULL)
+    {
+      *s = '\0';
+      snprintf(str, sizeof(str), "%s  %s", state, s + 1);

Review Comment:
   why use the two spaces



##########
sched/misc/assert.c:
##########
@@ -255,13 +271,29 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void 
*arg)
 
   group_argvstr(tcb, args, sizeof(args));
 
+  /* get the task_state */
+
+  nxsched_get_stateinfo(tcb, state, sizeof(state));
+  if ((s = strchr(state, ',')) != NULL)
+    {
+      *s = '\0';
+      snprintf(str, sizeof(str), "%s  %s", state, s + 1);
+    }
+  else
+    {
+      strlcpy(str, state, sizeof(str));
+    }
+
   /* Dump interesting properties of this task */
 
-  _alert("  %4d   %4d"
+    _alert("   %4d %5d"

Review Comment:
   why add two spaces



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to