ruby-changes:4437
From: ko1@a...
Date: Tue, 8 Apr 2008 21:37:01 +0900 (JST)
Subject: [ruby-changes:4437] nobu - Ruby:r15928 (trunk): * thread.c (rb_mutex_sleep): ensures to re-acquire at waking up.
nobu 2008-04-08 21:36:42 +0900 (Tue, 08 Apr 2008)
New Revision: 15928
Modified files:
trunk/ChangeLog
trunk/thread.c
Log:
* thread.c (rb_mutex_sleep): ensures to re-acquire at waking up.
[ruby-Patches-19361]
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15928&r2=15927&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/thread.c?r1=15928&r2=15927&diff_format=u
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15927)
+++ ChangeLog (revision 15928)
@@ -1,3 +1,8 @@
+Tue Apr 8 21:36:40 2008 Nobuyoshi Nakada <nobu@r...>
+
+ * thread.c (rb_mutex_sleep): ensures to re-acquire at waking up.
+ [ruby-Patches-19361]
+
Tue Apr 8 11:00:14 2008 Yukihiro Matsumoto <matz@r...>
* lib/complex.rb: remove Math first before overwriting by CMath.
Index: thread.c
===================================================================
--- thread.c (revision 15927)
+++ thread.c (revision 15928)
@@ -2423,6 +2423,21 @@
return self;
}
+static VALUE
+rb_mutex_sleep_forever(VALUE time)
+{
+ rb_thread_sleep_forever();
+ return Qnil;
+}
+
+static VALUE
+rb_mutex_wait_for(VALUE time)
+{
+ const struct timeval *t = (struct timeval *)time;
+ rb_thread_wait_for(*t);
+ return Qnil;
+}
+
VALUE
rb_mutex_sleep(VALUE self, VALUE timeout)
{
@@ -2435,19 +2450,18 @@
rb_mutex_unlock(self);
beg = time(0);
if (NIL_P(timeout)) {
- rb_thread_sleep_forever();
+ rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self);
}
else {
- rb_thread_wait_for(t);
+ rb_ensure(rb_mutex_wait_for, (VALUE)&t, rb_mutex_lock, self);
}
- rb_mutex_lock(self);
end = time(0) - beg;
return INT2FIX(end);
}
/*
* call-seq:
- * mutex.sleep(timeout = nil) => self
+ * mutex.sleep(timeout = nil) => number
*
* Releases the lock and sleeps +timeout+ seconds if it is given and
* non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/