зеркало из https://github.com/github/ruby.git
* thread.c (rb_mutex_sleep): ensures to re-acquire at waking up.
[ruby-Patches-19361] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
298d20c25b
Коммит
d7b8efd872
|
@ -1,3 +1,8 @@
|
|||
Tue Apr 8 21:36:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* lib/complex.rb: remove Math first before overwriting by CMath.
|
||||
|
|
22
thread.c
22
thread.c
|
@ -2423,6 +2423,21 @@ rb_mutex_unlock(VALUE self)
|
|||
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_sleep(VALUE self, VALUE timeout)
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче