mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
298d20c25b
commit
d7b8efd872
2 changed files with 23 additions and 4 deletions
|
@ -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>
|
Tue Apr 8 11:00:14 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* lib/complex.rb: remove Math first before overwriting by CMath.
|
* 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;
|
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
|
VALUE
|
||||||
rb_mutex_sleep(VALUE self, VALUE timeout)
|
rb_mutex_sleep(VALUE self, VALUE timeout)
|
||||||
{
|
{
|
||||||
|
@ -2435,19 +2450,18 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
|
||||||
rb_mutex_unlock(self);
|
rb_mutex_unlock(self);
|
||||||
beg = time(0);
|
beg = time(0);
|
||||||
if (NIL_P(timeout)) {
|
if (NIL_P(timeout)) {
|
||||||
rb_thread_sleep_forever();
|
rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self);
|
||||||
}
|
}
|
||||||
else {
|
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;
|
end = time(0) - beg;
|
||||||
return INT2FIX(end);
|
return INT2FIX(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* mutex.sleep(timeout = nil) => self
|
* mutex.sleep(timeout = nil) => number
|
||||||
*
|
*
|
||||||
* Releases the lock and sleeps +timeout+ seconds if it is given and
|
* Releases the lock and sleeps +timeout+ seconds if it is given and
|
||||||
* non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by
|
* non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue