Ruby: ractor_core.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Enumerations | Functions
ractor_core.h File Reference
`#include "ruby/ruby.h"`
`#include "ruby/ractor.h"`
`#include "vm_core.h"`
`#include "id_table.h"`
`#include "vm_debug.h"`

Go to the source code of this file.

## Data Structures
struct | rb_ractor_basket
struct | rb_ractor_queue
struct | rb_ractor_waiting_list
struct | rb_ractor_sync
struct | rb_ractor_sync::ractor_wait
struct | rb_ractor_struct
struct | rb_ractor_struct::gc_mark_func_data_struct

## Macros
#define | RACTOR_CHECK_MODE (0 || VM_CHECK_MODE || RUBY_DEBUG)
#define | rb_ractor_confirm_belonging(obj) obj

## Enumerations
enum | rb_ractor_basket_type { basket_type_none , basket_type_ref , basket_type_copy , basket_type_move , basket_type_will , basket_type_deleted , basket_type_reserved }

## Functions
rb_ractor_t * | rb_ractor_main_alloc (void)
void | rb_ractor_main_setup (rb_vm_t *vm, rb_ractor_t *main_ractor, rb_thread_t *main_thread)
void | rb_ractor_atexit (rb_execution_context_t *ec, VALUE result)
void | rb_ractor_atexit_exception (rb_execution_context_t *ec)
void | rb_ractor_teardown (rb_execution_context_t *ec)
void | rb_ractor_receive_parameters (rb_execution_context_t *ec, rb_ractor_t *g, int len, VALUE *ptr)
void | rb_ractor_send_parameters (rb_execution_context_t *ec, rb_ractor_t *g, VALUE args)
VALUE | rb_thread_create_ractor (rb_ractor_t *g, VALUE args, VALUE proc)
rb_global_vm_lock_t * | rb_ractor_gvl (rb_ractor_t *)
int | rb_ractor_living_thread_num (const rb_ractor_t *)
VALUE | rb_ractor_thread_list (rb_ractor_t *r)
void | rb_ractor_living_threads_init (rb_ractor_t *r)
void | rb_ractor_living_threads_insert (rb_ractor_t *r, rb_thread_t *th)
void | rb_ractor_living_threads_remove (rb_ractor_t *r, rb_thread_t *th)
void | rb_ractor_blocking_threads_inc (rb_ractor_t *r, const char *file, int line)
void | rb_ractor_blocking_threads_dec (rb_ractor_t *r, const char *file, int line)
void | rb_ractor_vm_barrier_interrupt_running_thread (rb_ractor_t *r)
void | rb_ractor_terminate_interrupt_main_thread (rb_ractor_t *r)
void | rb_ractor_terminate_all (void)
bool | rb_ractor_main_p_ (void)
void | rb_ractor_finish_marking (void)
void | rb_ractor_atfork (rb_vm_t *vm, rb_thread_t *th)
VALUE | rb_ractor_ensure_shareable (VALUE obj, VALUE name)
bool | rb_ractor_shareable_p_continue (VALUE obj)
void | rb_ractor_local_storage_delkey (rb_ractor_local_key_t key)
void | rb_vm_ractor_blocking_cnt_inc (rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line)
void | rb_vm_ractor_blocking_cnt_dec (rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line)

## Macro Definition Documentation

## ◆ RACTOR_CHECK_MODE

#define RACTOR_CHECK_MODE (0 || VM_CHECK_MODE || RUBY_DEBUG)

Definition at line 8 of file ractor_core.h.

## ◆ rb_ractor_confirm_belonging

#define rb_ractor_confirm_belonging | ( |  | obj | ) | obj

Definition at line 340 of file ractor_core.h.

## Enumeration Type Documentation

## ◆ rb_ractor_basket_type

enum rb_ractor_basket_type

Enumerator
basket_type_none |
basket_type_ref |
basket_type_copy |
basket_type_move |
basket_type_will |
basket_type_deleted |
basket_type_reserved |

Definition at line 11 of file ractor_core.h.

## Function Documentation

## ◆ rb_ractor_atexit()

void rb_ractor_atexit | ( | rb_execution_context_t * | ec,
|  | VALUE | result
| ) |  |

Definition at line 1668 of file ractor.c.

## ◆ rb_ractor_atexit_exception()

void rb_ractor_atexit_exception | ( | rb_execution_context_t * | ec | ) |

Definition at line 1675 of file ractor.c.

References rb_execution_context_struct::errinfo.

## ◆ rb_ractor_atfork()

void rb_ractor_atfork | ( | rb_vm_t * | vm,
|  | rb_thread_t * | th
| ) |  |

## ◆ rb_ractor_blocking_threads_dec()

void rb_ractor_blocking_threads_dec | ( | rb_ractor_t * | r,
|  | const char * | file,
|  | int | line
| ) |  |

Definition at line 1870 of file ractor.c.

