Ruby: include/ruby/ractor.h Source File

Ruby 3.3.7p123 (2025-01-15 revision be31f993d7fa0219d85f7b3c694d454da4ecc10b)

ractor.h
Go to the documentation of this file.
1#ifndef RUBY_RACTOR_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_RACTOR_H 1
3
14#include "internal/dllexport.h" /* RUBY_EXTERN is here */
15#include "internal/fl_type.h" /* FL_TEST_RAW is here */
16#include "internal/special_consts.h" /* RB_SPECIAL_CONSTS_P is here */
17#include "internal/stdbool.h" /* bool is here */
18#include "internal/value.h" /* VALUE is here */
19
21 struct rb_ractor_local_storage_type {
22
29 void (*mark)(void *ptr);
30
37 void (*free)(void *ptr);
38 // TODO: update
39};
40
42 typedef struct rb_ractor_local_key_struct *rb_ractor_local_key_t;
43
44 RBIMPL_SYMBOL_EXPORT_BEGIN()
45
46
51 RUBY_EXTERN VALUE rb_cRactor;
52
60 VALUE rb_ractor_stdin(void);
61
69 VALUE rb_ractor_stdout(void);
70
78 VALUE rb_ractor_stderr(void);
79
89void rb_ractor_stdin_set(VALUE io);
90
100void rb_ractor_stdout_set(VALUE io);
101
111void rb_ractor_stderr_set(VALUE io);
112
119 rb_ractor_local_key_t rb_ractor_local_storage_value_newkey(void);
120
130 VALUE rb_ractor_local_storage_value(rb_ractor_local_key_t key);
131
142bool rb_ractor_local_storage_value_lookup(rb_ractor_local_key_t key, VALUE *val);
143
151void rb_ractor_local_storage_value_set(rb_ractor_local_key_t key, VALUE val);
152
161 RUBY_EXTERN const struct rb_ractor_local_storage_type rb_ractor_local_storage_type_free;
162
164#define RB_RACTOR_LOCAL_STORAGE_TYPE_FREE (&rb_ractor_local_storage_type_free)
165
174 rb_ractor_local_key_t rb_ractor_local_storage_ptr_newkey(const struct rb_ractor_local_storage_type *type);
175
183void *rb_ractor_local_storage_ptr(rb_ractor_local_key_t key);
184
192void rb_ractor_local_storage_ptr_set(rb_ractor_local_key_t key, void *ptr);
193
212 VALUE rb_ractor_make_shareable(VALUE obj);
213
222 VALUE rb_ractor_make_shareable_copy(VALUE obj);
223
224 RBIMPL_SYMBOL_EXPORT_END()
225
226
235#define RB_OBJ_SHAREABLE_P(obj) FL_TEST_RAW((obj), RUBY_FL_SHAREABLE)
236
248static inline bool
249rb_ractor_shareable_p(VALUE obj)
250{
251 bool rb_ractor_shareable_p_continue(VALUE obj);
252
253 if (RB_SPECIAL_CONST_P(obj)) {
254 return true;
255 }
256 else if (RB_OBJ_SHAREABLE_P(obj)) {
257 return true;
258 }
259 else {
260 return rb_ractor_shareable_p_continue(obj);
261 }
262}
263
264#endif /* RUBY_RACTOR_H */
dllexport.h
Tweaking visibility of C variables/functions.
RUBY_EXTERN
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition dllexport.h:45
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
fl_type.h
Defines enum ruby_fl_type.
rb_cRactor
VALUE rb_cRactor
Ractor class.
Definition ractor.c:22
rb_ractor_local_storage_type_free
const struct rb_ractor_local_storage_type rb_ractor_local_storage_type_free
A type of ractor-local storage that destructs itself using ruby_xfree.
Definition ractor.c:3677
rb_ractor_make_shareable_copy
VALUE rb_ractor_make_shareable_copy(VALUE obj)
Identical to rb_ractor_make_shareable(), except it returns a (deep) copy of the passed one instead of...
Definition ractor.c:3058
rb_ractor_local_key_t
struct rb_ractor_local_key_struct * rb_ractor_local_key_t
(Opaque) struct that holds a ractor-local storage key.
Definition ractor.h:42
rb_ractor_local_storage_ptr
void * rb_ractor_local_storage_ptr(rb_ractor_local_key_t key)
Identical to rb_ractor_local_storage_value() except the return type.
Definition ractor.c:3786
rb_ractor_local_storage_ptr_set
void rb_ractor_local_storage_ptr_set(rb_ractor_local_key_t key, void *ptr)
Identical to rb_ractor_local_storage_value_set() except the parameter type.
Definition ractor.c:3798
rb_ractor_local_storage_ptr_newkey
rb_ractor_local_key_t rb_ractor_local_storage_ptr_newkey(const struct rb_ractor_local_storage_type *type)
Extended version of rb_ractor_local_storage_value_newkey().
Definition ractor.c:3688
rb_ractor_stdin
VALUE rb_ractor_stdin(void)
Queries the standard input of the current Ractor that is calling this function.
Definition ractor.c:2671
rb_ractor_shareable_p
static bool rb_ractor_shareable_p(VALUE obj)
Queries if multiple Ractors can share the passed object or not.
Definition ractor.h:249
rb_ractor_stderr_set
void rb_ractor_stderr_set(VALUE io)
Assigns an IO to the standard error of the Ractor that is calling this function.
Definition ractor.c:2731
rb_ractor_local_storage_value_set
void rb_ractor_local_storage_value_set(rb_ractor_local_key_t key, VALUE val)
Associates the passed value to the passed key.
Definition ractor.c:3780
rb_ractor_local_storage_value_lookup
bool rb_ractor_local_storage_value_lookup(rb_ractor_local_key_t key, VALUE *val)
Queries the key.
Definition ractor.c:3769
RB_OBJ_SHAREABLE_P
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
Definition ractor.h:235
rb_ractor_local_storage_value_newkey
rb_ractor_local_key_t rb_ractor_local_storage_value_newkey(void)
Issues a new key.
Definition ractor.c:3697
rb_ractor_stdout_set
void rb_ractor_stdout_set(VALUE io)
Assigns an IO to the standard output of the Ractor that is calling this function.
Definition ractor.c:2719
rb_ractor_stdin_set
void rb_ractor_stdin_set(VALUE io)
Assigns an IO to the standard input of the Ractor that is calling this function.
Definition ractor.c:2707
rb_ractor_local_storage_value
VALUE rb_ractor_local_storage_value(rb_ractor_local_key_t key)
Queries the key.
Definition ractor.c:3757
special_consts.h
Defines enum ruby_special_consts.
RB_SPECIAL_CONST_P
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
Definition special_consts.h:327
stdbool.h
C99 shim for <stdbool.h>
rb_ractor_local_key_struct
Definition ractor.c:3598
rb_ractor_local_storage_type
Type that defines a ractor-local storage.
Definition ractor.h:21
rb_ractor_local_storage_type::free
void(* free)(void *ptr)
A function to destruct a ractor-local storage.
Definition ractor.h:37
rb_ractor_local_storage_type::mark
void(* mark)(void *ptr)
A function to mark a ractor-local storage.
Definition ractor.h:29
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40