diff --git a/ChangeLog b/ChangeLog index 3654044a06..395978ac80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 11 01:08:01 2008 Yukihiro Matsumoto + + * thread.c (rb_mutex_unlock): proper error message for unlocking + mutex that is not locked. a patch from Yusuke ENDOH + in [ruby-dev:33010]. + Thu Jan 10 18:00:41 2008 Yukihiro Matsumoto * prelude.rb (Mutex::synchronize): capture exception from unlock. diff --git a/thread.c b/thread.c index 31679bb9ed..e5b79b7330 100644 --- a/thread.c +++ b/thread.c @@ -2362,22 +2362,30 @@ VALUE rb_mutex_unlock(VALUE self) { mutex_t *mutex; + char *err = NULL; GetMutexPtr(self, mutex); - if (mutex->th != GET_THREAD()) { - rb_raise(rb_eThreadError, - "Attempt to unlock a mutex which is locked by another thread"); + native_mutex_lock(&mutex->lock); + + if (mutex->th == 0) { + err = "Attempt to unlock a mutex which is not locked"; + } + else if (mutex->th != GET_THREAD()) { + err = "Attempt to unlock a mutex which is locked by another thread"; + } + else { + mutex->th = 0; + if (mutex->cond_waiting > 0) { + /* waiting thread */ + native_cond_signal(&mutex->cond); + mutex->cond_waiting--; + } } - native_mutex_lock(&mutex->lock); - mutex->th = 0; - if (mutex->cond_waiting > 0) { - /* waiting thread */ - native_cond_signal(&mutex->cond); - mutex->cond_waiting--; - } native_mutex_unlock(&mutex->lock); + if (err) rb_raise(rb_eThreadError, err); + return self; } diff --git a/version.h b/version.h index 698088098d..eeedb4ce53 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2008-01-10" +#define RUBY_RELEASE_DATE "2008-01-11" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20080110 +#define RUBY_RELEASE_CODE 20080111 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2008 #define RUBY_RELEASE_MONTH 1 -#define RUBY_RELEASE_DAY 10 +#define RUBY_RELEASE_DAY 11 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[];