* 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
This commit is contained in:
nobu 2011-12-14 01:20:11 +00:00
parent aa432d2334
commit f2fff83e96
3 changed files with 29 additions and 3 deletions

View File

@ -1,3 +1,11 @@
Wed Dec 14 10:20:08 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <okkez000@gmail.com> Wed Dec 14 01:24:55 2011 okkez <okkez000@gmail.com>
* thread_pthread.c (rb_thread_create_timer_thread): fix memory * thread_pthread.c (rb_thread_create_timer_thread): fix memory

10
load.c
View File

@ -405,7 +405,15 @@ load_lock(const char *ftptr)
rb_warning("loading in progress, circular require considered harmful - %s", ftptr); rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
rb_backtrace(); 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 static void

View File

@ -3694,19 +3694,29 @@ rb_barrier_new(void)
return barrier; 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 VALUE
rb_barrier_wait(VALUE self) rb_barrier_wait(VALUE self)
{ {
VALUE mutex = GetBarrierPtr(self); VALUE mutex = GetBarrierPtr(self);
rb_mutex_t *m; rb_mutex_t *m;
int waiting;
if (!mutex) return Qfalse; if (!mutex) return Qfalse;
GetMutexPtr(mutex, m); GetMutexPtr(mutex, m);
if (m->th == GET_THREAD()) return Qfalse; if (m->th == GET_THREAD()) return Qnil;
rb_mutex_lock(mutex); rb_mutex_lock(mutex);
if (DATA_PTR(self)) return Qtrue; if (DATA_PTR(self)) return Qtrue;
waiting = m->cond_waiting;
rb_mutex_unlock(mutex); rb_mutex_unlock(mutex);
return Qfalse; return waiting ? Qnil : Qfalse;
} }
VALUE VALUE