datadog-ruby_core_source 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.datadog.md +4 -0
  3. data/README.md +8 -5
  4. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/build_assert/build_assert.h +40 -0
  5. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/check_type/check_type.h +63 -0
  6. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/container_of/container_of.h +142 -0
  7. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/list/list.h +791 -0
  8. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/str/str.h +17 -0
  9. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/id.h +352 -0
  10. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/id_table.h +39 -0
  11. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/array.h +152 -0
  12. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/basic_operators.h +65 -0
  13. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/bignum.h +244 -0
  14. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/bits.h +650 -0
  15. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/class.h +283 -0
  16. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/cmdlineopt.h +61 -0
  17. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compar.h +29 -0
  18. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compile.h +34 -0
  19. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compilers.h +107 -0
  20. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/complex.h +29 -0
  21. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/cont.h +35 -0
  22. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/dir.h +16 -0
  23. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enc.h +19 -0
  24. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/encoding.h +38 -0
  25. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enum.h +18 -0
  26. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enumerator.h +21 -0
  27. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/error.h +244 -0
  28. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/eval.h +33 -0
  29. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/file.h +38 -0
  30. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/fixnum.h +185 -0
  31. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/gc.h +333 -0
  32. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/hash.h +193 -0
  33. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/imemo.h +257 -0
  34. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/inits.h +47 -0
  35. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/io.h +143 -0
  36. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/load.h +18 -0
  37. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/loadpath.h +16 -0
  38. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/math.h +23 -0
  39. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/missing.h +19 -0
  40. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/numeric.h +274 -0
  41. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/object.h +63 -0
  42. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/parse.h +131 -0
  43. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/proc.h +30 -0
  44. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/process.h +124 -0
  45. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/ractor.h +10 -0
  46. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/random.h +17 -0
  47. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/range.h +40 -0
  48. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/rational.h +71 -0
  49. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/re.h +28 -0
  50. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/ruby_parser.h +102 -0
  51. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/sanitizers.h +330 -0
  52. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/serial.h +23 -0
  53. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/signal.h +24 -0
  54. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/st.h +11 -0
  55. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/static_assert.h +16 -0
  56. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/string.h +199 -0
  57. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/struct.h +119 -0
  58. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/symbol.h +47 -0
  59. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/thread.h +108 -0
  60. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/time.h +37 -0
  61. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/transcode.h +23 -0
  62. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/util.h +27 -0
  63. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/variable.h +70 -0
  64. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/vm.h +137 -0
  65. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/warnings.h +16 -0
  66. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal.h +108 -0
  67. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/iseq.h +351 -0
  68. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/method.h +258 -0
  69. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/node.h +122 -0
  70. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/parser_st.h +162 -0
  71. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/parser_value.h +106 -0
  72. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/ast.h +7964 -0
  73. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/defines.h +260 -0
  74. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/diagnostic.h +451 -0
  75. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/encoding.h +283 -0
  76. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/extension.h +19 -0
  77. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/node.h +129 -0
  78. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/options.h +442 -0
  79. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/pack.h +163 -0
  80. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/parser.h +933 -0
  81. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/prettyprint.h +34 -0
  82. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/prism.h +383 -0
  83. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/regexp.h +43 -0
  84. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/static_literals.h +121 -0
  85. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_buffer.h +228 -0
  86. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_char.h +204 -0
  87. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_constant_pool.h +218 -0
  88. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_integer.h +126 -0
  89. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_list.h +97 -0
  90. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_memchr.h +29 -0
  91. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_newline_list.h +113 -0
  92. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_string.h +190 -0
  93. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_strncasecmp.h +32 -0
  94. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_strpbrk.h +46 -0
  95. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/version.h +29 -0
  96. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism_compile.h +105 -0
  97. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ractor_core.h +382 -0
  98. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ruby_assert.h +14 -0
  99. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ruby_atomic.h +23 -0
  100. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/rubyparser.h +1380 -0
  101. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/shape.h +234 -0
  102. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/thread_none.h +21 -0
  103. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/thread_pthread.h +167 -0
  104. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_core.h +2235 -0
  105. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_debug.h +124 -0
  106. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_opts.h +67 -0
  107. data/lib/datadog/ruby_core_source/version.rb +1 -1
  108. metadata +105 -2
