mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread.c: thread_shield_get_mutex
* thread.c (thread_shield_get_mutex): explicitly check if destroyed already. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d8225d9f04
commit
35a76874db
1 changed files with 11 additions and 2 deletions
13
thread.c
13
thread.c
|
@ -4713,13 +4713,22 @@ rb_thread_shield_wait(VALUE self)
|
||||||
return rb_thread_shield_waiting(self) > 0 ? Qnil : Qfalse;
|
return rb_thread_shield_waiting(self) > 0 ? Qnil : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
thread_shield_get_mutex(VALUE self)
|
||||||
|
{
|
||||||
|
VALUE mutex = GetThreadShieldPtr(self);
|
||||||
|
if (!mutex)
|
||||||
|
rb_raise(rb_eThreadError, "destroyed thread shield - %p", (void *)mutex);
|
||||||
|
return mutex;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Release a thread shield, and return true if it has waiting threads.
|
* Release a thread shield, and return true if it has waiting threads.
|
||||||
*/
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_thread_shield_release(VALUE self)
|
rb_thread_shield_release(VALUE self)
|
||||||
{
|
{
|
||||||
VALUE mutex = GetThreadShieldPtr(self);
|
VALUE mutex = thread_shield_get_mutex(self);
|
||||||
rb_mutex_unlock(mutex);
|
rb_mutex_unlock(mutex);
|
||||||
return rb_thread_shield_waiting(self) > 0 ? Qtrue : Qfalse;
|
return rb_thread_shield_waiting(self) > 0 ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
@ -4730,7 +4739,7 @@ rb_thread_shield_release(VALUE self)
|
||||||
VALUE
|
VALUE
|
||||||
rb_thread_shield_destroy(VALUE self)
|
rb_thread_shield_destroy(VALUE self)
|
||||||
{
|
{
|
||||||
VALUE mutex = GetThreadShieldPtr(self);
|
VALUE mutex = thread_shield_get_mutex(self);
|
||||||
DATA_PTR(self) = 0;
|
DATA_PTR(self) = 0;
|
||||||
rb_mutex_unlock(mutex);
|
rb_mutex_unlock(mutex);
|
||||||
return rb_thread_shield_waiting(self) > 0 ? Qtrue : Qfalse;
|
return rb_thread_shield_waiting(self) > 0 ? Qtrue : Qfalse;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue