summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-28 09:43:02 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-28 09:43:02 +0000
commit524ec326e28d07ac621466309ec14b6df897c533 (patch)
tree6853bdebf8662c7602f59c790fcc58b6dcd9bf28 /thread.c
parenta389b36398ccaa9485e286cfde6d1ad2a21ef047 (diff)
merges r21105 and r21106 from trunk into ruby_1_9_1.
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/thread.c b/thread.c
index 2fcac49954..bdf21c50a7 100644
--- a/thread.c
+++ b/thread.c
@@ -2708,7 +2708,7 @@ thgroup_add(VALUE group, VALUE thread)
#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 volatile *th);
static void
mutex_free(void *ptr)
@@ -2717,7 +2717,8 @@ mutex_free(void *ptr)
mutex_t *mutex = ptr;
if (mutex->th) {
/* rb_warn("free locked mutex"); */
- mutex_unlock(mutex);
+ const 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 @@ rb_mutex_lock(VALUE self)
}
static const char *
-mutex_unlock(mutex_t *mutex)
+mutex_unlock(mutex_t *mutex, rb_thread_t volatile *th)
{
const char *err = NULL;
- rb_thread_t *th = GET_THREAD();
mutex_t *th_mutex;
native_mutex_lock(&mutex->lock);
@@ -2928,7 +2928,7 @@ mutex_unlock(mutex_t *mutex)
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 @@ rb_mutex_unlock(VALUE self)
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_mutex_unlock_all(mutex_t *mutexes)
/* 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);
}
}