dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] thread_sync.c (rb_mutex_sleep): disable interrupt checking in ensure
Date: Sun, 19 Aug 2018 19:39:54 +0000	[thread overview]
Message-ID: <20180819193954.13807-1-e@80x24.org> (raw)

---
 thread_sync.c | 47 +++++++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/thread_sync.c b/thread_sync.c
index 19f14fa958..79eb1768c4 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -221,15 +221,8 @@ rb_mutex_trylock(VALUE self)
  */
 static const rb_thread_t *patrol_thread = NULL;
 
-/*
- * call-seq:
- *    mutex.lock  -> self
- *
- * Attempts to grab the lock and waits if it isn't available.
- * Raises +ThreadError+ if +mutex+ was locked by the current thread.
- */
-VALUE
-rb_mutex_lock(VALUE self)
+static VALUE
+do_mutex_lock(VALUE self, int interruptible_p)
 {
     rb_thread_t *th = GET_THREAD();
     rb_mutex_t *mutex;
@@ -290,16 +283,37 @@ rb_mutex_lock(VALUE self)
 	    th->vm->sleeper--;
 	    if (mutex->th == th) mutex_locked(th, self);
 
-	    RUBY_VM_CHECK_INTS_BLOCKING(th->ec); /* may release mutex */
-	    if (!mutex->th) {
-		mutex->th = th;
-	        mutex_locked(th, self);
-	    }
+            if (interruptible_p) {
+                RUBY_VM_CHECK_INTS_BLOCKING(th->ec); /* may release mutex */
+                if (!mutex->th) {
+                    mutex->th = th;
+                    mutex_locked(th, self);
+                }
+            }
 	}
     }
     return self;
 }
 
+static VALUE
+mutex_lock_uninterruptible(VALUE self)
+{
+    return do_mutex_lock(self, 0);
+}
+
+/*
+ * call-seq:
+ *    mutex.lock  -> self
+ *
+ * Attempts to grab the lock and waits if it isn't available.
+ * Raises +ThreadError+ if +mutex+ was locked by the current thread.
+ */
+VALUE
+rb_mutex_lock(VALUE self)
+{
+    return do_mutex_lock(self, 1);
+}
+
 /*
  * call-seq:
  *    mutex.owned?  -> true or false
@@ -462,14 +476,15 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
     rb_mutex_unlock(self);
     beg = time(0);
     if (NIL_P(timeout)) {
-	rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self);
+	rb_ensure(rb_mutex_sleep_forever, Qnil, mutex_lock_uninterruptible, self);
     }
     else {
         struct timespec ts;
         VALUE tsp = (VALUE)timespec_for(&ts, &t);
 
-        rb_ensure(rb_mutex_wait_for, tsp, rb_mutex_lock, self);
+        rb_ensure(rb_mutex_wait_for, tsp, mutex_lock_uninterruptible, self);
     }
+    RUBY_VM_CHECK_INTS_BLOCKING(GET_EC());
     end = time(0) - beg;
     return INT2FIX(end);
 }
-- 
EW


                 reply	other threads:[~2018-08-19 19:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180819193954.13807-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).