5#include "debug_counter.h"
8#define LOCATION_ARGS const char *file, int line
9#define LOCATION_PARAMS file, line
10#define APPEND_LOCATION_ARGS , const char *file, int line
11#define APPEND_LOCATION_PARAMS , file, line
13#define LOCATION_ARGS void
14#define LOCATION_PARAMS
15#define APPEND_LOCATION_ARGS
16#define APPEND_LOCATION_PARAMS
19bool rb_vm_locked_p(
void);
20void rb_vm_lock_body(LOCATION_ARGS);
21void rb_vm_unlock_body(LOCATION_ARGS);
24NOINLINE(
void rb_vm_lock_enter_body_cr(
struct rb_ractor_struct *cr,
unsigned int *lev APPEND_LOCATION_ARGS));
25NOINLINE(
void rb_vm_lock_enter_body_nb(
unsigned int *lev APPEND_LOCATION_ARGS));
26NOINLINE(
void rb_vm_lock_enter_body(
unsigned int *lev APPEND_LOCATION_ARGS));
27void rb_vm_lock_leave_body_nb(
unsigned int *lev APPEND_LOCATION_ARGS);
28void rb_vm_lock_leave_body(
unsigned int *lev APPEND_LOCATION_ARGS);
29void rb_vm_barrier(
void);
39rb_multi_ractor_p(
void)
41 if (LIKELY(ruby_single_main_ractor)) {
53rb_vm_lock(
const char *file,
int line)
55 RB_DEBUG_COUNTER_INC(vm_sync_lock);
57 if (rb_multi_ractor_p()) {
58 rb_vm_lock_body(LOCATION_PARAMS);
63rb_vm_unlock(
const char *file,
int line)
65 if (rb_multi_ractor_p()) {
66 rb_vm_unlock_body(LOCATION_PARAMS);
71rb_vm_lock_enter(
unsigned int *lev,
const char *file,
int line)
73 RB_DEBUG_COUNTER_INC(vm_sync_lock_enter);
75 if (rb_multi_ractor_p()) {
76 rb_vm_lock_enter_body(lev APPEND_LOCATION_PARAMS);
81rb_vm_lock_enter_nb(
unsigned int *lev,
const char *file,
int line)
83 RB_DEBUG_COUNTER_INC(vm_sync_lock_enter_nb);
85 if (rb_multi_ractor_p()) {
86 rb_vm_lock_enter_body_nb(lev APPEND_LOCATION_PARAMS);
91rb_vm_lock_leave_nb(
unsigned int *lev,
const char *file,
int line)
93 if (rb_multi_ractor_p()) {
94 rb_vm_lock_leave_body_nb(lev APPEND_LOCATION_PARAMS);
99rb_vm_lock_leave(
unsigned int *lev,
const char *file,
int line)
101 if (rb_multi_ractor_p()) {
102 rb_vm_lock_leave_body(lev APPEND_LOCATION_PARAMS);
107rb_vm_lock_enter_cr(
struct rb_ractor_struct *cr,
unsigned int *levp,
const char *file,
int line)
109 RB_DEBUG_COUNTER_INC(vm_sync_lock_enter_cr);
110 rb_vm_lock_enter_body_cr(cr, levp APPEND_LOCATION_PARAMS);
114rb_vm_lock_leave_cr(
struct rb_ractor_struct *cr,
unsigned int *levp,
const char *file,
int line)
116 rb_vm_lock_leave_body(levp APPEND_LOCATION_PARAMS);
119#define RB_VM_LOCKED_P() rb_vm_locked_p()
121#define RB_VM_LOCK() rb_vm_lock(__FILE__, __LINE__)
122#define RB_VM_UNLOCK() rb_vm_unlock(__FILE__, __LINE__)
124#define RB_VM_LOCK_ENTER_CR_LEV(cr, levp) rb_vm_lock_enter_cr(cr, levp, __FILE__, __LINE__)
125#define RB_VM_LOCK_LEAVE_CR_LEV(cr, levp) rb_vm_lock_leave_cr(cr, levp, __FILE__, __LINE__)
126#define RB_VM_LOCK_ENTER_LEV(levp) rb_vm_lock_enter(levp, __FILE__, __LINE__)
127#define RB_VM_LOCK_LEAVE_LEV(levp) rb_vm_lock_leave(levp, __FILE__, __LINE__)
129#define RB_VM_LOCK_ENTER() { unsigned int _lev; RB_VM_LOCK_ENTER_LEV(&_lev);
130#define RB_VM_LOCK_LEAVE() RB_VM_LOCK_LEAVE_LEV(&_lev); }
131#define RB_VM_LOCKING() \
132 for (unsigned int vm_locking_level, vm_locking_do = (RB_VM_LOCK_ENTER_LEV(&vm_locking_level), 1); \
133 vm_locking_do; RB_VM_LOCK_LEAVE_LEV(&vm_locking_level), vm_locking_do = 0)
135#define RB_VM_LOCK_ENTER_LEV_NB(levp) rb_vm_lock_enter_nb(levp, __FILE__, __LINE__)
136#define RB_VM_LOCK_LEAVE_LEV_NB(levp) rb_vm_lock_leave_nb(levp, __FILE__, __LINE__)
137#define RB_VM_LOCK_ENTER_NO_BARRIER() { unsigned int _lev; RB_VM_LOCK_ENTER_LEV_NB(&_lev);
138#define RB_VM_LOCK_LEAVE_NO_BARRIER() RB_VM_LOCK_LEAVE_LEV_NB(&_lev); }
139#define RB_VM_LOCKING_NO_BARRIER() \
140 for (unsigned int vm_locking_level, vm_locking_do = (RB_VM_LOCK_ENTER_LEV_NB(&vm_locking_level), 1); \
141 vm_locking_do; RB_VM_LOCK_LEAVE_LEV_NB(&vm_locking_level), vm_locking_do = 0)
144void RUBY_ASSERT_vm_locking(
void);
145void RUBY_ASSERT_vm_unlocking(
void);
146#define ASSERT_vm_locking() RUBY_ASSERT_vm_locking()
147#define ASSERT_vm_unlocking() RUBY_ASSERT_vm_unlocking()
149#define ASSERT_vm_locking()
150#define ASSERT_vm_unlocking()
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define RUBY_EXTERN
Declaration of externally visible global variables.