|
Ruby 4.1.0dev (2026-09-14 revision d568c610946b44722ffb51ab7b36edc2e779d306)
|
#include "internal/dllexport.h"#include "internal/fl_type.h"#include "internal/special_consts.h"#include "internal/stdbool.h"#include "internal/value.h"

Go to the source code of this file.
Data Structures | |
| struct | rb_ractor_local_storage_type |
| Type that defines a ractor-local storage. More... | |
Macros | |
| #define | RB_RACTOR_LOCAL_STORAGE_TYPE_FREE (&rb_ractor_local_storage_type_free) |
| Just another name of rb_ractor_local_storage_type_free. | |
| #define | RB_OBJ_SHAREABLE_P(obj) FL_TEST_RAW((obj), RUBY_FL_SHAREABLE) |
| Queries if the passed object has previously classified as shareable or not. | |
| #define | RB_OBJ_SET_SHAREABLE(obj) rb_obj_set_shareable(obj) |
| Wrapper of rb_obj_set_shareable(). | |
Typedefs | |
| typedef struct rb_ractor_local_key_struct * | rb_ractor_local_key_t |
| (Opaque) struct that holds a ractor-local storage key. | |
Functions | |
| VALUE | rb_ractor_stdin (void) |
| Queries the standard input of the current Ractor that is calling this function. | |
| VALUE | rb_ractor_stdout (void) |
| Queries the standard output of the current Ractor that is calling this function. | |
| VALUE | rb_ractor_stderr (void) |
| Queries the standard error of the current Ractor that is calling this function. | |
| void | rb_ractor_stdin_set (VALUE io) |
| Assigns an IO to the standard input of the Ractor that is calling this function. | |
| void | rb_ractor_stdout_set (VALUE io) |
| Assigns an IO to the standard output of the Ractor that is calling this function. | |
| void | rb_ractor_stderr_set (VALUE io) |
| Assigns an IO to the standard error of the Ractor that is calling this function. | |
| rb_ractor_local_key_t | rb_ractor_local_storage_value_newkey (void) |
| Issues a new key. | |
| VALUE | rb_ractor_local_storage_value (rb_ractor_local_key_t key) |
| Queries the key. | |
| bool | rb_ractor_local_storage_value_lookup (rb_ractor_local_key_t key, VALUE *val) |
| Queries the key. | |
| void | rb_ractor_local_storage_value_set (rb_ractor_local_key_t key, VALUE val) |
| Associates the passed value to the passed key. | |
| 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(). | |
| void * | rb_ractor_local_storage_ptr (rb_ractor_local_key_t key) |
| Identical to rb_ractor_local_storage_value() except the return type. | |
| 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. | |
| VALUE | rb_ractor_make_shareable (VALUE obj) |
| Destructively transforms the passed object so that multiple Ractors can share it. | |
| 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 modifying it in-place. | |
| VALUE | rb_obj_set_shareable (VALUE obj) |
| Marks the passed object as shareable, without any check. | |
| static bool | rb_ractor_shareable_p (VALUE obj) |
| Queries if multiple Ractors can share the passed object or not. | |
| static VALUE | RB_OBJ_SET_FROZEN_SHAREABLE (VALUE obj) |
| Freezes and marks the object as shareable. | |
Variables | |
| VALUE | rb_cRactor |
Ractor class. | |
| 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 in file ractor.h.
| #define RB_OBJ_SET_SHAREABLE | ( | obj | ) | rb_obj_set_shareable(obj) |
Wrapper of rb_obj_set_shareable().
Use this macro, not the function.
| #define RB_OBJ_SHAREABLE_P | ( | obj | ) | FL_TEST_RAW((obj), RUBY_FL_SHAREABLE) |
Queries if the passed object has previously classified as shareable or not.
This doesn't mean anything in practice... Objects can be shared later. Always use rb_ractor_shareable_p() instead.
| [in] | obj | Object in question. |
| RUBY_FL_SHAREABLE | It once was shareable before. |
| 0 | Otherwise. |
| #define RB_RACTOR_LOCAL_STORAGE_TYPE_FREE (&rb_ractor_local_storage_type_free) |
Just another name of rb_ractor_local_storage_type_free.
| typedef struct rb_ractor_local_key_struct* rb_ractor_local_key_t |
Freezes and marks the object as shareable.
The same warning and note as rb_obj_set_shareable() apply.
| [out] | obj | Arbitrary ruby object, except special constants. |
obj. Marks the passed object as shareable, without any check.
This is for objects which the caller knows are safe to be shared among Ractors, for instance because they are frozen and only refer to shareable objects.
| [out] | obj | Arbitrary ruby object, except special constants. |
obj. obj. | void * rb_ractor_local_storage_ptr | ( | rb_ractor_local_key_t | key | ) |
Identical to rb_ractor_local_storage_value() except the return type.
| [in] | key | A ractor-local storage key to lookup. |
| NULL | No such key. |
| otherwise | A value corresponds to key in the current Ractor. |
| 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().
It additionally takes the type of the issuing key.
| [in] | type | How the value associated with the issuing key should behave. |
type. Definition at line 3582 of file ractor.c.
Referenced by rb_ractor_local_storage_value_newkey().
| 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.
| [in] | key | A ractor-local storage key. |
| [in] | ptr | A pointer that conforms key's type. |
ptr corresponds to key in the current Ractor. | VALUE rb_ractor_local_storage_value | ( | rb_ractor_local_key_t | key | ) |
Queries the key.
| [in] | key | A ractor-local storage key to lookup. |
| RUBY_Qnil | No such key. |
| otherwise | A value corresponds to key in the current Ractor. |
| bool rb_ractor_local_storage_value_lookup | ( | rb_ractor_local_key_t | key, |
| VALUE * | val | ||
| ) |
| rb_ractor_local_key_t rb_ractor_local_storage_value_newkey | ( | void | ) |
| void rb_ractor_local_storage_value_set | ( | rb_ractor_local_key_t | key, |
| VALUE | val | ||
| ) |
Destructively transforms the passed object so that multiple Ractors can share it.
What is a shareable object and what is not is a nuanced concept, and @ko1 says the definition can still change. However extension library authors might interest to learn how to use RUBY_TYPED_FROZEN_SHAREABLE.
| [out] | obj | Arbitrary ruby object to modify. |
| rb_eRactorError | Ractors cannot share `obj` by nature. |
obj. obj. Definition at line 1911 of file ractor.c.
Referenced by rb_ractor_make_shareable(), and rb_ractor_make_shareable_copy().
Identical to rb_ractor_make_shareable(), except it returns a (deep) copy of the passed one instead of modifying it in-place.
| [in] | obj | Arbitrary ruby object to duplicate. |
| rb_eRactorError | Ractors cannot share `obj` by nature. |
obj which is shareable among Ractors. Definition at line 1922 of file ractor.c.
Referenced by rb_ractor_make_shareable_copy().
|
inlinestatic |
Queries if multiple Ractors can share the passed object or not.
Ractors run without protecting each other. Sharing an object among them is basically dangerous, disabled by default. However there are objects that are extremely carefully implemented to be Ractor-safe; for instance integers have such property. This function can classify that.
| [in] | obj | Arbitrary ruby object. |
| true | obj is capable of shared across ractors. |
| false | obj cannot travel across ractor boundaries. |
Definition at line 269 of file ractor.h.
Referenced by make_singleton_class().
| VALUE rb_ractor_stderr | ( | void | ) |
| void rb_ractor_stderr_set | ( | VALUE | io | ) |
Assigns an IO to the standard error of the Ractor that is calling this function.
| [in] | io | An IO. |
io is the standard input of the current ractor. | VALUE rb_ractor_stdin | ( | void | ) |
| void rb_ractor_stdin_set | ( | VALUE | io | ) |
| VALUE rb_ractor_stdout | ( | void | ) |
| void rb_ractor_stdout_set | ( | VALUE | io | ) |
Assigns an IO to the standard output of the Ractor that is calling this function.
| [in] | io | An IO. |
io is the standard input of the current ractor.
|
extern |