[前][次][番号順一覧][スレッド一覧]

ruby-changes:52282

From: normal <ko1@a...>
Date: Tue, 21 Aug 2018 10:01:47 +0900 (JST)
Subject: [ruby-changes:52282] normal:r64490 (trunk): thread*.c: replace GetMutexPtr with mutex_ptr

normal	2018-08-21 10:01:42 +0900 (Tue, 21 Aug 2018)

  New Revision: 64490

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64490

  Log:
    thread*.c: replace GetMutexPtr with mutex_ptr
    
    Following ko1's lead in r59192, this gets rid of non-obvious
    assignments which happen inside macros.

  Modified files:
    trunk/thread.c
    trunk/thread_sync.c
Index: thread_sync.c
===================================================================
--- thread_sync.c	(revision 64489)
+++ thread_sync.c	(revision 64490)
@@ -81,9 +81,6 @@ static const char* rb_mutex_unlock_th(rb https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L81
  *
  */
 
-#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_t https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L120
     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) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L178
 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 https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L204
 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 https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L229
 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) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L328
 {
     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 https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L389
 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_thre https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L410
 static void
 rb_mutex_abandon_locking_mutex(rb_thread_t *th)
 {
-    rb_mutex_t *mutex;
-
-    if (!th->locking_mutex) return;
+    if (th->locking_mutex) {
+        rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
 
-    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
Index: thread.c
===================================================================
--- thread.c	(revision 64489)
+++ thread.c	(revision 64490)
@@ -4710,7 +4710,7 @@ rb_thread_shield_wait(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L4710
     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 https://github.com/ruby/ruby/blob/trunk/thread.c#L5197
 		    "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) https://github.com/ruby/ruby/blob/trunk/thread.c#L5229
 	    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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]