Skip to content
Browse files

wrap_mutex_lock

  • Loading branch information...
1 parent 91ec46d commit f81089c4c5f977f940ed6fa5e33e053a4fee4dfe @funny-falcon committed Nov 4, 2012
Showing with 12 additions and 2 deletions.
  1. +12 −2 thread.c
View
14 thread.c
@@ -4070,6 +4070,16 @@ rb_mutex_wait_for(VALUE time)
return Qnil;
}
+static VALUE
+wrap_mutex_lock(VALUE self)
+{
+ if (rb_block_given_p()) {
+ rb_ensure(rb_yield, Qnil, rb_mutex_lock, self);
+ return self;
+ }
+ return rb_mutex_lock(self);
+}
+
VALUE
rb_mutex_sleep(VALUE self, VALUE timeout)
{
@@ -4082,10 +4092,10 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
rb_mutex_unlock(self);
beg = time(0);
if (NIL_P(timeout)) {
- rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self);
+ rb_ensure(rb_mutex_sleep_forever, Qnil, wrap_mutex_lock, self);
}
else {
- rb_ensure(rb_mutex_wait_for, (VALUE)&t, rb_mutex_lock, self);
+ rb_ensure(rb_mutex_wait_for, (VALUE)&t, wrap_mutex_lock, self);
}
end = time(0) - beg;
return INT2FIX(end);

0 comments on commit f81089c

Please sign in to comment.
Something went wrong with that request. Please try again.