Make Addrinfo objects Ractor shareable
[ruby.git] / internal / thread.h
blob5406a617e402ef65fd1b127f9f2993bbd819993d
1 #ifndef INTERNAL_THREAD_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_THREAD_H
3 /**
4 * @author Ruby developers <ruby-core@ruby-lang.org>
5 * @copyright This file is a part of the programming language Ruby.
6 * Permission is hereby granted, to either redistribute and/or
7 * modify this file, provided that the conditions mentioned in the
8 * file COPYING are met. Consult the file for details.
9 * @brief Internal header for Thread.
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 */
15 struct rb_thread_struct; /* in vm_core.h */
16 struct rb_io;
18 #define RB_VM_SAVE_MACHINE_CONTEXT(th) \
19 do { \
20 FLUSH_REGISTER_WINDOWS; \
21 setjmp((th)->ec->machine.regs); \
22 SET_MACHINE_STACK_END(&(th)->ec->machine.stack_end); \
23 } while (0)
25 /* thread.c */
26 #define COVERAGE_INDEX_LINES 0
27 #define COVERAGE_INDEX_BRANCHES 1
28 #define COVERAGE_TARGET_LINES 1
29 #define COVERAGE_TARGET_BRANCHES 2
30 #define COVERAGE_TARGET_METHODS 4
31 #define COVERAGE_TARGET_ONESHOT_LINES 8
32 #define COVERAGE_TARGET_EVAL 16
34 #define RUBY_FATAL_THREAD_KILLED INT2FIX(0)
35 #define RUBY_FATAL_THREAD_TERMINATED INT2FIX(1)
36 #define RUBY_FATAL_FIBER_KILLED RB_INT2FIX(2)
38 VALUE rb_obj_is_mutex(VALUE obj);
39 VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
40 void rb_thread_execute_interrupts(VALUE th);
41 VALUE rb_get_coverages(void);
42 int rb_get_coverage_mode(void);
43 VALUE rb_default_coverage(int);
44 VALUE rb_thread_shield_new(void);
45 bool rb_thread_shield_owned(VALUE self);
46 VALUE rb_thread_shield_wait(VALUE self);
47 VALUE rb_thread_shield_release(VALUE self);
48 VALUE rb_thread_shield_destroy(VALUE self);
49 int rb_thread_to_be_killed(VALUE thread);
50 void rb_thread_acquire_fork_lock(void);
51 void rb_thread_release_fork_lock(void);
52 void rb_thread_reset_fork_lock(void);
53 void rb_mutex_allow_trap(VALUE self, int val);
54 VALUE rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data);
55 VALUE rb_mutex_owned_p(VALUE self);
56 VALUE rb_exec_recursive_outer_mid(VALUE (*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h, ID mid);
57 void ruby_mn_threads_params(void);
59 int rb_thread_io_wait(struct rb_io *io, int events, struct timeval * timeout);
60 int rb_thread_wait_for_single_fd(int fd, int events, struct timeval * timeout);
62 size_t rb_thread_io_close_interrupt(struct rb_io *);
63 void rb_thread_io_close_wait(struct rb_io *);
65 void rb_ec_check_ints(struct rb_execution_context_struct *ec);
67 RUBY_SYMBOL_EXPORT_BEGIN
69 void *rb_thread_prevent_fork(void *(*func)(void *), void *data); /* for ext/socket/raddrinfo.c */
71 /* Temporary. This API will be removed (renamed). */
72 VALUE rb_thread_io_blocking_region(struct rb_io *io, rb_blocking_function_t *func, void *data1);
73 VALUE rb_thread_io_blocking_call(struct rb_io *io, rb_blocking_function_t *func, void *data1, int events);
75 /* thread.c (export) */
76 int ruby_thread_has_gvl_p(void); /* for ext/fiddle/closure.c */
78 RUBY_SYMBOL_EXPORT_END
80 int rb_threadptr_execute_interrupts(struct rb_thread_struct *th, int blocking_timing);
81 bool rb_thread_mn_schedulable(VALUE thread);
83 // interrupt exec
85 typedef VALUE (rb_interrupt_exec_func_t)(void *data);
87 enum rb_interrupt_exec_flag {
88 rb_interrupt_exec_flag_none = 0x00,
89 rb_interrupt_exec_flag_value_data = 0x01,
92 // interrupt the target_th and run func.
93 struct rb_ractor_struct;
95 void rb_threadptr_interrupt_exec(struct rb_thread_struct *target_th,
96 rb_interrupt_exec_func_t *func, void *data, enum rb_interrupt_exec_flag flags);
98 // create a thread in the target_r and run func on the created thread.
99 void rb_ractor_interrupt_exec(struct rb_ractor_struct *target_r,
100 rb_interrupt_exec_func_t *func, void *data, enum rb_interrupt_exec_flag flags);
102 void rb_threadptr_interrupt_exec_task_mark(struct rb_thread_struct *th);
104 #endif /* INTERNAL_THREAD_H */