[前][次][番号順一覧][スレッド一覧]

ruby-changes:34770

From: nobu <ko1@a...>
Date: Thu, 17 Jul 2014 19:57:42 +0900 (JST)
Subject: [ruby-changes:34770] nobu:r46853 (trunk): thread/thread.c: simplify

nobu	2014-07-17 19:57:31 +0900 (Thu, 17 Jul 2014)

  New Revision: 46853

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46853

  Log:
    thread/thread.c: simplify
    
    * ext/thread/thread.c (queue_pop_should_block): returns int
      instead of VALUE, and use rb_check_arity.
    
    * ext/thread/thread.c (szqueue_push_should_block): ditto.

  Modified files:
    trunk/ext/thread/thread.c
Index: ext/thread/thread.c
===================================================================
--- ext/thread/thread.c	(revision 46852)
+++ ext/thread/thread.c	(revision 46853)
@@ -262,14 +262,14 @@ queue_sleep(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L262
 }
 
 static VALUE
-queue_do_pop(VALUE self, VALUE should_block)
+queue_do_pop(VALUE self, int should_block)
 {
     struct waiting_delete args;
     args.waiting = GET_QUEUE_WAITERS(self);
     args.th	 = rb_thread_current();
 
     while (queue_length(self) == 0) {
-	if (!(int)should_block) {
+	if (!should_block) {
 	    rb_raise(rb_eThreadError, "queue empty");
 	}
 	rb_ary_push(args.waiting, args.th);
@@ -279,18 +279,13 @@ queue_do_pop(VALUE self, VALUE should_bl https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L279
     return rb_ary_shift(GET_QUEUE_QUE(self));
 }
 
-static VALUE
-queue_pop_should_block(int argc, VALUE *argv)
+static int
+queue_pop_should_block(int argc, const VALUE *argv)
 {
-    VALUE should_block = Qtrue;
-    switch (argc) {
-      case 0:
-	break;
-      case 1:
-	should_block = RTEST(argv[0]) ? Qfalse : Qtrue;
-	break;
-      default:
-	rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
+    int should_block = 1;
+    rb_check_arity(argc, 0, 1);
+    if (argc > 0) {
+	should_block = !RTEST(argv[0]);
     }
     return should_block;
 }
@@ -312,7 +307,7 @@ queue_pop_should_block(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L307
 static VALUE
 rb_queue_pop(int argc, VALUE *argv, VALUE self)
 {
-    VALUE should_block = queue_pop_should_block(argc, argv);
+    int should_block = queue_pop_should_block(argc, argv);
     return queue_do_pop(self, should_block);
 }
 
@@ -443,21 +438,13 @@ rb_szqueue_max_set(VALUE self, VALUE vma https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L438
     return vmax;
 }
 
-static VALUE
-szqueue_push_should_block(int argc, VALUE *argv)
+static int
+szqueue_push_should_block(int argc, const VALUE *argv)
 {
-    VALUE should_block = Qtrue;
-    switch (argc) {
-      case 0:
-	rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
-	break;
-      case 1:
-	break;
-      case 2:
-	should_block = RTEST(argv[1]) ? Qfalse : Qtrue;
-	break;
-      default:
-	rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
+    int should_block = 1;
+    rb_check_arity(argc, 1, 2);
+    if (argc > 1) {
+	should_block = !RTEST(argv[1]);
     }
     return should_block;
 }
@@ -480,12 +467,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L467
 rb_szqueue_push(int argc, VALUE *argv, VALUE self)
 {
     struct waiting_delete args;
-    VALUE should_block = szqueue_push_should_block(argc, argv);
+    int should_block = szqueue_push_should_block(argc, argv);
     args.waiting = GET_SZQUEUE_WAITERS(self);
     args.th      = rb_thread_current();
 
     while (queue_length(self) >= GET_SZQUEUE_ULONGMAX(self)) {
-	if (!(int)should_block) {
+	if (!should_block) {
 	    rb_raise(rb_eThreadError, "queue full");
 	}
 	rb_ary_push(args.waiting, args.th);
@@ -495,7 +482,7 @@ rb_szqueue_push(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L482
 }
 
 static VALUE
-szqueue_do_pop(VALUE self, VALUE should_block)
+szqueue_do_pop(VALUE self, int should_block)
 {
     VALUE retval = queue_do_pop(self, should_block);
 
@@ -523,7 +510,7 @@ szqueue_do_pop(VALUE self, VALUE should_ https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L510
 static VALUE
 rb_szqueue_pop(int argc, VALUE *argv, VALUE self)
 {
-    VALUE should_block = queue_pop_should_block(argc, argv);
+    int should_block = queue_pop_should_block(argc, argv);
     return szqueue_do_pop(self, should_block);
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]