зеркало из https://github.com/github/ruby.git
`rb_ractor_thread_list()` only for current ractor
so that no need to lock the ractor.
This commit is contained in:
Родитель
94e4182267
Коммит
30b43f4f1a
37
ractor.c
37
ractor.c
|
@ -2120,34 +2120,23 @@ rb_ractor_living_thread_num(const rb_ractor_t *r)
|
|||
return r->threads.cnt;
|
||||
}
|
||||
|
||||
// only for current ractor
|
||||
VALUE
|
||||
rb_ractor_thread_list(rb_ractor_t *r)
|
||||
rb_ractor_thread_list(void)
|
||||
{
|
||||
rb_ractor_t *r = GET_RACTOR();
|
||||
rb_thread_t *th = 0;
|
||||
VALUE *ts;
|
||||
int ts_cnt;
|
||||
|
||||
RACTOR_LOCK(r);
|
||||
{
|
||||
ts = ALLOCA_N(VALUE, r->threads.cnt);
|
||||
ts_cnt = 0;
|
||||
|
||||
ccan_list_for_each(&r->threads.set, th, lt_node) {
|
||||
switch (th->status) {
|
||||
case THREAD_RUNNABLE:
|
||||
case THREAD_STOPPED:
|
||||
case THREAD_STOPPED_FOREVER:
|
||||
ts[ts_cnt++] = th->self;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
RACTOR_UNLOCK(r);
|
||||
|
||||
VALUE ary = rb_ary_new();
|
||||
for (int i=0; i<ts_cnt; i++) {
|
||||
rb_ary_push(ary, ts[i]);
|
||||
|
||||
ccan_list_for_each(&r->threads.set, th, lt_node) {
|
||||
switch (th->status) {
|
||||
case THREAD_RUNNABLE:
|
||||
case THREAD_STOPPED:
|
||||
case THREAD_STOPPED_FOREVER:
|
||||
rb_ary_push(ary, th->self);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ary;
|
||||
|
|
|
@ -209,7 +209,7 @@ void rb_ractor_send_parameters(rb_execution_context_t *ec, rb_ractor_t *g, VALUE
|
|||
VALUE rb_thread_create_ractor(rb_ractor_t *g, VALUE args, VALUE proc); // defined in thread.c
|
||||
|
||||
int rb_ractor_living_thread_num(const rb_ractor_t *);
|
||||
VALUE rb_ractor_thread_list(rb_ractor_t *r);
|
||||
VALUE rb_ractor_thread_list(void);
|
||||
bool rb_ractor_p(VALUE rv);
|
||||
|
||||
void rb_ractor_living_threads_init(rb_ractor_t *r);
|
||||
|
|
2
thread.c
2
thread.c
|
@ -2728,7 +2728,7 @@ VALUE
|
|||
rb_thread_list(void)
|
||||
{
|
||||
// TODO
|
||||
return rb_ractor_thread_list(GET_RACTOR());
|
||||
return rb_ractor_thread_list();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче