summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-29 07:19:32 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-29 07:19:32 +0000
commita25b3c05e7600a5b66e8043b6e9dbb8927bca94b (patch)
treec2d478f0bb22a5f7fada4c6e71943803c160d4ae /thread.c
parent0d546bd1ff9dd4ac57c7a2d37ef0e9653c0b3810 (diff)
merges r21148 from trunk into ruby_1_9_1.
* 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/branches/ruby_1_9_1@21160 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 bdf21c50a7..081c3cd507 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;