rb_ractor_thread_list() only for current ractor

so that no need to lock the ractor.
This commit is contained in:
Koichi Sasada 2023-03-30 02:38:08 +09:00
parent 94e4182267
commit 30b43f4f1a
Notes: git 2023-03-30 05:56:59 +00:00
3 changed files with 15 additions and 26 deletions

View File

@ -2120,34 +2120,23 @@ rb_ractor_living_thread_num(const rb_ractor_t *r)
return r->threads.cnt; return r->threads.cnt;
} }
// only for current ractor
VALUE 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; 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(); 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; return ary;

View File

@ -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 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 *); 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); bool rb_ractor_p(VALUE rv);
void rb_ractor_living_threads_init(rb_ractor_t *r); void rb_ractor_living_threads_init(rb_ractor_t *r);

View File

@ -2728,7 +2728,7 @@ VALUE
rb_thread_list(void) rb_thread_list(void)
{ {
// TODO // TODO
return rb_ractor_thread_list(GET_RACTOR()); return rb_ractor_thread_list();
} }
/* /*