dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 1/2] avoid redundant GET_THREAD() calls
Date: Thu, 16 Jul 2015 20:23:06 +0000	[thread overview]
Message-ID: <1437078187-20241-1-git-send-email-e@80x24.org> (raw)

This reduces binary size slightly but can do even more we enable
OPT_CALL_CFUNC_WITHOUT_FRAME
---
 iseq.c    |  2 +-
 process.c |  3 ++-
 thread.c  | 12 +++++++-----
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/iseq.c b/iseq.c
index a42eae8..b9eb034 100644
--- a/iseq.c
+++ b/iseq.c
@@ -568,7 +568,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE li
 	    node = rb_parser_compile_string_path(parser, file, src, ln);
 
 	    if (!node) {
-		rb_exc_raise(GET_THREAD()->errinfo);	/* TODO: check err */
+		rb_exc_raise(th->errinfo);	/* TODO: check err */
 	    }
 	}
 
diff --git a/process.c b/process.c
index ac72463..8b583f4 100644
--- a/process.c
+++ b/process.c
@@ -876,7 +876,8 @@ rb_waitpid(rb_pid_t pid, int *st, int flags)
 							 RUBY_UBF_PROCESS, 0);
     if (result < 0) {
 	if (errno == EINTR) {
-            RUBY_VM_CHECK_INTS(GET_THREAD());
+            rb_thread_t *th = GET_THREAD();
+            RUBY_VM_CHECK_INTS(th);
             goto retry;
         }
 	return (rb_pid_t)-1;
diff --git a/thread.c b/thread.c
index 95b022f..1e16eb1 100644
--- a/thread.c
+++ b/thread.c
@@ -670,7 +670,7 @@ thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS))
     rb_thread_t *th, *current_th = GET_THREAD();
     int err;
 
-    if (OBJ_FROZEN(GET_THREAD()->thgroup)) {
+    if (OBJ_FROZEN(current_th->thgroup)) {
 	rb_raise(rb_eThreadError,
 		 "can't start a new thread (frozen ThreadGroup)");
     }
@@ -1173,7 +1173,8 @@ rb_thread_wait_for(struct timeval time)
 void
 rb_thread_check_ints(void)
 {
-    RUBY_VM_CHECK_INTS_BLOCKING(GET_THREAD());
+    rb_thread_t *th = GET_THREAD();
+    RUBY_VM_CHECK_INTS_BLOCKING(th);
 }
 
 /*
@@ -4258,10 +4259,11 @@ rb_mutex_trylock(VALUE self)
 
     native_mutex_lock(&mutex->lock);
     if (mutex->th == 0) {
-	mutex->th = GET_THREAD();
+	rb_thread_t *th = GET_THREAD();
+	mutex->th = th;
 	locked = Qtrue;
 
-	mutex_locked(GET_THREAD(), self);
+	mutex_locked(th, self);
     }
     native_mutex_unlock(&mutex->lock);
 
@@ -4345,7 +4347,7 @@ rb_mutex_lock(VALUE self)
     }
 
     if (rb_mutex_trylock(self) == Qfalse) {
-	if (mutex->th == GET_THREAD()) {
+	if (mutex->th == th) {
 	    rb_raise(rb_eThreadError, "deadlock; recursive locking");
 	}
 
-- 
EW


             reply	other threads:[~2015-07-16 20:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16 20:23 Eric Wong [this message]
2015-07-16 20:23 ` [PATCH 2/2] remove enumerator requires Eric Wong

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=1437078187-20241-1-git-send-email-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).