make RB_DEBUG_COUNTER_INC()_thread-safe
This commit is contained in:
parent
d5929b39a9
commit
c58142134c
Notes:
git
2020-12-17 03:44:26 +09:00
@ -3733,6 +3733,7 @@ debug_counter.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
|
|||||||
debug_counter.$(OBJEXT): {$(VPATH)}missing.h
|
debug_counter.$(OBJEXT): {$(VPATH)}missing.h
|
||||||
debug_counter.$(OBJEXT): {$(VPATH)}st.h
|
debug_counter.$(OBJEXT): {$(VPATH)}st.h
|
||||||
debug_counter.$(OBJEXT): {$(VPATH)}subst.h
|
debug_counter.$(OBJEXT): {$(VPATH)}subst.h
|
||||||
|
debug_counter.$(OBJEXT): {$(VPATH)}thread_native.h
|
||||||
dir.$(OBJEXT): $(hdrdir)/ruby.h
|
dir.$(OBJEXT): $(hdrdir)/ruby.h
|
||||||
dir.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
dir.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
||||||
dir.$(OBJEXT): $(top_srcdir)/internal/array.h
|
dir.$(OBJEXT): $(top_srcdir)/internal/array.h
|
||||||
|
@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
#include "internal.h"
|
|
||||||
#include "debug_counter.h"
|
#include "debug_counter.h"
|
||||||
|
#include "internal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include "ruby/thread_native.h"
|
||||||
|
|
||||||
#if USE_DEBUG_COUNTER
|
#if USE_DEBUG_COUNTER
|
||||||
|
|
||||||
static const char *const debug_counter_names[] = {
|
static const char *const debug_counter_names[] = {
|
||||||
""
|
""
|
||||||
#define RB_DEBUG_COUNTER(name) #name,
|
#define RB_DEBUG_COUNTER(name) #name,
|
||||||
@ -23,8 +25,28 @@ static const char *const debug_counter_names[] = {
|
|||||||
|
|
||||||
MJIT_SYMBOL_EXPORT_BEGIN
|
MJIT_SYMBOL_EXPORT_BEGIN
|
||||||
size_t rb_debug_counter[numberof(debug_counter_names)];
|
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
|
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;
|
int debug_counter_disable_show_at_exit = 0;
|
||||||
|
|
||||||
// note that this operation is not atomic.
|
// 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.");
|
rb_debug_counter_show_results("normal exit.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_debug_counter_show_results(const char *msg)
|
rb_debug_counter_show_results(const char *msg)
|
||||||
{
|
{
|
||||||
|
@ -391,19 +391,27 @@ enum rb_debug_counter_type {
|
|||||||
|
|
||||||
#if USE_DEBUG_COUNTER
|
#if USE_DEBUG_COUNTER
|
||||||
extern size_t rb_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
|
inline static int
|
||||||
rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond)
|
rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond)
|
||||||
{
|
{
|
||||||
if (cond) {
|
if (cond) {
|
||||||
|
if (ruby_single_main_ractor != NULL) {
|
||||||
rb_debug_counter[(int)type] += add;
|
rb_debug_counter[(int)type] += add;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
rb_debug_counter_add_atomic(type, add);
|
||||||
|
}
|
||||||
|
}
|
||||||
return cond;
|
return cond;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static int
|
inline static int
|
||||||
rb_debug_counter_max(enum rb_debug_counter_type type, unsigned int num)
|
rb_debug_counter_max(enum rb_debug_counter_type type, unsigned int num)
|
||||||
{
|
{
|
||||||
|
// TODO: sync
|
||||||
if (rb_debug_counter[(int)type] < num) {
|
if (rb_debug_counter[(int)type] < num) {
|
||||||
rb_debug_counter[(int)type] = num;
|
rb_debug_counter[(int)type] = num;
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user