xiaoxiang781216 commented on a change in pull request #2518:
URL: https://github.com/apache/incubator-nuttx/pull/2518#discussion_r587980736



##########
File path: sched/task/task_gettid.c
##########
@@ -45,5 +50,42 @@
 
 pid_t gettid(void)
 {
-  return getpid();
+  FAR struct tcb_s *rtcb;
+
+  /* Get the TCB at the head of the ready-to-run task list.  That
+   * will usually be the currently executing task.  There are two
+   * exceptions to this:
+   *
+   * 1. Early in the start-up sequence, the ready-to-run list may be
+   *    empty!  In this case, of course, the CPU0 start-up/IDLE thread with
+   *    pid == 0 must be running, and
+   * 2. As described above, during certain context-switching conditions the
+   *    task at the head of the ready-to-run list may not actually be
+   *    running.
+   */
+
+  rtcb = this_task();
+  if (rtcb != NULL)
+    {
+      /* Check if the task is actually running */
+
+      if (rtcb->task_state == TSTATE_TASK_RUNNING)
+        {
+          /* Yes.. Return the task ID from the TCB at the head of the
+           * ready-to-run task list
+           */
+
+          return rtcb->pid;

Review comment:
       Ok, I will create a new PR to rename this field.




----------------------------------------------------------------
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.

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


Reply via email to