aboutsummaryrefslogtreecommitdiffstats
path: root/vm_core.h
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-11-11 14:37:31 +0900
committerKoichi Sasada <ko1@atdot.net>2020-11-11 15:49:02 +0900
commit1e8abe5d03ae386af82e2c95ef05170cd9791889 (patch)
tree053d9153f20d975961d39cc6e2471290a49bd618 /vm_core.h
parentdd07354f2797473261f06159801e50dc6445ef76 (diff)
downloadruby-1e8abe5d03ae386af82e2c95ef05170cd9791889.tar.gz
introduce USE_VM_CLOCK for windows.
The timer function used on windows system set timer interrupt flag of current main ractor's executing ec and thread can detect the end of time slice. However, to set all ec->interrupt_flag for all running ractors, it is requires to synchronize with other ractors. However, timer thread can not acquire the ractor-wide lock because of some limitation. To solve this issue, this patch introduces USE_VM_CLOCK compile option to introduce rb_vm_t::clock. This clock will be incremented by the timer thread and each thread can check the incrementing by comparison with previous checked clock. At last, on windows platform this patch introduces some overhead, but I think there is no critical performance issue because of this modification.
Diffstat (limited to 'vm_core.h')
-rw-r--r--vm_core.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/vm_core.h b/vm_core.h
index 9ef3af515c..53bf67c2e5 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -649,6 +649,10 @@ typedef struct rb_vm_struct {
const struct rb_builtin_function *builtin_function_table;
int builtin_inline_index;
+#if USE_VM_CLOCK
+ uint32_t clock;
+#endif
+
/* params */
struct { /* size in byte */
size_t thread_vm_stack_size;
@@ -845,6 +849,9 @@ struct rb_execution_context_struct {
/* interrupt flags */
rb_atomic_t interrupt_flag;
rb_atomic_t interrupt_mask; /* size should match flag */
+#if USE_VM_CLOCK
+ uint32_t checked_clock;
+#endif
rb_fiber_t *fiber_ptr;
struct rb_thread_struct *thread_ptr;
@@ -1845,7 +1852,20 @@ enum {
#define RUBY_VM_SET_VM_BARRIER_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, VM_BARRIER_INTERRUPT_MASK)
#define RUBY_VM_INTERRUPTED(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask & \
(PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
-#define RUBY_VM_INTERRUPTED_ANY(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask)
+
+static inline bool
+RUBY_VM_INTERRUPTED_ANY(rb_execution_context_t *ec)
+{
+#if USE_VM_CLOCK
+ uint32_t current_clock = rb_ec_vm_ptr(ec)->clock;
+
+ if (current_clock != ec->checked_clock) {
+ ec->checked_clock = current_clock;
+ RUBY_VM_SET_TIMER_INTERRUPT(ec);
+ }
+#endif
+ return ec->interrupt_flag & ~(ec)->interrupt_mask;
+}
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt);
int rb_signal_buff_size(void);