summaryrefslogtreecommitdiff
path: root/ractor.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-03-30 02:38:08 +0900
committerKoichi Sasada <ko1@atdot.net>2023-03-30 14:56:37 +0900
commit30b43f4f1a37641edc0b146b8a648686a65a3aef (patch)
treecfb8eadc793d0590a1a01459279f0400ab9bda81 /ractor.c
parent94e41822679ebd269564ad10d366596e1514d4ef (diff)
`rb_ractor_thread_list()` only for current ractor
so that no need to lock the ractor.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7616
Diffstat (limited to 'ractor.c')
-rw-r--r--ractor.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/ractor.c b/ractor.c
index 23b3ca98f3..cd1a15eb2b 100644
--- a/ractor.c
+++ b/ractor.c
@@ -2120,35 +2120,24 @@ 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;
+ VALUE ary = rb_ary_new();
- 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;
- }
+ 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;
}
}
- RACTOR_UNLOCK(r);
-
- VALUE ary = rb_ary_new();
- for (int i=0; i<ts_cnt; i++) {
- rb_ary_push(ary, ts[i]);
- }
return ary;
}