@@ -0,0 +1,105 @@
1
+ #include "prism/prism.h"
2
+ #include "ruby/encoding.h"
3
+
4
+ /**
5
+ * the getlocal and setlocal instructions require two parameters. level is how
6
+ * many hops up the iseq stack one needs to go before finding the correct local
7
+ * table. The index is the index in that table where our variable is.
8
+ *
9
+ * Because these are always calculated and used together, we'll bind them
10
+ * together as a tuple.
11
+ */
12
+ typedef struct pm_local_index_struct {
13
+ int index, level;
14
+ } pm_local_index_t;
15
+
16
+ // A declaration for the struct that lives in compile.c.
17
+ struct iseq_link_anchor;
18
+
19
+ // ScopeNodes are helper nodes, and will never be part of the AST. We manually
20
+ // declare them here to avoid generating them.
21
+ typedef struct pm_scope_node {
22
+ pm_node_t base;
23
+ struct pm_scope_node *previous;
24
+ pm_node_t *ast_node;
25
+ pm_node_t *parameters;
26
+ pm_node_t *body;
27
+ pm_constant_id_list_t locals;
28
+
29
+ const pm_parser_t *parser;
30
+ rb_encoding *encoding;
31
+
32
+ /**
33
+ * This is a pointer to the list of script lines for the ISEQs that will be
34
+ * associated with this scope node. It is only set if
35
+ * RubyVM.keep_script_lines is true. If it is set, it will be set to a
36
+ * pointer to an array that is always stack allocated (so no GC marking is
37
+ * needed by this struct). If it is not set, it will be NULL. It is
38
+ * inherited by all child scopes.
39
+ */
40
+ VALUE *script_lines;
41
+
42
+ /**
43
+ * This is the encoding of the actual filepath object that will be used when
44
+ * a __FILE__ node is compiled or when the path has to be set on a syntax
45
+ * error.
46
+ */
47
+ rb_encoding *filepath_encoding;
48
+
49
+ // The size of the local table on the iseq which includes locals and hidden
50
+ // variables.
51
+ int local_table_for_iseq_size;
52
+
53
+ ID *constants;
54
+ st_table *index_lookup_table;
55
+
56
+ // The current coverage setting, passed down through the various scopes.
57
+ int coverage_enabled;
58
+
59
+ /**
60
+ * This will only be set on the top-level scope node. It will contain all of
61
+ * the instructions pertaining to BEGIN{} nodes.
62
+ */
63
+ struct iseq_link_anchor *pre_execution_anchor;
64
+ } pm_scope_node_t;
65
+
66
+ void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous);
67
+ void pm_scope_node_destroy(pm_scope_node_t *scope_node);
68
+
69
+ typedef struct {
70
+ /** The parser that will do the actual parsing. */
71
+ pm_parser_t parser;
72
+
73
+ /** The options that will be passed to the parser. */
74
+ pm_options_t options;
75
+
76
+ /** The input that represents the source to be parsed. */
77
+ pm_string_t input;
78
+
79
+ /** The resulting scope node that will hold the generated AST. */
80
+ pm_scope_node_t node;
81
+
82
+ /** Whether or not this parse result has performed its parsing yet. */
83
+ bool parsed;
84
+ } pm_parse_result_t;
85
+
86
+ #define PM_SPECIAL_CONSTANT_FLAG ((pm_constant_id_t)(1 << 31))
87
+ #define PM_CONSTANT_AND ((pm_constant_id_t)(idAnd | PM_SPECIAL_CONSTANT_FLAG))
88
+ #define PM_CONSTANT_DOT3 ((pm_constant_id_t)(idDot3 | PM_SPECIAL_CONSTANT_FLAG))
89
+ #define PM_CONSTANT_MULT ((pm_constant_id_t)(idMULT | PM_SPECIAL_CONSTANT_FLAG))
90
+ #define PM_CONSTANT_POW ((pm_constant_id_t)(idPow | PM_SPECIAL_CONSTANT_FLAG))
91
+
92
+ VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath, bool load_error);
93
+ VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
94
+ VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
95
+ VALUE pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath, VALUE *script_lines);
96
+ VALUE pm_parse_stdin(pm_parse_result_t *result);
97
+ void pm_parse_result_free(pm_parse_result_t *result);
98
+
99
+ rb_iseq_t *pm_iseq_new(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum rb_iseq_type, int *error_state);
100
+ rb_iseq_t *pm_iseq_new_top(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, int *error_state);
101
+ rb_iseq_t *pm_iseq_new_main(pm_scope_node_t *node, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt, int *error_state);
102
+ rb_iseq_t *pm_iseq_new_eval(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, int *error_state);
103
+ rb_iseq_t *pm_iseq_new_with_opt(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, enum rb_iseq_type, const rb_compile_option_t *option, int *error_state);
104
+
105
+ VALUE pm_iseq_compile_node(rb_iseq_t *iseq, pm_scope_node_t *node);
@@ -0,0 +1,382 @@
1
+ #include "internal/gc.h"
2
+ #include "ruby/ruby.h"
3
+ #include "ruby/ractor.h"
4
+ #include "vm_core.h"
5
+ #include "id_table.h"
6
+ #include "vm_debug.h"
7
+
8
+ #ifndef RACTOR_CHECK_MODE
9
+ #define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
10
+ #endif
11
+
12
+ enum rb_ractor_basket_type {
13
+ // basket is empty
14
+ basket_type_none,
15
+
16
+ // value is available
17
+ basket_type_ref,
18
+ basket_type_copy,
19
+ basket_type_move,
20
+ basket_type_will,
21
+
22
+ // basket should be deleted
23
+ basket_type_deleted,
24
+
25
+ // basket is reserved
26
+ basket_type_reserved,
27
+
28
+ // take_basket is available
29
+ basket_type_take_basket,
30
+
31
+ // basket is keeping by yielding ractor
32
+ basket_type_yielding,
33
+ };
34
+
35
+ // per ractor taking configuration
36
+ struct rb_ractor_selector_take_config {
37
+ bool closed;
38
+ bool oneshot;
39
+ };
40
+
41
+ struct rb_ractor_basket {
42
+ union {
43
+ enum rb_ractor_basket_type e;
44
+ rb_atomic_t atomic;
45
+ } type;
46
+ VALUE sender;
47
+
48
+ union {
49
+ struct {
50
+ VALUE v;
51
+ bool exception;
52
+ } send;
53
+
54
+ struct {
55
+ struct rb_ractor_basket *basket;
56
+ struct rb_ractor_selector_take_config *config;
57
+ } take;
58
+ } p; // payload
59
+ };
60
+
61
+ static inline bool
62
+ basket_type_p(struct rb_ractor_basket *b, enum rb_ractor_basket_type type)
63
+ {
64
+ return b->type.e == type;
65
+ }
66
+
67
+ static inline bool
68
+ basket_none_p(struct rb_ractor_basket *b)
69
+ {
70
+ return basket_type_p(b, basket_type_none);
71
+ }
72
+
73
+ struct rb_ractor_queue {
74
+ struct rb_ractor_basket *baskets;
75
+ int start;
76
+ int cnt;
77
+ int size;
78
+ unsigned int serial;
79
+ unsigned int reserved_cnt;
80
+ };
81
+
82
+ enum rb_ractor_wait_status {
83
+ wait_none = 0x00,
84
+ wait_receiving = 0x01,
85
+ wait_taking = 0x02,
86
+ wait_yielding = 0x04,
87
+ wait_moving = 0x08,
88
+ };
89
+
90
+ enum rb_ractor_wakeup_status {
91
+ wakeup_none,
92
+ wakeup_by_send,
93
+ wakeup_by_yield,
94
+ wakeup_by_take,
95
+ wakeup_by_close,
96
+ wakeup_by_interrupt,
97
+ wakeup_by_retry,
98
+ };
99
+
100
+ struct rb_ractor_sync {
101
+ // ractor lock
102
+ rb_nativethread_lock_t lock;
103
+ #if RACTOR_CHECK_MODE > 0
104
+ VALUE locked_by;
105
+ #endif
106
+
107
+ bool incoming_port_closed;
108
+ bool outgoing_port_closed;
109
+
110
+ // All sent messages will be pushed into recv_queue
111
+ struct rb_ractor_queue recv_queue;
112
+
113
+ // The following ractors waiting for the yielding by this ractor
114
+ struct rb_ractor_queue takers_queue;
115
+
116
+ // Enabled if the ractor already terminated and not taken yet.
117
+ struct rb_ractor_basket will_basket;
118
+
119
+ struct ractor_wait {
120
+ enum rb_ractor_wait_status status;
121
+ enum rb_ractor_wakeup_status wakeup_status;
122
+ rb_thread_t *waiting_thread;
123
+ } wait;
124
+
125
+ #ifndef RUBY_THREAD_PTHREAD_H
126
+ rb_nativethread_cond_t cond;
127
+ #endif
128
+ };
129
+
130
+ // created
131
+ // | ready to run
132
+ // ====================== inserted to vm->ractor
133
+ // v
134
+ // blocking <---+ all threads are blocking
135
+ // | |
136
+ // v |
137
+ // running -----+
138
+ // | all threads are terminated.
139
+ // ====================== removed from vm->ractor
140
+ // v
141
+ // terminated
142
+ //
143
+ // status is protected by VM lock (global state)
144
+ enum ractor_status {
145
+ ractor_created,
146
+ ractor_running,
147
+ ractor_blocking,
148
+ ractor_terminated,
149
+ };
150
+
151
+ struct rb_ractor_struct {
152
+ struct rb_ractor_pub pub;
153
+
154
+ struct rb_ractor_sync sync;
155
+ VALUE receiving_mutex;
156
+
157
+ // vm wide barrier synchronization
158
+ rb_nativethread_cond_t barrier_wait_cond;
159
+
160
+ // thread management
161
+ struct {
162
+ struct ccan_list_head set;
163
+ unsigned int cnt;
164
+ unsigned int blocking_cnt;
165
+ unsigned int sleeper;
166
+ struct rb_thread_sched sched;
167
+ rb_execution_context_t *running_ec;
168
+ rb_thread_t *main;
169
+ } threads;
170
+ VALUE thgroup_default;
171
+
172
+ VALUE name;
173
+ VALUE loc;
174
+
175
+ enum ractor_status status_;
176
+
177
+ struct ccan_list_node vmlr_node;
178
+
179
+ // ractor local data
180
+
181
+ st_table *local_storage;
182
+ struct rb_id_table *idkey_local_storage;
183
+ VALUE local_storage_store_lock;
184
+
185
+ VALUE r_stdin;
186
+ VALUE r_stdout;
187
+ VALUE r_stderr;
188
+ VALUE verbose;
189
+ VALUE debug;
190
+
191
+ void *newobj_cache;
192
+ }; // rb_ractor_t is defined in vm_core.h
193
+
194
+
195
+ static inline VALUE
196
+ rb_ractor_self(const rb_ractor_t *r)
197
+ {
198
+ return r->pub.self;
199
+ }
200
+
201
+ rb_ractor_t *rb_ractor_main_alloc(void);
202
+ void rb_ractor_main_setup(rb_vm_t *vm, rb_ractor_t *main_ractor, rb_thread_t *main_thread);
203
+ void rb_ractor_atexit(rb_execution_context_t *ec, VALUE result);
204
+ void rb_ractor_atexit_exception(rb_execution_context_t *ec);
205
+ void rb_ractor_teardown(rb_execution_context_t *ec);
206
+ void rb_ractor_receive_parameters(rb_execution_context_t *ec, rb_ractor_t *g, int len, VALUE *ptr);
207
+ void rb_ractor_send_parameters(rb_execution_context_t *ec, rb_ractor_t *g, VALUE args);
208
+
209
+ VALUE rb_thread_create_ractor(rb_ractor_t *g, VALUE args, VALUE proc); // defined in thread.c
210
+
211
+ int rb_ractor_living_thread_num(const rb_ractor_t *);
212
+ VALUE rb_ractor_thread_list(void);
213
+ bool rb_ractor_p(VALUE rv);
214
+
215
+ void rb_ractor_living_threads_init(rb_ractor_t *r);
216
+ void rb_ractor_living_threads_insert(rb_ractor_t *r, rb_thread_t *th);
217
+ void rb_ractor_living_threads_remove(rb_ractor_t *r, rb_thread_t *th);
218
+ void rb_ractor_blocking_threads_inc(rb_ractor_t *r, const char *file, int line); // TODO: file, line only for RUBY_DEBUG_LOG
219
+ void rb_ractor_blocking_threads_dec(rb_ractor_t *r, const char *file, int line); // TODO: file, line only for RUBY_DEBUG_LOG
220
+
221
+ void rb_ractor_vm_barrier_interrupt_running_thread(rb_ractor_t *r);
222
+ void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r);
223
+ void rb_ractor_terminate_all(void);
224
+ bool rb_ractor_main_p_(void);
225
+ void rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th);
226
+ VALUE rb_ractor_require(VALUE feature);
227
+ VALUE rb_ractor_autoload_load(VALUE space, ID id);
228
+
229
+ VALUE rb_ractor_ensure_shareable(VALUE obj, VALUE name);
230
+
231
+ RUBY_SYMBOL_EXPORT_BEGIN
232
+ void rb_ractor_finish_marking(void);
233
+
234
+ bool rb_ractor_shareable_p_continue(VALUE obj);
235
+
236
+ // THIS FUNCTION SHOULD NOT CALL WHILE INCREMENTAL MARKING!!
237
+ // This function is for T_DATA::free_func
238
+ void rb_ractor_local_storage_delkey(rb_ractor_local_key_t key);
239
+
240
+ RUBY_SYMBOL_EXPORT_END
241
+
242
+ static inline bool
243
+ rb_ractor_main_p(void)
244
+ {
245
+ if (ruby_single_main_ractor) {
246
+ return true;
247
+ }
248
+ else {
249
+ return rb_ractor_main_p_();
250
+ }
251
+ }
252
+
253
+ static inline bool
254
+ rb_ractor_status_p(rb_ractor_t *r, enum ractor_status status)
255
+ {
256
+ return r->status_ == status;
257
+ }
258
+
259
+ static inline void
260
+ rb_ractor_sleeper_threads_inc(rb_ractor_t *r)
261
+ {
262
+ r->threads.sleeper++;
263
+ }
264
+
265
+ static inline void
266
+ rb_ractor_sleeper_threads_dec(rb_ractor_t *r)
267
+ {
268
+ r->threads.sleeper--;
269
+ }
270
+
271
+ static inline void
272
+ rb_ractor_sleeper_threads_clear(rb_ractor_t *r)
273
+ {
274
+ r->threads.sleeper = 0;
275
+ }
276
+
277
+ static inline int
278
+ rb_ractor_sleeper_thread_num(rb_ractor_t *r)
279
+ {
280
+ return r->threads.sleeper;
281
+ }
282
+
283
+ static inline void
284
+ rb_ractor_thread_switch(rb_ractor_t *cr, rb_thread_t *th)
285
+ {
286
+ RUBY_DEBUG_LOG("th:%d->%u%s",
287
+ cr->threads.running_ec ? (int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
288
+ rb_th_serial(th), cr->threads.running_ec == th->ec ? " (same)" : "");
289
+
290
+ if (cr->threads.running_ec != th->ec) {
291
+ if (0) {
292
+ ruby_debug_printf("rb_ractor_thread_switch ec:%p->%p\n",
293
+ (void *)cr->threads.running_ec, (void *)th->ec);
294
+ }
295
+ }
296
+ else {
297
+ return;
298
+ }
299
+
300
+ if (cr->threads.running_ec != th->ec) {
301
+ th->running_time_us = 0;
302
+ }
303
+
304
+ cr->threads.running_ec = th->ec;
305
+
306
+ VM_ASSERT(cr == GET_RACTOR());
307
+ }
308
+
309
+ #define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
310
+ #ifdef RB_THREAD_LOCAL_SPECIFIER
311
+ void rb_current_ec_set(rb_execution_context_t *ec);
312
+ #endif
313
+
314
+ static inline void
315
+ rb_ractor_set_current_ec_(rb_ractor_t *cr, rb_execution_context_t *ec, const char *file, int line)
316
+ {
317
+ #ifdef RB_THREAD_LOCAL_SPECIFIER
318
+ rb_current_ec_set(ec);
319
+ #else
320
+ native_tls_set(ruby_current_ec_key, ec);
321
+ #endif
322
+ RUBY_DEBUG_LOG2(file, line, "ec:%p->%p", (void *)cr->threads.running_ec, (void *)ec);
323
+ VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
324
+ cr->threads.running_ec = ec;
325
+ }
326
+
327
+ void rb_vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line);
328
+ void rb_vm_ractor_blocking_cnt_dec(rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line);
329
+
330
+ static inline uint32_t
331
+ rb_ractor_id(const rb_ractor_t *r)
332
+ {
333
+ return r->pub.id;
334
+ }
335
+
336
+ #if RACTOR_CHECK_MODE > 0
337
+ # define RACTOR_BELONGING_ID(obj) (*(uint32_t *)(((uintptr_t)(obj)) + rb_gc_obj_slot_size(obj)))
338
+
339
+ uint32_t rb_ractor_current_id(void);
340
+
341
+ static inline void
342
+ rb_ractor_setup_belonging_to(VALUE obj, uint32_t rid)
343
+ {
344
+ RACTOR_BELONGING_ID(obj) = rid;
345
+ }
346
+
347
+ static inline uint32_t
348
+ rb_ractor_belonging(VALUE obj)
349
+ {
350
+ if (SPECIAL_CONST_P(obj) || RB_OBJ_SHAREABLE_P(obj)) {
351
+ return 0;
352
+ }
353
+ else {
354
+ return RACTOR_BELONGING_ID(obj);
355
+ }
356
+ }
357
+
358
+ static inline VALUE
359
+ rb_ractor_confirm_belonging(VALUE obj)
360
+ {
361
+ uint32_t id = rb_ractor_belonging(obj);
362
+
363
+ if (id == 0) {
364
+ if (UNLIKELY(!rb_ractor_shareable_p(obj))) {
365
+ rp(obj);
366
+ rb_bug("id == 0 but not shareable");
367
+ }
368
+ }
369
+ else if (UNLIKELY(id != rb_ractor_current_id())) {
370
+ if (rb_ractor_shareable_p(obj)) {
371
+ // ok
372
+ }
373
+ else {
374
+ rp(obj);
375
+ rb_bug("rb_ractor_confirm_belonging object-ractor id:%u, current-ractor id:%u", id, rb_ractor_current_id());
376
+ }
377
+ }
378
+ return obj;
379
+ }
380
+ #else
381
+ #define rb_ractor_confirm_belonging(obj) obj
382
+ #endif
@@ -0,0 +1,14 @@
1
+ #ifndef RUBY_TOPLEVEL_ASSERT_H /*-*-C-*-vi:se ft=c:*/
2
+ #define RUBY_TOPLEVEL_ASSERT_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
+ */
10
+ #include "ruby/assert.h"
11
+ #undef assert
12
+ #define assert RUBY_ASSERT_NDEBUG
13
+
14
+ #endif /* RUBY_TOPLEVEL_ASSERT_H */
@@ -0,0 +1,23 @@
1
+ #include "ruby/atomic.h"
2
+
3
+ /* shim macros only */
4
+ #define ATOMIC_ADD(var, val) RUBY_ATOMIC_ADD(var, val)
5
+ #define ATOMIC_CAS(var, oldval, newval) RUBY_ATOMIC_CAS(var, oldval, newval)
6
+ #define ATOMIC_DEC(var) RUBY_ATOMIC_DEC(var)
7
+ #define ATOMIC_EXCHANGE(var, val) RUBY_ATOMIC_EXCHANGE(var, val)
8
+ #define ATOMIC_FETCH_ADD(var, val) RUBY_ATOMIC_FETCH_ADD(var, val)
9
+ #define ATOMIC_FETCH_SUB(var, val) RUBY_ATOMIC_FETCH_SUB(var, val)
10
+ #define ATOMIC_INC(var) RUBY_ATOMIC_INC(var)
11
+ #define ATOMIC_OR(var, val) RUBY_ATOMIC_OR(var, val)
12
+ #define ATOMIC_PTR_CAS(var, oldval, newval) RUBY_ATOMIC_PTR_CAS(var, oldval, newval)
13
+ #define ATOMIC_PTR_EXCHANGE(var, val) RUBY_ATOMIC_PTR_EXCHANGE(var, val)
14
+ #define ATOMIC_SET(var, val) RUBY_ATOMIC_SET(var, val)
15
+ #define ATOMIC_SIZE_ADD(var, val) RUBY_ATOMIC_SIZE_ADD(var, val)
16
+ #define ATOMIC_SIZE_CAS(var, oldval, newval) RUBY_ATOMIC_SIZE_CAS(var, oldval, newval)
17
+ #define ATOMIC_SIZE_DEC(var) RUBY_ATOMIC_SIZE_DEC(var)
18
+ #define ATOMIC_SIZE_EXCHANGE(var, val) RUBY_ATOMIC_SIZE_EXCHANGE(var, val)
19
+ #define ATOMIC_SIZE_INC(var) RUBY_ATOMIC_SIZE_INC(var)
20
+ #define ATOMIC_SIZE_SUB(var, val) RUBY_ATOMIC_SIZE_SUB(var, val)
21
+ #define ATOMIC_SUB(var, val) RUBY_ATOMIC_SUB(var, val)
22
+ #define ATOMIC_VALUE_CAS(var, oldval, val) RUBY_ATOMIC_VALUE_CAS(var, oldval, val)
23
+ #define ATOMIC_VALUE_EXCHANGE(var, val) RUBY_ATOMIC_VALUE_EXCHANGE(var, val)