diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-04 16:02:07 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-04 16:02:07 +0000 |
commit | bbfbf662cceb6e7d8dc769ca365c563b9c073592 (patch) | |
tree | 9ea0a75f1d52fd7a2be933c5342cbfc290e51adb /thread.c | |
parent | 1bdf339516c9886db6f950da6f5506c4f94baa65 (diff) | |
download | ruby-bbfbf662cceb6e7d8dc769ca365c563b9c073592.tar.gz |
* thread.c (rb_mutex_owned_p): new method that return current
thread have the target mutex or not. [Feature #7505] [ruby-dev:46697]
* test/ruby/test_thread.rb (test_mutex_owned, test_mutex_owned2):
test for the above.
* NEWS: new for the above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -4251,6 +4251,28 @@ rb_mutex_lock(VALUE self) return self; } +/* + * call-seq: + * mutex.owned? -> true or false + * + * Returns +true+ if this lock is currently held by current thread. + * <em>This API is experimental, and subject to change.</em> + */ +static VALUE +rb_mutex_owned_p(VALUE self) +{ + VALUE owned = Qfalse; + rb_thread_t *th = GET_THREAD(); + rb_mutex_t *mutex; + + GetMutexPtr(self, mutex); + + if (mutex->th == th) + owned = Qtrue; + + return owned; +} + static const char * rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t volatile *th) { @@ -4874,6 +4896,7 @@ Init_Thread(void) rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0); rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1); rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize_m, 0); + rb_define_method(rb_cMutex, "owned?", rb_mutex_owned_p, 0); recursive_key = rb_intern("__recursive_key__"); rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError); |