* 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
This commit is contained in:
nobu 2008-09-26 08:02:07 +00:00
Родитель 3deb806a06
Коммит f8718692a2
2 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Fri Sep 26 17:02:04 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <matz@ruby-lang.org> Fri Sep 26 12:04:07 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/curses/curses.c: should include <ruby/io.h>. * ext/curses/curses.c: should include <ruby/io.h>.

Просмотреть файл

@ -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 >= maxth && maxth) break;
} }
} }
if (!woken && woken_thread) *woken_thread = 0;
return woken; return woken;
} }
@ -3128,23 +3129,25 @@ rb_barrier_wait(VALUE self)
{ {
rb_barrier_t *barrier; rb_barrier_t *barrier;
rb_thread_list_t *q; rb_thread_list_t *q;
rb_thread_t *th = GET_THREAD();
Data_Get_Struct(self, rb_barrier_t, barrier); Data_Get_Struct(self, rb_barrier_t, barrier);
if (!barrier->owner || barrier->owner->status == THREAD_KILLED) { if (!barrier->owner || barrier->owner->status == THREAD_KILLED) {
barrier->owner = 0; barrier->owner = 0;
if (thlist_signal(&barrier->waiting, 1, &barrier->owner)) return Qfalse; if (thlist_signal(&barrier->waiting, 1, &barrier->owner)) return Qfalse;
barrier->owner = th;
return Qtrue; return Qtrue;
} }
else if (barrier->owner == GET_THREAD()) { else if (barrier->owner == th) {
return Qfalse; return Qfalse;
} }
else { else {
*barrier->tail = q = ALLOC(rb_thread_list_t); *barrier->tail = q = ALLOC(rb_thread_list_t);
q->th = GET_THREAD(); q->th = th;
q->next = 0; q->next = 0;
barrier->tail = &q->next; barrier->tail = &q->next;
rb_thread_sleep_forever(); rb_thread_sleep_forever();
return barrier->owner == GET_THREAD() ? Qtrue : Qfalse; return barrier->owner == th ? Qtrue : Qfalse;
} }
} }