mutex-synchronize-use-c-implementation.patch

Motohiro KOSAKI, 01/12/2011 04:45 PM

Download (1.28 KB)

View differences:

prelude.rb
1
class Mutex
2
  # call-seq:
3
  #    mutex.synchronize { ... }
4
  #
5
  # Obtains a lock, runs the block, and releases the lock when the
6
  # block completes.  See the example under Mutex.
7
  def synchronize
8
    self.lock
9
    begin
10
      yield
11
    ensure
12
      self.unlock rescue nil
13
    end
14
  end
15
end
16

  
17 1
class Thread
18 2
  MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
19 3

  
thread.c
3435 3435
    return rb_ensure(func, arg, rb_mutex_unlock, mutex);
3436 3436
}
3437 3437

  
3438
static VALUE
3439
rb_synchronize(VALUE self)
3440
{
3441
    return rb_mutex_synchronize(self, rb_yield, Qnil);
3442
}
3443

  
3438 3444
/*
3439 3445
 * Document-class: Barrier
3440 3446
 */
......
4381 4387
    rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
4382 4388
    rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
4383 4389
    rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
4390
    rb_define_method(rb_cMutex, "synchronize", rb_synchronize, 0);
4384 4391

  
4385 4392
    recursive_key = rb_intern("__recursive_key__");
4386 4393
    rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);