You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/03/04 19:54:09 UTC

[GitHub] [incubator-nuttx] patacongo commented on a change in pull request #2518: sched: Implement getpid and gettid correctly

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



##########
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:
       We will need to rename the pid field in tcb.s to tid.  This will effect a lot of files, but is not a risky change otherwise.




----------------------------------------------------------------
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:
users@infra.apache.org