References rb_ractor_struct::blocking_cnt, rb_ractor_struct::cnt, RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, rb_vm_ractor_blocking_cnt_dec(), RUBY_DEBUG_LOG2, rb_ractor_struct::threads, and VM_ASSERT.

## ◆ rb_ractor_blocking_threads_inc()

void rb_ractor_blocking_threads_inc | ( | rb_ractor_t * | r,
|  | const char * | file,
|  | int | line
| ) |  |

Definition at line 1858 of file ractor.c.

References rb_ractor_struct::blocking_cnt, rb_ractor_struct::cnt, RUBY_DEBUG_LOG2, rb_ractor_struct::threads, and VM_ASSERT.

## ◆ rb_ractor_ensure_shareable()

VALUE rb_ractor_ensure_shareable | ( | VALUE | obj,
|  | VALUE | name
| ) |  |

Definition at line 2518 of file ractor.c.

References name, PRIsVALUE, rb_eRactorIsolationError, rb_exc_new_str(), rb_exc_raise(), and rb_sprintf().

## ◆ rb_ractor_finish_marking()

void rb_ractor_finish_marking | ( | void |  | ) |

Definition at line 3215 of file ractor.c.

References DEFAULT_KEYS_CAPA, REALLOC_N, and ruby_xfree().

## ◆ rb_ractor_gvl()

rb_global_vm_lock_t * rb_ractor_gvl | ( | rb_ractor_t * | r | ) |

Definition at line 1715 of file ractor.c.

References rb_ractor_struct::gvl, and rb_ractor_struct::threads.

Referenced by Init_Thread().

## ◆ rb_ractor_living_thread_num()

int rb_ractor_living_thread_num | ( | const rb_ractor_t * | r | ) |

Definition at line 1721 of file ractor.c.

References rb_ractor_struct::cnt, and rb_ractor_struct::threads.

Referenced by rb_nogvl(), rb_thread_alone(), and rb_thread_terminate_all().

## ◆ rb_ractor_living_threads_init()

void rb_ractor_living_threads_init | ( | rb_ractor_t * | r | ) |

Definition at line 1546 of file ractor.c.

References rb_ractor_struct::blocking_cnt, rb_ractor_struct::cnt, rb_ractor_struct::set, and rb_ractor_struct::threads.

## ◆ rb_ractor_living_threads_insert()

void rb_ractor_living_threads_insert | ( | rb_ractor_t * | r,
|  | rb_thread_t * | th
| ) |  |

Definition at line 1760 of file ractor.c.

References rb_ractor_struct::cnt, rb_ractor_pub::id, rb_thread_struct::lt_node, NULL, rb_ractor_struct::pub, RACTOR_LOCK, RACTOR_UNLOCK, RUBY_DEBUG_LOG, rb_ractor_struct::set, rb_ractor_struct::threads, rb_thread_struct::vm, and VM_ASSERT.

Referenced by rb_ractor_main_setup().

## ◆ rb_ractor_living_threads_remove()

void rb_ractor_living_threads_remove | ( | rb_ractor_t * | r,
|  | rb_thread_t * | th
| ) |  |

Definition at line 1838 of file ractor.c.

References rb_ractor_struct::cnt, rb_thread_struct::lt_node, RACTOR_LOCK, RACTOR_UNLOCK, RUBY_DEBUG_LOG, rb_ractor_struct::threads, rb_thread_struct::vm, and VM_ASSERT.

## ◆ rb_ractor_local_storage_delkey()

void rb_ractor_local_storage_delkey | ( | rb_ractor_local_key_t | key | ) |

Definition at line 3112 of file ractor.c.

References key, RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, and REALLOC_N.

## ◆ rb_ractor_main_alloc()

rb_ractor_t * rb_ractor_main_alloc | ( | void |  | ) |

Definition at line 1508 of file ractor.c.

References EXIT_FAILURE, rb_ractor_pub::id, rb_ractor_struct::loc, MEMZERO, rb_ractor_struct::name, NULL, rb_ractor_struct::pub, Qnil, ruby_mimmalloc(), ruby_single_main_ractor, and rb_ractor_pub::self.

Referenced by Init_BareVM().

## ◆ rb_ractor_main_p_()

bool rb_ractor_main_p_ | ( | void |  | ) |

Definition at line 1699 of file ractor.c.

References VM_ASSERT.

## ◆ rb_ractor_main_setup()

void rb_ractor_main_setup | ( | rb_vm_t * | vm,
|  | rb_ractor_t * | main_ractor,
|  | rb_thread_t * | main_thread
| ) |  |

Definition at line 1581 of file ractor.c.

References FL_SET_RAW, rb_ractor_struct::main, rb_ractor_struct::pub, Qnil, rb_cRactor, rb_ractor_living_threads_insert(), RUBY_FL_SHAREABLE, rb_ractor_pub::self, rb_ractor_struct::threads, and TypedData_Wrap_Struct.

