aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/thread.c b/thread.c
index 7165905007..192a96bfe5 100644
--- a/thread.c
+++ b/thread.c
@@ -3694,19 +3694,29 @@ rb_barrier_new(void)
return barrier;
}
+/*
+ * Wait a barrier.
+ *
+ * Returns
+ * true: acquired the barrier
+ * false: the barrier was destroyed and no other threads waiting
+ * nil: the barrier was destroyed but still in use
+ */
VALUE
rb_barrier_wait(VALUE self)
{
VALUE mutex = GetBarrierPtr(self);
rb_mutex_t *m;
+ int waiting;
if (!mutex) return Qfalse;
GetMutexPtr(mutex, m);
- if (m->th == GET_THREAD()) return Qfalse;
+ if (m->th == GET_THREAD()) return Qnil;
rb_mutex_lock(mutex);
if (DATA_PTR(self)) return Qtrue;
+ waiting = m->cond_waiting;
rb_mutex_unlock(mutex);
- return Qfalse;
+ return waiting ? Qnil : Qfalse;
}
VALUE