summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-29 03:03:09 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-29 03:03:09 +0000
commitb2ad49565f10dfdd594680c2fa7a4af81c1027fe (patch)
tree840c36be0f50cc01ff145a9d56b095c05304652f /thread.c
parenta928613a313e7750c7dcee824631cd6ed1690344 (diff)
* thread.c (rb_mutex_trylock): return false if Mutex owned
by current thread. [ruby-core:20943] * thread.c (rb_mutex_lock): check dead lock (recursive lock) here. * test/ruby/test_thread.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/thread.c b/thread.c
index b21af09db9..4f5f150650 100644
--- a/thread.c
+++ b/thread.c
@@ -2796,10 +2796,6 @@ rb_mutex_trylock(VALUE self)
VALUE locked = Qfalse;
GetMutexPtr(self, mutex);
- if (mutex->th == GET_THREAD()) {
- rb_raise(rb_eThreadError, "deadlock; recursive locking");
- }
-
native_mutex_lock(&mutex->lock);
if (mutex->th == 0) {
mutex->th = GET_THREAD();
@@ -2871,11 +2867,16 @@ lock_interrupt(void *ptr)
VALUE
rb_mutex_lock(VALUE self)
{
+
if (rb_mutex_trylock(self) == Qfalse) {
mutex_t *mutex;
rb_thread_t *th = GET_THREAD();
GetMutexPtr(self, mutex);
+ if (mutex->th == GET_THREAD()) {
+ rb_raise(rb_eThreadError, "deadlock; recursive locking");
+ }
+
while (mutex->th != th) {
int interrupted;
enum rb_thread_status prev_status = th->status;