From f2fff83e96fe5faea36354993602195881ee8ba3 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 14 Dec 2011 01:20:11 +0000 Subject: [PATCH] * load.c (load_lock): delete the loading barrier if it has been destroyed. * thread.c (rb_barrier_wait): return nil for recursive lock instead of false, to distinguish it from destroyed barrier. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ load.c | 10 +++++++++- thread.c | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c06680f81..b58743cec9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Dec 14 10:20:08 2011 Nobuyoshi Nakada + + * load.c (load_lock): delete the loading barrier if it has been + destroyed. + + * thread.c (rb_barrier_wait): return nil for recursive lock + instead of false, to distinguish it from destroyed barrier. + Wed Dec 14 01:24:55 2011 okkez * thread_pthread.c (rb_thread_create_timer_thread): fix memory diff --git a/load.c b/load.c index 9d389f9efb..2672051727 100644 --- a/load.c +++ b/load.c @@ -405,7 +405,15 @@ load_lock(const char *ftptr) rb_warning("loading in progress, circular require considered harmful - %s", ftptr); rb_backtrace(); } - return RTEST(rb_barrier_wait((VALUE)data)) ? (char *)ftptr : 0; + switch (rb_barrier_wait((VALUE)data)) { + case Qfalse: + data = (st_data_t)ftptr; + st_delete(loading_tbl, &data, 0); + return 0; + case Qnil: + return 0; + } + return (char *)ftptr; } static void 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