mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
fix ractor-locking around rb_ractor_thread_list()
With locking a ractor, rb_ary_push() can call RB_VM_LOCK_ENTER() and it violates an assertion: should not acquire ractor-lock.
This commit is contained in:
parent
458d5175b9
commit
7fcb6b3dbe
1 changed files with 21 additions and 9 deletions
30
ractor.c
30
ractor.c
|
@ -1672,21 +1672,33 @@ rb_ractor_living_thread_num(const rb_ractor_t *r)
|
||||||
VALUE
|
VALUE
|
||||||
rb_ractor_thread_list(rb_ractor_t *r)
|
rb_ractor_thread_list(rb_ractor_t *r)
|
||||||
{
|
{
|
||||||
VALUE ary = rb_ary_new();
|
|
||||||
rb_thread_t *th = 0;
|
rb_thread_t *th = 0;
|
||||||
|
VALUE *ts;
|
||||||
|
int ts_cnt;
|
||||||
|
|
||||||
RACTOR_LOCK(r);
|
RACTOR_LOCK(r);
|
||||||
list_for_each(&r->threads.set, th, lt_node) {
|
{
|
||||||
switch (th->status) {
|
ts = ALLOCA_N(VALUE, r->threads.cnt);
|
||||||
case THREAD_RUNNABLE:
|
ts_cnt = 0;
|
||||||
case THREAD_STOPPED:
|
|
||||||
case THREAD_STOPPED_FOREVER:
|
list_for_each(&r->threads.set, th, lt_node) {
|
||||||
rb_ary_push(ary, th->self);
|
switch (th->status) {
|
||||||
default:
|
case THREAD_RUNNABLE:
|
||||||
break;
|
case THREAD_STOPPED:
|
||||||
|
case THREAD_STOPPED_FOREVER:
|
||||||
|
ts[ts_cnt++] = th->self;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RACTOR_UNLOCK(r);
|
RACTOR_UNLOCK(r);
|
||||||
|
|
||||||
|
VALUE ary = rb_ary_new();
|
||||||
|
for (int i=0; i<ts_cnt; i++) {
|
||||||
|
rb_ary_push(ary, ts[i]);
|
||||||
|
}
|
||||||
|
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue