summaryrefslogtreecommitdiff
path: root/debug_counter.h
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-17 01:29:15 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-17 03:43:59 +0900
commitc58142134cccdd31811f12aabf4f9dd3ce6a17f7 (patch)
tree9d16b373dd8f316e847ec46039a383036014a49e /debug_counter.h
parentd5929b39a9c7944de14c133fa3948b7b3a92e423 (diff)
make RB_DEBUG_COUNTER_INC()_thread-safe
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3915
Diffstat (limited to 'debug_counter.h')
-rw-r--r--debug_counter.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/debug_counter.h b/debug_counter.h
index 593d2f701d..362c85e2f5 100644
--- a/debug_counter.h
+++ b/debug_counter.h
@@ -391,12 +391,19 @@ enum rb_debug_counter_type {
#if USE_DEBUG_COUNTER
extern size_t rb_debug_counter[];
+RUBY_EXTERN struct rb_ractor_struct *ruby_single_main_ractor;
+RUBY_EXTERN void rb_debug_counter_add_atomic(enum rb_debug_counter_type type, int add);
inline static int
rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond)
{
if (cond) {
- rb_debug_counter[(int)type] += add;
+ if (ruby_single_main_ractor != NULL) {
+ rb_debug_counter[(int)type] += add;
+ }
+ else {
+ rb_debug_counter_add_atomic(type, add);
+ }
}
return cond;
}
@@ -404,6 +411,7 @@ rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond)
inline static int
rb_debug_counter_max(enum rb_debug_counter_type type, unsigned int num)
{
+ // TODO: sync
if (rb_debug_counter[(int)type] < num) {
rb_debug_counter[(int)type] = num;
return 1;