mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread*.c: replace GetMutexPtr with mutex_ptr
Following ko1's lead in r59192, this gets rid of non-obvious assignments which happen inside macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
383d7dba12
commit
79bdb6f9c8
2 changed files with 25 additions and 28 deletions
8
thread.c
8
thread.c
|
@ -4710,7 +4710,7 @@ rb_thread_shield_wait(VALUE self)
|
||||||
rb_mutex_t *m;
|
rb_mutex_t *m;
|
||||||
|
|
||||||
if (!mutex) return Qfalse;
|
if (!mutex) return Qfalse;
|
||||||
GetMutexPtr(mutex, m);
|
m = mutex_ptr(mutex);
|
||||||
if (m->th == GET_THREAD()) return Qnil;
|
if (m->th == GET_THREAD()) return Qnil;
|
||||||
rb_thread_shield_waiting_inc(self);
|
rb_thread_shield_waiting_inc(self);
|
||||||
rb_mutex_lock(mutex);
|
rb_mutex_lock(mutex);
|
||||||
|
@ -5197,8 +5197,7 @@ debug_deadlock_check(rb_vm_t *vm, VALUE msg)
|
||||||
"native:%"PRI_THREAD_ID" int:%u",
|
"native:%"PRI_THREAD_ID" int:%u",
|
||||||
th->self, (void *)th, thread_id_str(th), th->ec->interrupt_flag);
|
th->self, (void *)th, thread_id_str(th), th->ec->interrupt_flag);
|
||||||
if (th->locking_mutex) {
|
if (th->locking_mutex) {
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
|
||||||
GetMutexPtr(th->locking_mutex, mutex);
|
|
||||||
rb_str_catf(msg, " mutex:%p cond:%"PRIuSIZE,
|
rb_str_catf(msg, " mutex:%p cond:%"PRIuSIZE,
|
||||||
(void *)mutex->th, rb_mutex_num_waiting(mutex));
|
(void *)mutex->th, rb_mutex_num_waiting(mutex));
|
||||||
}
|
}
|
||||||
|
@ -5230,8 +5229,7 @@ rb_check_deadlock(rb_vm_t *vm)
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
else if (th->locking_mutex) {
|
else if (th->locking_mutex) {
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
|
||||||
GetMutexPtr(th->locking_mutex, mutex);
|
|
||||||
|
|
||||||
if (mutex->th == th || (!mutex->th && !list_empty(&mutex->waitq))) {
|
if (mutex->th == th || (!mutex->th && !list_empty(&mutex->waitq))) {
|
||||||
found = 1;
|
found = 1;
|
||||||
|
|
|
@ -81,9 +81,6 @@ static const char* rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t *th);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define GetMutexPtr(obj, tobj) \
|
|
||||||
TypedData_Get_Struct((obj), rb_mutex_t, &mutex_data_type, (tobj))
|
|
||||||
|
|
||||||
#define mutex_mark NULL
|
#define mutex_mark NULL
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
|
@ -123,6 +120,15 @@ static const rb_data_type_t mutex_data_type = {
|
||||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static rb_mutex_t *
|
||||||
|
mutex_ptr(VALUE obj)
|
||||||
|
{
|
||||||
|
rb_mutex_t *mutex;
|
||||||
|
|
||||||
|
TypedData_Get_Struct(obj, rb_mutex_t, &mutex_data_type, mutex);
|
||||||
|
return mutex;
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_obj_is_mutex(VALUE obj)
|
rb_obj_is_mutex(VALUE obj)
|
||||||
{
|
{
|
||||||
|
@ -172,16 +178,15 @@ rb_mutex_new(void)
|
||||||
VALUE
|
VALUE
|
||||||
rb_mutex_locked_p(VALUE self)
|
rb_mutex_locked_p(VALUE self)
|
||||||
{
|
{
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
GetMutexPtr(self, mutex);
|
|
||||||
return mutex->th ? Qtrue : Qfalse;
|
return mutex->th ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mutex_locked(rb_thread_t *th, VALUE self)
|
mutex_locked(rb_thread_t *th, VALUE self)
|
||||||
{
|
{
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
GetMutexPtr(self, mutex);
|
|
||||||
|
|
||||||
if (th->keeping_mutexes) {
|
if (th->keeping_mutexes) {
|
||||||
mutex->next_mutex = th->keeping_mutexes;
|
mutex->next_mutex = th->keeping_mutexes;
|
||||||
|
@ -199,9 +204,8 @@ mutex_locked(rb_thread_t *th, VALUE self)
|
||||||
VALUE
|
VALUE
|
||||||
rb_mutex_trylock(VALUE self)
|
rb_mutex_trylock(VALUE self)
|
||||||
{
|
{
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
VALUE locked = Qfalse;
|
VALUE locked = Qfalse;
|
||||||
GetMutexPtr(self, mutex);
|
|
||||||
|
|
||||||
if (mutex->th == 0) {
|
if (mutex->th == 0) {
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
|
@ -225,8 +229,7 @@ static VALUE
|
||||||
do_mutex_lock(VALUE self, int interruptible_p)
|
do_mutex_lock(VALUE self, int interruptible_p)
|
||||||
{
|
{
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
GetMutexPtr(self, mutex);
|
|
||||||
|
|
||||||
/* When running trap handler */
|
/* When running trap handler */
|
||||||
if (!FL_TEST_RAW(self, MUTEX_ALLOW_TRAP) &&
|
if (!FL_TEST_RAW(self, MUTEX_ALLOW_TRAP) &&
|
||||||
|
@ -325,9 +328,7 @@ rb_mutex_owned_p(VALUE self)
|
||||||
{
|
{
|
||||||
VALUE owned = Qfalse;
|
VALUE owned = Qfalse;
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
|
|
||||||
GetMutexPtr(self, mutex);
|
|
||||||
|
|
||||||
if (mutex->th == th)
|
if (mutex->th == th)
|
||||||
owned = Qtrue;
|
owned = Qtrue;
|
||||||
|
@ -388,8 +389,7 @@ VALUE
|
||||||
rb_mutex_unlock(VALUE self)
|
rb_mutex_unlock(VALUE self)
|
||||||
{
|
{
|
||||||
const char *err;
|
const char *err;
|
||||||
rb_mutex_t *mutex;
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
GetMutexPtr(self, mutex);
|
|
||||||
|
|
||||||
err = rb_mutex_unlock_th(mutex, GET_THREAD());
|
err = rb_mutex_unlock_th(mutex, GET_THREAD());
|
||||||
if (err) rb_raise(rb_eThreadError, "%s", err);
|
if (err) rb_raise(rb_eThreadError, "%s", err);
|
||||||
|
@ -410,14 +410,13 @@ rb_mutex_abandon_keeping_mutexes(rb_thread_t *th)
|
||||||
static void
|
static void
|
||||||
rb_mutex_abandon_locking_mutex(rb_thread_t *th)
|
rb_mutex_abandon_locking_mutex(rb_thread_t *th)
|
||||||
{
|
{
|
||||||
rb_mutex_t *mutex;
|
if (th->locking_mutex) {
|
||||||
|
rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
|
||||||
|
|
||||||
if (!th->locking_mutex) return;
|
if (mutex->th == th)
|
||||||
|
rb_mutex_abandon_all(mutex);
|
||||||
GetMutexPtr(th->locking_mutex, mutex);
|
th->locking_mutex = Qfalse;
|
||||||
if (mutex->th == th)
|
}
|
||||||
rb_mutex_abandon_all(mutex);
|
|
||||||
th->locking_mutex = Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Reference in a new issue