]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
_thread_suspend: hold on to the lock when suspending some other
authorJulian Seward <jseward@acm.org>
Fri, 17 Oct 2014 16:03:20 +0000 (16:03 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 17 Oct 2014 16:03:20 +0000 (16:03 +0000)
thread, so as to not deadlock the process.

_thread_resume: add wrapper

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14636

coregrind/m_syswrap/priv_syswrap-darwin.h
coregrind/m_syswrap/syswrap-darwin.c

index 780966545da3cccfcd40f89695bd6a45afcceedb..1f0b49f71a39a45c57846053f907d7fef910a7d2 100644 (file)
@@ -565,6 +565,7 @@ DECL_TEMPLATE(darwin, thread_terminate);
 DECL_TEMPLATE(darwin, thread_create);
 DECL_TEMPLATE(darwin, thread_create_running);
 DECL_TEMPLATE(darwin, thread_suspend);
+DECL_TEMPLATE(darwin, thread_resume);
 DECL_TEMPLATE(darwin, thread_get_state);
 DECL_TEMPLATE(darwin, thread_policy);
 DECL_TEMPLATE(darwin, thread_policy_set);
index e04e39acf0e22ecaf2ba9e6ce2fee7cb3a1d5f55..6c6cc43d45e6f92e340bd3d08bd0587a96ffa5c8 100644 (file)
@@ -6882,6 +6882,33 @@ PRE(thread_suspend)
        // Do keep the scheduler lock while suspending any other thread. 
        // Otherwise we might halt the other thread while it holds the lock, 
        // which would deadlock the process.
+       *flags &= ~SfMayBlock;
+   }
+}
+
+
+POST(thread_resume)
+{
+}
+
+PRE(thread_resume)
+{
+   mach_msg_header_t *mh = (mach_msg_header_t *)ARG1;
+   Bool self_resume = (mh->msgh_request_port == MACH_THREAD);
+
+   PRINT("thread_resume(%s)", name_for_port(mh->msgh_request_port));
+
+   AFTER = POST_FN(thread_resume);
+
+   if (self_resume) {
+       // This doesn't make much sense.  If we are resuming ourself, we can't
+       // already be running.  So I don't see how we can ever get here.
+       vg_assert(0);
+   } else {
+       // Resuming some other thread.  It might not yet come back to life
+       // (if the suspend count is still above zero) so make sure we keep
+       // holding the lock.
+       *flags &= ~SfMayBlock;
    }
 }
 
@@ -7375,6 +7402,9 @@ PRE(mach_msg_thread)
    case 3605: 
       CALL_PRE(thread_suspend);
       return;
+   case 3606:
+      CALL_PRE(thread_resume);
+      return;
    case 3612: 
       CALL_PRE(thread_info);
       return;