Referenced by Init_VM().

## ◆ rb_ractor_receive_parameters()

void rb_ractor_receive_parameters | ( | rb_execution_context_t * | ec,
|  | rb_ractor_t * | g,
|  | int | len,
|  | VALUE * | ptr
| ) |  |

Definition at line 1682 of file ractor.c.

References len, and ptr.

## ◆ rb_ractor_send_parameters()

void rb_ractor_send_parameters | ( | rb_execution_context_t * | ec,
|  | rb_ractor_t * | g,
|  | VALUE | args
| ) |  |

Definition at line 1690 of file ractor.c.

References len, and RARRAY_AREF.

## ◆ rb_ractor_shareable_p_continue()

bool rb_ractor_shareable_p_continue | ( | VALUE | obj | ) |

Definition at line 2550 of file ractor.c.

## ◆ rb_ractor_teardown()

void rb_ractor_teardown | ( | rb_execution_context_t * | ec | ) |

Definition at line 1652 of file ractor.c.

References rb_ractor_struct::main, NULL, RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, rb_ractor_struct::threads, and VM_ASSERT.

## ◆ rb_ractor_terminate_all()

void rb_ractor_terminate_all | ( | void |  | ) |

Definition at line 1946 of file ractor.c.

References rb_vm_struct::cnt, rb_vm_struct::main_ractor, rb_vm_struct::ractor, rb_thread_terminate_all(), rb_vm_cond_timedwait(), RB_VM_LOCK, rb_vm_ractor_blocking_cnt_dec(), rb_vm_ractor_blocking_cnt_inc(), RB_VM_UNLOCK, RUBY_DEBUG_LOG, rb_vm_struct::sync, rb_vm_struct::terminate_cond, rb_vm_struct::terminate_waiting, and VM_ASSERT.

## ◆ rb_ractor_terminate_interrupt_main_thread()

void rb_ractor_terminate_interrupt_main_thread | ( | rb_ractor_t * | r | ) |

Definition at line 1911 of file ractor.c.

References ASSERT_vm_locking, rb_thread_struct::ec, rb_ractor_struct::main, rb_threadptr_interrupt(), RUBY_DEBUG_LOG, RUBY_VM_SET_TERMINATE_INTERRUPT, THREAD_KILLED, rb_ractor_struct::threads, and VM_ASSERT.

## ◆ rb_ractor_thread_list()

VALUE rb_ractor_thread_list | ( | rb_ractor_t * | r | ) |

Definition at line 1727 of file ractor.c.

References ALLOCA_N, rb_ractor_struct::cnt, RACTOR_LOCK, RACTOR_UNLOCK, rb_ary_new(), rb_ary_push(), rb_thread_struct::self, rb_ractor_struct::set, THREAD_RUNNABLE, THREAD_STOPPED, THREAD_STOPPED_FOREVER, and rb_ractor_struct::threads.

Referenced by rb_thread_list().

## ◆ rb_ractor_vm_barrier_interrupt_running_thread()

void rb_ractor_vm_barrier_interrupt_running_thread | ( | rb_ractor_t * | r | ) |

Definition at line 1892 of file ractor.c.

References ASSERT_vm_locking, RACTOR_LOCK, RACTOR_UNLOCK, RUBY_VM_SET_VM_BARRIER_INTERRUPT, rb_ractor_struct::running_ec, rb_ractor_struct::threads, and VM_ASSERT.

Referenced by rb_vm_barrier().

## ◆ rb_thread_create_ractor()

VALUE rb_thread_create_ractor | ( | rb_ractor_t * | g,
|  | VALUE | args,
|  | VALUE | proc
| ) |  |

Definition at line 1130 of file thread.c.

References thread_create_params::args, g, thread_create_params::proc, rb_cThread, rb_thread_alloc(), and thread_create_params::type.

## ◆ rb_vm_ractor_blocking_cnt_dec()

void rb_vm_ractor_blocking_cnt_dec | ( | rb_vm_t * | vm,
|  | rb_ractor_t * | cr,
|  | const char * | file,
|  | int | line
| ) |  |

Definition at line 1798 of file ractor.c.

References ASSERT_vm_locking, rb_vm_struct::blocking_cnt, rb_vm_struct::ractor, RUBY_DEBUG_LOG2, and VM_ASSERT.

Referenced by rb_ractor_blocking_threads_dec(), rb_ractor_terminate_all(), and rb_vm_barrier().

## ◆ rb_vm_ractor_blocking_cnt_inc()

void rb_vm_ractor_blocking_cnt_inc | ( | rb_vm_t * | vm,
|  | rb_ractor_t * | cr,
|  | const char * | file,
|  | int | line
| ) |  |

Definition at line 1790 of file ractor.c.

References ASSERT_vm_locking, and VM_ASSERT.

Referenced by rb_ractor_terminate_all(), and rb_vm_barrier().