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;
 | 
			
		||||
 | 
			
		||||
    if (!mutex) return Qfalse;
 | 
			
		||||
    GetMutexPtr(mutex, m);
 | 
			
		||||
    m = mutex_ptr(mutex);
 | 
			
		||||
    if (m->th == GET_THREAD()) return Qnil;
 | 
			
		||||
    rb_thread_shield_waiting_inc(self);
 | 
			
		||||
    rb_mutex_lock(mutex);
 | 
			
		||||
| 
						 | 
				
			
			@ -5197,8 +5197,7 @@ debug_deadlock_check(rb_vm_t *vm, VALUE msg)
 | 
			
		|||
		    "native:%"PRI_THREAD_ID" int:%u",
 | 
			
		||||
		    th->self, (void *)th, thread_id_str(th), th->ec->interrupt_flag);
 | 
			
		||||
	if (th->locking_mutex) {
 | 
			
		||||
	    rb_mutex_t *mutex;
 | 
			
		||||
	    GetMutexPtr(th->locking_mutex, mutex);
 | 
			
		||||
	    rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
 | 
			
		||||
	    rb_str_catf(msg, " mutex:%p cond:%"PRIuSIZE,
 | 
			
		||||
			(void *)mutex->th, rb_mutex_num_waiting(mutex));
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -5230,8 +5229,7 @@ rb_check_deadlock(rb_vm_t *vm)
 | 
			
		|||
	    found = 1;
 | 
			
		||||
	}
 | 
			
		||||
	else if (th->locking_mutex) {
 | 
			
		||||
	    rb_mutex_t *mutex;
 | 
			
		||||
	    GetMutexPtr(th->locking_mutex, mutex);
 | 
			
		||||
	    rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
 | 
			
		||||
 | 
			
		||||
	    if (mutex->th == th || (!mutex->th && !list_empty(&mutex->waitq))) {
 | 
			
		||||
		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
 | 
			
		||||
 | 
			
		||||
static size_t
 | 
			
		||||
| 
						 | 
				
			
			@ -123,6 +120,15 @@ static const rb_data_type_t mutex_data_type = {
 | 
			
		|||
    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
 | 
			
		||||
rb_obj_is_mutex(VALUE obj)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -172,16 +178,15 @@ rb_mutex_new(void)
 | 
			
		|||
VALUE
 | 
			
		||||
rb_mutex_locked_p(VALUE self)
 | 
			
		||||
{
 | 
			
		||||
    rb_mutex_t *mutex;
 | 
			
		||||
    GetMutexPtr(self, mutex);
 | 
			
		||||
    rb_mutex_t *mutex = mutex_ptr(self);
 | 
			
		||||
 | 
			
		||||
    return mutex->th ? Qtrue : Qfalse;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
mutex_locked(rb_thread_t *th, VALUE self)
 | 
			
		||||
{
 | 
			
		||||
    rb_mutex_t *mutex;
 | 
			
		||||
    GetMutexPtr(self, mutex);
 | 
			
		||||
    rb_mutex_t *mutex = mutex_ptr(self);
 | 
			
		||||
 | 
			
		||||
    if (th->keeping_mutexes) {
 | 
			
		||||
	mutex->next_mutex = th->keeping_mutexes;
 | 
			
		||||
| 
						 | 
				
			
			@ -199,9 +204,8 @@ mutex_locked(rb_thread_t *th, VALUE self)
 | 
			
		|||
VALUE
 | 
			
		||||
rb_mutex_trylock(VALUE self)
 | 
			
		||||
{
 | 
			
		||||
    rb_mutex_t *mutex;
 | 
			
		||||
    rb_mutex_t *mutex = mutex_ptr(self);
 | 
			
		||||
    VALUE locked = Qfalse;
 | 
			
		||||
    GetMutexPtr(self, mutex);
 | 
			
		||||
 | 
			
		||||
    if (mutex->th == 0) {
 | 
			
		||||
	rb_thread_t *th = GET_THREAD();
 | 
			
		||||
| 
						 | 
				
			
			@ -225,8 +229,7 @@ static VALUE
 | 
			
		|||
do_mutex_lock(VALUE self, int interruptible_p)
 | 
			
		||||
{
 | 
			
		||||
    rb_thread_t *th = GET_THREAD();
 | 
			
		||||
    rb_mutex_t *mutex;
 | 
			
		||||
    GetMutexPtr(self, mutex);
 | 
			
		||||
    rb_mutex_t *mutex = mutex_ptr(self);
 | 
			
		||||
 | 
			
		||||
    /* When running trap handler */
 | 
			
		||||
    if (!FL_TEST_RAW(self, MUTEX_ALLOW_TRAP) &&
 | 
			
		||||
| 
						 | 
				
			
			@ -325,9 +328,7 @@ rb_mutex_owned_p(VALUE self)
 | 
			
		|||
{
 | 
			
		||||
    VALUE owned = Qfalse;
 | 
			
		||||
    rb_thread_t *th = GET_THREAD();
 | 
			
		||||
    rb_mutex_t *mutex;
 | 
			
		||||
 | 
			
		||||
    GetMutexPtr(self, mutex);
 | 
			
		||||
    rb_mutex_t *mutex = mutex_ptr(self);
 | 
			
		||||
 | 
			
		||||
    if (mutex->th == th)
 | 
			
		||||
	owned = Qtrue;
 | 
			
		||||
| 
						 | 
				
			
			@ -388,8 +389,7 @@ VALUE
 | 
			
		|||
rb_mutex_unlock(VALUE self)
 | 
			
		||||
{
 | 
			
		||||
    const char *err;
 | 
			
		||||
    rb_mutex_t *mutex;
 | 
			
		||||
    GetMutexPtr(self, mutex);
 | 
			
		||||
    rb_mutex_t *mutex = mutex_ptr(self);
 | 
			
		||||
 | 
			
		||||
    err = rb_mutex_unlock_th(mutex, GET_THREAD());
 | 
			
		||||
    if (err) rb_raise(rb_eThreadError, "%s", err);
 | 
			
		||||
| 
						 | 
				
			
			@ -410,14 +410,13 @@ rb_mutex_abandon_keeping_mutexes(rb_thread_t *th)
 | 
			
		|||
static void
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
    GetMutexPtr(th->locking_mutex, mutex);
 | 
			
		||||
    if (mutex->th == th)
 | 
			
		||||
	rb_mutex_abandon_all(mutex);
 | 
			
		||||
    th->locking_mutex = Qfalse;
 | 
			
		||||
        if (mutex->th == th)
 | 
			
		||||
            rb_mutex_abandon_all(mutex);
 | 
			
		||||
        th->locking_mutex = Qfalse;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue