зеркало из https://github.com/github/ruby.git
* thread.c (rb_barrier_waiting): save the number of waiting threads
in RBASIC()->flags. [ruby-dev:45002] [Bug #5768] * thread.c (rb_barrier_wait): increment and decrement around rb_mutex_lock, and use rb_barrier_waiting(). * thread.c (rb_barrier_release): use rb_barrier_waiting(). * thread.c (rb_barrier_destroy): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
035e4949c5
Коммит
82ab1e189b
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Sat Dec 31 06:28:37 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* thread.c (rb_barrier_waiting): save the number of waiting threads
|
||||
in RBASIC()->flags. [ruby-dev:45002] [Bug #5768]
|
||||
|
||||
* thread.c (rb_barrier_wait): increment and decrement around
|
||||
rb_mutex_lock, and use rb_barrier_waiting().
|
||||
|
||||
* thread.c (rb_barrier_release): use rb_barrier_waiting().
|
||||
|
||||
* thread.c (rb_barrier_destroy): ditto.
|
||||
|
||||
Mon Dec 26 17:20:10 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* vm.c (vm_exec): add guard to prevent optimization for LLVM clang.
|
||||
|
|
|
@ -181,7 +181,6 @@ void rb_thread_execute_interrupts(VALUE th);
|
|||
void rb_clear_trace_func(void);
|
||||
VALUE rb_thread_backtrace(VALUE thval);
|
||||
VALUE rb_get_coverages(void);
|
||||
int rb_barrier_waiting(VALUE barrier);
|
||||
|
||||
/* thread_pthread.c, thread_win32.c */
|
||||
void Init_native_thread(void);
|
||||
|
|
40
thread.c
40
thread.c
|
@ -3685,6 +3685,21 @@ barrier_alloc(VALUE klass)
|
|||
}
|
||||
|
||||
#define GetBarrierPtr(obj) ((VALUE)rb_check_typeddata((obj), &barrier_data_type))
|
||||
#define BARRIER_WAITING_MASK (FL_USER0|FL_USER1|FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6|FL_USER7|FL_USER8|FL_USER9|FL_USER10|FL_USER11|FL_USER12|FL_USER13|FL_USER14|FL_USER15|FL_USER16|FL_USER17|FL_USER18|FL_USER19)
|
||||
#define BARRIER_WAITING_SHIFT (FL_USHIFT)
|
||||
#define rb_barrier_waiting(b) ((RBASIC(b)->flags&BARRIER_WAITING_MASK)>>BARRIER_WAITING_SHIFT)
|
||||
#define rb_barrier_waiting_inc(b) do { \
|
||||
int w = rb_barrier_waiting(b); \
|
||||
w++; \
|
||||
RBASIC(b)->flags &= ~BARRIER_WAITING_MASK; \
|
||||
RBASIC(b)->flags |= (w << BARRIER_WAITING_SHIFT); \
|
||||
} while (0)
|
||||
#define rb_barrier_waiting_dec(b) do { \
|
||||
int w = rb_barrier_waiting(b); \
|
||||
w--; \
|
||||
RBASIC(b)->flags &= ~BARRIER_WAITING_MASK; \
|
||||
RBASIC(b)->flags |= (w << BARRIER_WAITING_SHIFT); \
|
||||
} while (0)
|
||||
|
||||
VALUE
|
||||
rb_barrier_new(void)
|
||||
|
@ -3707,16 +3722,16 @@ 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 Qnil;
|
||||
rb_barrier_waiting_inc(self);
|
||||
rb_mutex_lock(mutex);
|
||||
rb_barrier_waiting_dec(self);
|
||||
if (DATA_PTR(self)) return Qtrue;
|
||||
waiting = m->cond_waiting;
|
||||
rb_mutex_unlock(mutex);
|
||||
return waiting ? Qnil : Qfalse;
|
||||
return rb_barrier_waiting(self) > 0 ? Qnil : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3726,10 +3741,8 @@ VALUE
|
|||
rb_barrier_release(VALUE self)
|
||||
{
|
||||
VALUE mutex = GetBarrierPtr(self);
|
||||
rb_mutex_t *m;
|
||||
rb_mutex_unlock(mutex);
|
||||
GetMutexPtr(mutex, m);
|
||||
return m->cond_waiting > 0 ? Qtrue : Qfalse;
|
||||
return rb_barrier_waiting(self) > 0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3739,22 +3752,9 @@ VALUE
|
|||
rb_barrier_destroy(VALUE self)
|
||||
{
|
||||
VALUE mutex = GetBarrierPtr(self);
|
||||
rb_mutex_t *m;
|
||||
DATA_PTR(self) = 0;
|
||||
rb_mutex_unlock(mutex);
|
||||
GetMutexPtr(mutex, m);
|
||||
return m->cond_waiting > 0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
int
|
||||
rb_barrier_waiting(VALUE self)
|
||||
{
|
||||
VALUE mutex = GetBarrierPtr(self);
|
||||
rb_mutex_t *m;
|
||||
|
||||
if (!mutex) return 0;
|
||||
GetMutexPtr(mutex, m);
|
||||
return m->cond_waiting;
|
||||
return rb_barrier_waiting(self) > 0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/* variables for recursive traversals */
|
||||
|
|
Загрузка…
Ссылка в новой задаче