mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/thread/thread.c (rb_thread_exclusive): Implement
Thread.exclusive. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f9c378051a
commit
2a7ec27be2
2 changed files with 39 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Feb 11 05:32:54 2007 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* ext/thread/thread.c (rb_thread_exclusive): Implement
|
||||
Thread.exclusive.
|
||||
|
||||
Sun Feb 11 05:26:51 2007 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* ext/thread/thread.c: Get rid of use of a dummy function.
|
||||
|
|
|
@ -18,6 +18,38 @@ static VALUE rb_cConditionVariable;
|
|||
static VALUE rb_cQueue;
|
||||
static VALUE rb_cSizedQueue;
|
||||
|
||||
static VALUE
|
||||
thread_exclusive_do()
|
||||
{
|
||||
rb_thread_critical = Qtrue;
|
||||
|
||||
return rb_yield(Qundef);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
thread_exclusive_ensure(val)
|
||||
VALUE val;
|
||||
{
|
||||
rb_thread_critical = val;
|
||||
|
||||
return Qundef;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* Thread.exclusive { block } => obj
|
||||
*
|
||||
* Wraps a block in Thread.critical, restoring the original value
|
||||
* upon exit from the critical section, and returns the value of the
|
||||
* block.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
rb_thread_exclusive()
|
||||
{
|
||||
return rb_ensure(thread_exclusive_do, Qundef, thread_exclusive_ensure, rb_thread_critical);
|
||||
}
|
||||
|
||||
typedef struct _Entry {
|
||||
VALUE value;
|
||||
struct _Entry *next;
|
||||
|
@ -1067,6 +1099,8 @@ dummy_dump(VALUE self)
|
|||
void
|
||||
Init_thread(void)
|
||||
{
|
||||
rb_define_singleton_method(rb_cThread, "exclusive", rb_thread_exclusive, 0);
|
||||
|
||||
rb_cMutex = rb_define_class("Mutex", rb_cObject);
|
||||
rb_define_alloc_func(rb_cMutex, rb_mutex_alloc);
|
||||
rb_define_method(rb_cMutex, "marshal_load", dummy_load, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue