From f8718692a2ee7e62e2fa3678963c8d71809abb42 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 26 Sep 2008 08:02:07 +0000 Subject: [PATCH] * thread.c (thlist_signal): clears the woken thread if nothing woke. * thread.c (rb_barrier_wait): achieves the lock if no thread was waiting yet. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ thread.c | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 751e0d948e..6ecad566d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Sep 26 17:02:04 2008 Nobuyoshi Nakada + + * thread.c (thlist_signal): clears the woken thread if nothing woke. + + * thread.c (rb_barrier_wait): achieves the lock if no thread was + waiting yet. + Fri Sep 26 12:04:07 2008 Yukihiro Matsumoto * ext/curses/curses.c: should include . diff --git a/thread.c b/thread.c index 964fb7c60a..646223e8f5 100644 --- a/thread.c +++ b/thread.c @@ -3076,6 +3076,7 @@ thlist_signal(rb_thread_list_t **list, unsigned int maxth, rb_thread_t **woken_t if (++woken >= maxth && maxth) break; } } + if (!woken && woken_thread) *woken_thread = 0; return woken; } @@ -3128,23 +3129,25 @@ rb_barrier_wait(VALUE self) { rb_barrier_t *barrier; rb_thread_list_t *q; + rb_thread_t *th = GET_THREAD(); Data_Get_Struct(self, rb_barrier_t, barrier); if (!barrier->owner || barrier->owner->status == THREAD_KILLED) { barrier->owner = 0; if (thlist_signal(&barrier->waiting, 1, &barrier->owner)) return Qfalse; + barrier->owner = th; return Qtrue; } - else if (barrier->owner == GET_THREAD()) { + else if (barrier->owner == th) { return Qfalse; } else { *barrier->tail = q = ALLOC(rb_thread_list_t); - q->th = GET_THREAD(); + q->th = th; q->next = 0; barrier->tail = &q->next; rb_thread_sleep_forever(); - return barrier->owner == GET_THREAD() ? Qtrue : Qfalse; + return barrier->owner == th ? Qtrue : Qfalse; } }