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

ruby-changes:9565

From: mame <ko1@a...>
Date: Sun, 28 Dec 2008 10:39:38 +0900 (JST)
Subject: [ruby-changes:9565] Ruby:r21105 (trunk): * thread.c (mutex_free): GC thread (main thread) has failed to unlock

mame	2008-12-28 10:39:18 +0900 (Sun, 28 Dec 2008)

  New Revision: 21105

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21105

  Log:
    * thread.c (mutex_free): GC thread (main thread) has failed to unlock
      a mutex that is locked by another thread, which makes the mutex
      dangling in keeping_mutexes and causes [BUG] or stuck finally.
      Now unlocking is performed as locking thread.
    * thread.c (mutex_unlock, rb_mutex_unlock, rb_mutex_unlock_all):
      mutex_unlock receives a thread.

  Modified files:
    trunk/ChangeLog
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21104)
+++ ChangeLog	(revision 21105)
@@ -1,3 +1,13 @@
+Sun Dec 28 10:28:04 2008  Yusuke Endoh  <mame@t...>
+
+	* thread.c (mutex_free): GC thread (main thread) has failed to unlock
+	  a mutex that is locked by another thread, which makes the mutex
+	  dangling in keeping_mutexes and causes [BUG] or stuck finally.
+	  Now unlocking is performed as locking thread.
+
+	* thread.c (mutex_unlock, rb_mutex_unlock, rb_mutex_unlock_all):
+	  mutex_unlock receives a thread.
+
 Sun Dec 28 05:44:44 2008  Ryan Davis  <ryan@w...>
 
 	* lib/minitest/*.rb: Imported minitest 1.3.1 r4505.
Index: thread.c
===================================================================
--- thread.c	(revision 21104)
+++ thread.c	(revision 21105)
@@ -2708,7 +2708,7 @@
 #define GetMutexPtr(obj, tobj) \
   Data_Get_Struct(obj, mutex_t, tobj)
 
-static const char *mutex_unlock(mutex_t *mutex);
+static const char *mutex_unlock(mutex_t *mutex, rb_thread_t *th);
 
 static void
 mutex_free(void *ptr)
@@ -2717,7 +2717,8 @@
 	mutex_t *mutex = ptr;
 	if (mutex->th) {
 	    /* rb_warn("free locked mutex"); */
-	    mutex_unlock(mutex);
+	    char *err = mutex_unlock(mutex, mutex->th);
+	    if (err) rb_bug("%s", err);
 	}
 	native_mutex_destroy(&mutex->lock);
 	native_cond_destroy(&mutex->cond);
@@ -2917,10 +2918,9 @@
 }
 
 static const char *
-mutex_unlock(mutex_t *mutex)
+mutex_unlock(mutex_t *mutex, rb_thread_t *th)
 {
     const char *err = NULL;
-    rb_thread_t *th = GET_THREAD();
     mutex_t *th_mutex;
 
     native_mutex_lock(&mutex->lock);
@@ -2928,7 +2928,7 @@
     if (mutex->th == 0) {
 	err = "Attempt to unlock a mutex which is not locked";
     }
-    else if (mutex->th != GET_THREAD()) {
+    else if (mutex->th != th) {
 	err = "Attempt to unlock a mutex which is locked by another thread";
     }
     else {
@@ -2979,7 +2979,7 @@
     mutex_t *mutex;
     GetMutexPtr(self, mutex);
 
-    err = mutex_unlock(mutex);
+    err = mutex_unlock(mutex, GET_THREAD());
     if (err) rb_raise(rb_eThreadError, "%s", err);
 
     return self;
@@ -2996,7 +2996,7 @@
 	/* rb_warn("mutex #<%p> remains to be locked by terminated thread",
 		mutexes); */
 	mutexes = mutex->next_mutex;
-	err = mutex_unlock(mutex);
+	err = mutex_unlock(mutex, GET_THREAD());
 	if (err) rb_bug("invalid keeping_mutexes: %s", err);
     }
 }

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

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