Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
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 
22 
29  void (*mark)(void *ptr);
30 
37  void (*free)(void *ptr);
38  // TODO: update
39 };
40 
43 
45 
46 
52 
61 
70 
79 
89 void rb_ractor_stdin_set(VALUE io);
90 
100 void rb_ractor_stdout_set(VALUE io);
101 
111 void rb_ractor_stderr_set(VALUE io);
112 
120 
131 
143 
152 
162 
164 #define RB_RACTOR_LOCAL_STORAGE_TYPE_FREE (&rb_ractor_local_storage_type_free)
165 
175 
184 
193 
213 
223 
225 
226 
235 #define RB_OBJ_SHAREABLE_P(obj) FL_TEST_RAW((obj), RUBY_FL_SHAREABLE)
236 
248 static inline bool
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 */
Tweaking visibility of C variables/functions.
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition: dllexport.h:45
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
Defines enum ruby_fl_type.
VALUE rb_cRactor
Ractor class.
Definition: ractor.c:23
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
Definition: io.h:2
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:3714
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:3087
struct rb_ractor_local_key_struct * rb_ractor_local_key_t
(Opaque) struct that holds a ractor-local storage key.
Definition: ractor.h:42
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:3835
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:3725
VALUE rb_ractor_stderr(void)
Queries the standard error of the current Ractor that is calling this function.
Definition: ractor.c:2724
VALUE rb_ractor_stdin(void)
Queries the standard input of the current Ractor that is calling this function.
Definition: ractor.c:2700
static bool rb_ractor_shareable_p(VALUE obj)
Queries if multiple Ractors can share the passed object or not.
Definition: ractor.h:249
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:2760
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:3817
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:3823
bool rb_ractor_local_storage_value_lookup(rb_ractor_local_key_t key, VALUE *val)
Queries the key.
Definition: ractor.c:3806
VALUE rb_ractor_stdout(void)
Queries the standard output of the current Ractor that is calling this function.
Definition: ractor.c:2712
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
Definition: ractor.h:235
VALUE rb_ractor_make_shareable(VALUE obj)
Destructively transforms the passed object so that multiple Ractors can share it.
Definition: ractor.c:3078
rb_ractor_local_key_t rb_ractor_local_storage_value_newkey(void)
Issues a new key.
Definition: ractor.c:3734
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:2748
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:2736
VALUE rb_ractor_local_storage_value(rb_ractor_local_key_t key)
Queries the key.
Definition: ractor.c:3794
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
Defines enum ruby_special_consts.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
C99 shim for <stdbool.h>
Type that defines a ractor-local storage.
Definition: ractor.h:21
void(* free)(void *ptr)
A function to destruct a ractor-local storage.
Definition: ractor.h:37
void(* mark)(void *ptr)
A function to mark a ractor-local storage.
Definition: ractor.h:29
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40