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

ruby-changes:6358

From: nobu <ko1@a...>
Date: Fri, 4 Jul 2008 20:31:48 +0900 (JST)
Subject: [ruby-changes:6358] Ruby:r17874 (ruby_1_8): * eval.c (rb_thread_join): new API.

nobu	2008-07-04 20:31:35 +0900 (Fri, 04 Jul 2008)

  New Revision: 17874

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/eval.c
    branches/ruby_1_8/ext/thread/thread.c

  Log:
    * eval.c (rb_thread_join): new API.
    
    * ext/thread/thread.c (wait_mutex, lock_mutex): wait until the locking
      thread exits.  [ruby-dev:34856]


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

Index: ruby_1_8/ext/thread/thread.c
===================================================================
--- ruby_1_8/ext/thread/thread.c	(revision 17873)
+++ ruby_1_8/ext/thread/thread.c	(revision 17874)
@@ -242,19 +242,22 @@
     return Qnil;
 }
 
+extern int rb_thread_join _((VALUE thread, double limit));
+#define DELAY_INFTY 1E30
+
 static VALUE
-wait_list_inner(List *list)
+wait_list_inner(VALUE arg)
 {
-    push_list(list, rb_thread_current());
+    push_list((List *)arg, rb_thread_current());
     rb_thread_stop();
     return Qnil;
 }
 
 static VALUE
-wait_list_cleanup(List *list)
+wait_list_cleanup(VALUE arg)
 {
     /* cleanup in case of spurious wakeups */
-    remove_one(list, rb_thread_current());
+    remove_one((List *)arg, rb_thread_current());
     return Qnil;
 }
 
@@ -390,6 +393,25 @@
     return Qtrue;
 }
 
+static VALUE
+wait_mutex(VALUE arg)
+{
+    Mutex *mutex = (Mutex *)arg;
+    VALUE current = rb_thread_current();
+
+    push_list(&mutex->waiting, current);
+    do {
+	rb_thread_critical = 0;
+	rb_thread_join(mutex->owner, DELAY_INFTY);
+	rb_thread_critical = 1;
+	if (!MUTEX_LOCKED_P(mutex)) {
+	    mutex->owner = current;
+	    break;
+	}
+    } while (mutex->owner != current);
+    return Qnil;
+}
+
 /*
  * Document-method: lock
  * call-seq: lock
@@ -410,14 +432,7 @@
 	mutex->owner = current;
     }
     else {
-	do {
-	    wait_list(&mutex->waiting);
-	    rb_thread_critical = 1;
-	    if (!MUTEX_LOCKED_P(mutex)) {
-		mutex->owner = current;
-		break;
-	    }
-	} while (mutex->owner != current);
+	rb_ensure(wait_mutex, (VALUE)mutex, wait_list_cleanup, (VALUE)&mutex->waiting);
     }
 
     rb_thread_critical = 0;
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 17873)
+++ ruby_1_8/ChangeLog	(revision 17874)
@@ -1,3 +1,10 @@
+Fri Jul  4 20:31:33 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (rb_thread_join): new API.
+
+	* ext/thread/thread.c (wait_mutex, lock_mutex): wait until the locking
+	  thread exits.  [ruby-dev:34856]
+
 Fri Jul  4 20:20:09 2008  NAKAMURA Usaku  <usa@r...>
 
 	* numeric.c (check_uint): sorry, backport misstake.
Index: ruby_1_8/eval.c
===================================================================
--- ruby_1_8/eval.c	(revision 17873)
+++ ruby_1_8/eval.c	(revision 17874)
@@ -11360,10 +11360,10 @@
     return curr_thread->select_value;
 }
 
-static int rb_thread_join _((rb_thread_t, double));
+static int rb_thread_join0 _((rb_thread_t, double));
 
 static int
-rb_thread_join(th, limit)
+rb_thread_join0(th, limit)
     rb_thread_t th;
     double limit;
 {
@@ -11405,7 +11405,16 @@
     return Qtrue;
 }
 
+int
+rb_thread_join(thread, limit)
+    VALUE thread;
+    double limit;
+{
+    if (limit < 0) limit = DELAY_INFTY;
+    return rb_thread_join0(rb_thread_check(thread), limit);
+}
 
+
 /*
  *  call-seq:
  *     thr.join          => thr
@@ -11454,11 +11463,10 @@
 {
     VALUE limit;
     double delay = DELAY_INFTY;
-    rb_thread_t th = rb_thread_check(thread);
 
     rb_scan_args(argc, argv, "01", &limit);
     if (!NIL_P(limit)) delay = rb_num2dbl(limit);
-    if (!rb_thread_join(th, delay))
+    if (!rb_thread_join0(rb_thread_check(thread), delay))
 	return Qnil;
     return thread;
 }

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

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