summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-23 09:26:03 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-23 09:26:03 +0000
commit14579de431adaf0ad84c619c71c11915518207a6 (patch)
treedefab2c3b0505e21d5fb2c9c3ab87abe577aef05
parentcaaa35f068acb2de75262b328e6085561b323a47 (diff)
merge revision(s) 17874,17886:
* eval.c (rb_thread_join): new API. * ext/thread/thread.c (wait_mutex, lock_mutex): wait until the locking thread exits. [ruby-dev:34856] * eval.c (rb_thread_value): missed to change at r17874. [ruby-core:17595] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@23042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--eval.c21
-rw-r--r--ext/thread/thread.c39
-rw-r--r--version.h2
4 files changed, 54 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e9e681ce9..348a8fd6dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Mon Mar 23 18:12:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (rb_thread_value): missed to change at r17874. [ruby-core:17595]
+
+Mon Mar 23 18:12:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (rb_thread_join): new API.
+
+ * ext/thread/thread.c (wait_mutex, lock_mutex): wait until the locking
+ thread exits. [ruby-dev:34856]
+
Mon Mar 23 17:39:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (file_load_ok): checks if regular file, except for the
diff --git a/eval.c b/eval.c
index 049f78c998..4098b83382 100644
--- a/eval.c
+++ b/eval.c
@@ -1441,8 +1441,6 @@ eval_node(self, node)
int ruby_in_eval;
-static int rb_thread_join _((rb_thread_t, double));
-
static void rb_thread_cleanup _((void));
static void rb_thread_wait_other_threads _((void));
@@ -11130,8 +11128,11 @@ rb_thread_select(max, read, write, except, timeout)
return curr_thread->select_value;
}
+static int rb_thread_join0 _((rb_thread_t, double));
+int rb_thread_join _((VALUE, double));
+
static int
-rb_thread_join(th, limit)
+rb_thread_join0(th, limit)
rb_thread_t th;
double limit;
{
@@ -11173,6 +11174,15 @@ rb_thread_join(th, limit)
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:
@@ -11222,11 +11232,10 @@ rb_thread_join_m(argc, argv, thread)
{
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;
}
@@ -12269,7 +12278,7 @@ rb_thread_value(thread)
{
rb_thread_t th = rb_thread_check(thread);
- while (!rb_thread_join(th, DELAY_INFTY));
+ while (!rb_thread_join0(th, DELAY_INFTY));
return th->result;
}
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index bca807725e..ae08a61770 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -247,19 +247,22 @@ wake_all(List *list)
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;
}
@@ -395,6 +398,25 @@ rb_mutex_try_lock(VALUE self)
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
@@ -415,14 +437,7 @@ lock_mutex(Mutex *mutex)
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;
diff --git a/version.h b/version.h
index b30ddb6002..a249f8e2a2 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2009-03-23"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20090323
-#define RUBY_PATCHLEVEL 363
+#define RUBY_PATCHLEVEL 364
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8