Ruby 3.5.0dev (2025-02-22 revision 412997300569c1853c09813e4924b6df3d7e8669)
thread.h
1#ifndef INTERNAL_THREAD_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_THREAD_H
11#include "ruby/ruby.h" /* for VALUE */
12#include "ruby/intern.h" /* for rb_blocking_function_t */
13#include "ccan/list/list.h" /* for list in rb_io_close_wait_list */
14
15struct rb_thread_struct; /* in vm_core.h */
16
17#define RB_VM_SAVE_MACHINE_CONTEXT(th) \
18 do { \
19 FLUSH_REGISTER_WINDOWS; \
20 setjmp((th)->ec->machine.regs); \
21 SET_MACHINE_STACK_END(&(th)->ec->machine.stack_end); \
22 } while (0)
23
24/* thread.c */
25#define COVERAGE_INDEX_LINES 0
26#define COVERAGE_INDEX_BRANCHES 1
27#define COVERAGE_TARGET_LINES 1
28#define COVERAGE_TARGET_BRANCHES 2
29#define COVERAGE_TARGET_METHODS 4
30#define COVERAGE_TARGET_ONESHOT_LINES 8
31#define COVERAGE_TARGET_EVAL 16
32
33#define RUBY_FATAL_THREAD_KILLED INT2FIX(0)
34#define RUBY_FATAL_THREAD_TERMINATED INT2FIX(1)
35#define RUBY_FATAL_FIBER_KILLED RB_INT2FIX(2)
36
37VALUE rb_obj_is_mutex(VALUE obj);
38VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
39void rb_thread_execute_interrupts(VALUE th);
40VALUE rb_get_coverages(void);
41int rb_get_coverage_mode(void);
42VALUE rb_default_coverage(int);
43VALUE rb_thread_shield_new(void);
44bool rb_thread_shield_owned(VALUE self);
45VALUE rb_thread_shield_wait(VALUE self);
46VALUE rb_thread_shield_release(VALUE self);
47VALUE rb_thread_shield_destroy(VALUE self);
48int rb_thread_to_be_killed(VALUE thread);
49void rb_thread_acquire_fork_lock(void);
50void rb_thread_release_fork_lock(void);
51void rb_thread_reset_fork_lock(void);
52void rb_mutex_allow_trap(VALUE self, int val);
53VALUE rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data);
54VALUE rb_mutex_owned_p(VALUE self);
55VALUE rb_exec_recursive_outer_mid(VALUE (*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h, ID mid);
56void ruby_mn_threads_params(void);
57
58int rb_thread_wait_for_single_fd(int fd, int events, struct timeval * timeout);
59
61 struct ccan_list_head pending_fd_users;
62 VALUE closing_thread;
63 VALUE closing_fiber;
64 VALUE wakeup_mutex;
65};
66int rb_notify_fd_close(int fd, struct rb_io_close_wait_list *busy);
67void rb_notify_fd_close_wait(struct rb_io_close_wait_list *busy);
68
69void rb_ec_check_ints(struct rb_execution_context_struct *ec);
70
71RUBY_SYMBOL_EXPORT_BEGIN
72
73void *rb_thread_prevent_fork(void *(*func)(void *), void *data); /* for ext/socket/raddrinfo.c */
74
75/* Temporary. This API will be removed (renamed). */
76VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
77VALUE rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, int events);
78
79/* thread.c (export) */
80int ruby_thread_has_gvl_p(void); /* for ext/fiddle/closure.c */
81
82RUBY_SYMBOL_EXPORT_END
83
84int rb_threadptr_execute_interrupts(struct rb_thread_struct *th, int blocking_timing);
85bool rb_thread_mn_schedulable(VALUE thread);
86
87// interrupt exec
88
89typedef VALUE (rb_interrupt_exec_func_t)(void *data);
90
91enum rb_interrupt_exec_flag {
92 rb_interrupt_exec_flag_none = 0x00,
93 rb_interrupt_exec_flag_value_data = 0x01,
94};
95
96// interrupt the target_th and run func.
97struct rb_ractor_struct;
98
99void rb_threadptr_interrupt_exec(struct rb_thread_struct *target_th,
100 rb_interrupt_exec_func_t *func, void *data, enum rb_interrupt_exec_flag flags);
101
102// create a thread in the target_r and run func on the created thread.
103void rb_ractor_interrupt_exec(struct rb_ractor_struct *target_r,
104 rb_interrupt_exec_func_t *func, void *data, enum rb_interrupt_exec_flag flags);
105
106void rb_threadptr_interrupt_exec_task_mark(struct rb_thread_struct *th);
107
108#endif /* INTERNAL_THREAD_H */
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40