diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-12-17 01:29:15 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-12-17 03:43:59 +0900 |
commit | c58142134cccdd31811f12aabf4f9dd3ce6a17f7 (patch) | |
tree | 9d16b373dd8f316e847ec46039a383036014a49e /debug_counter.c | |
parent | d5929b39a9c7944de14c133fa3948b7b3a92e423 (diff) |
make RB_DEBUG_COUNTER_INC()_thread-safe
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3915
Diffstat (limited to 'debug_counter.c')
-rw-r--r-- | debug_counter.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/debug_counter.c b/debug_counter.c index af858115d2..e7b0bb0acd 100644 --- a/debug_counter.c +++ b/debug_counter.c @@ -8,12 +8,14 @@ **********************************************************************/ -#include "internal.h" #include "debug_counter.h" +#include "internal.h" #include <stdio.h> #include <locale.h> +#include "ruby/thread_native.h" #if USE_DEBUG_COUNTER + static const char *const debug_counter_names[] = { "" #define RB_DEBUG_COUNTER(name) #name, @@ -23,8 +25,28 @@ static const char *const debug_counter_names[] = { MJIT_SYMBOL_EXPORT_BEGIN size_t rb_debug_counter[numberof(debug_counter_names)]; +void rb_debug_counter_add_atomic(enum rb_debug_counter_type type, int add); MJIT_SYMBOL_EXPORT_END +rb_nativethread_lock_t debug_counter_lock; + +__attribute__((constructor)) +static void +debug_counter_setup(void) +{ + rb_nativethread_lock_initialize(&debug_counter_lock); +} + +void +rb_debug_counter_add_atomic(enum rb_debug_counter_type type, int add) +{ + rb_nativethread_lock_lock(&debug_counter_lock); + { + rb_debug_counter[(int)type] += add; + } + rb_nativethread_lock_unlock(&debug_counter_lock); +} + int debug_counter_disable_show_at_exit = 0; // note that this operation is not atomic. @@ -112,7 +134,9 @@ debug_counter_show_results_at_exit(void) rb_debug_counter_show_results("normal exit."); } } + #else + void rb_debug_counter_show_results(const char *msg) { |