You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/05/27 06:39:15 UTC

[incubator-nuttx] branch master updated: sched: Move the call of pthread_mutex_inconsistent to nxtask_recover

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


The following commit(s) were added to refs/heads/master by this push:
     new 3b136771ff sched: Move the call of pthread_mutex_inconsistent to nxtask_recover
3b136771ff is described below

commit 3b136771ff5b8f69d8796a77c70389bf6af0fb67
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed May 25 13:17:34 2022 +0800

    sched: Move the call of pthread_mutex_inconsistent to nxtask_recover
    
    to avoid it spread around all possible exit path
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 sched/pthread/pthread_cancel.c | 6 ------
 sched/pthread/pthread_exit.c   | 6 ------
 sched/task/exit.c              | 7 -------
 sched/task/task_recover.c      | 7 +++++++
 4 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c
index 9965706517..e80fe647b4 100644
--- a/sched/pthread/pthread_cancel.c
+++ b/sched/pthread/pthread_cancel.c
@@ -99,12 +99,6 @@ int pthread_cancel(pthread_t thread)
 
   pthread_completejoin((pid_t)thread, PTHREAD_CANCELED);
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent(tcb);
-#endif
-
   /* Then let nxtask_terminate do the real work */
 
   return nxtask_terminate((pid_t)thread, false);
diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c
index 7fe27a6121..e63dbc7ff2 100644
--- a/sched/pthread/pthread_exit.c
+++ b/sched/pthread/pthread_exit.c
@@ -90,12 +90,6 @@ void nx_pthread_exit(FAR void *exit_value)
       exit(EXIT_FAILURE);
     }
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent(tcb);
-#endif
-
   /* Perform common task termination logic.  This will get called again later
    * through logic kicked off by _exit().  However, we need to call it before
    * calling _exit() in order certain operations if this is the last thread
diff --git a/sched/task/exit.c b/sched/task/exit.c
index 0834d87e95..7bd7cbc5b3 100644
--- a/sched/task/exit.c
+++ b/sched/task/exit.c
@@ -34,7 +34,6 @@
 #include "task/task.h"
 #include "group/group.h"
 #include "sched/sched.h"
-#include "pthread/pthread.h"
 
 /****************************************************************************
  * Public Functions
@@ -68,12 +67,6 @@ void _exit(int status)
   group_kill_children(tcb);
 #endif
 
-#if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent(tcb);
-#endif
-
   /* Perform common task termination logic.  This will get called again later
    * through logic kicked off by up_exit().  However, we need to call it here
    * so that we can flush buffered I/O (both of which may required
diff --git a/sched/task/task_recover.c b/sched/task/task_recover.c
index ebbcf3f6ea..6e6dcd4889 100644
--- a/sched/task/task_recover.c
+++ b/sched/task/task_recover.c
@@ -33,6 +33,7 @@
 #include "semaphore/semaphore.h"
 #include "wdog/wdog.h"
 #include "mqueue/mqueue.h"
+#include "pthread/pthread.h"
 #include "sched/sched.h"
 #include "task/task.h"
 
@@ -61,6 +62,12 @@
 
 void nxtask_recover(FAR struct tcb_s *tcb)
 {
+#if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
+  /* Recover any mutexes still held by the canceled thread */
+
+  pthread_mutex_inconsistent(tcb);
+#endif
+
   /* The task is being deleted.  Cancel in pending timeout events. */
 
   wd_recover(tcb);