diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-26 08:02:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-26 08:02:07 +0000 |
commit | f8718692a2ee7e62e2fa3678963c8d71809abb42 (patch) | |
tree | b87fffd965a28d51286347fc3845683a06734cc0 /thread.c | |
parent | 3deb806a067dfcf68dd870f518a6eefe6f8794f7 (diff) |
* 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
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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; } } |