Ruby: cont.c File Reference

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

Data Structures | Macros | Typedefs | Enumerations | Functions
cont.c File Reference
`#include "ruby/internal/config.h"`
`#include <unistd.h>`
`#include <sys/mman.h>`
`#include <COROUTINE_H>`
`#include "eval_intern.h"`
`#include "gc.h"`
`#include "internal.h"`
`#include "internal/cont.h"`
`#include "internal/proc.h"`
`#include "internal/warnings.h"`
`#include "internal/scheduler.h"`
`#include "mjit.h"`
`#include "vm_core.h"`
`#include "id_table.h"`
`#include "ractor_core.h"`

Go to the source code of this file.

## Data Structures
struct | cont_saved_vm_stack
struct | fiber_pool_stack
struct | fiber_pool_vacancy
struct | fiber_pool_allocation
struct | fiber_pool
struct | rb_context_struct
struct | rb_fiber_struct

## Macros
#define | RB_PAGE_SIZE (pagesize)
#define | RB_PAGE_MASK (~(RB_PAGE_SIZE - 1))
#define | CAPTURE_JUST_VALID_VM_STACK 1
#define | FIBER_POOL_INITIAL_SIZE 32
#define | FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 1024
#define | FIBER_CREATED_P(fiber) ((fiber)->status == FIBER_CREATED)
#define | FIBER_RESUMED_P(fiber) ((fiber)->status == FIBER_RESUMED)
#define | FIBER_SUSPENDED_P(fiber) ((fiber)->status == FIBER_SUSPENDED)
#define | FIBER_TERMINATED_P(fiber) ((fiber)->status == FIBER_TERMINATED)
#define | FIBER_RUNNABLE_P(fiber) (FIBER_CREATED_P(fiber) || FIBER_SUSPENDED_P(fiber))
#define | FIBER_STACK_FLAGS (MAP_PRIVATE | MAP_ANON)
#define | ERRNOMSG strerror(errno)
#define | THREAD_MUST_BE_RUNNING(th)
#define | STACK_PAD_SIZE 1024

## Typedefs
typedef struct rb_context_struct | rb_context_t
typedef VALUE | e_proc(VALUE)

## Enumerations
enum | context_type { CONTINUATION_CONTEXT = 0 , FIBER_CONTEXT = 1 }
enum | fiber_status { FIBER_CREATED , FIBER_RESUMED , FIBER_SUSPENDED , FIBER_TERMINATED }

## Functions
rb_thread_t * | rb_fiber_threadptr (const rb_fiber_t *fiber)
void | rb_fiber_update_self (rb_fiber_t *fiber)
void | rb_fiber_mark_self (const rb_fiber_t *fiber)
VALUE | rb_obj_is_fiber (VALUE obj)
VALUE | rb_fiberptr_self (struct rb_fiber_struct *fiber)
unsigned int | rb_fiberptr_blocking (struct rb_fiber_struct *fiber)
void | rb_fiber_init_mjit_cont (struct rb_fiber_struct *fiber)
void | ruby_register_rollback_func_for_ensure (e_proc *ensure_func, e_proc *rollback_func)
VALUE | rb_fiber_new (rb_block_call_func_t func, VALUE obj)
void | rb_fiber_start (void)
void | rb_threadptr_root_fiber_setup (rb_thread_t *th)
void | rb_threadptr_root_fiber_release (rb_thread_t *th)
void | rb_threadptr_root_fiber_terminate (rb_thread_t *th)
VALUE | rb_fiber_current (void)
VALUE | rb_fiber_transfer (VALUE fiber_value, int argc, const VALUE *argv)
VALUE | rb_fiber_blocking_p (VALUE fiber)
void | rb_fiber_close (rb_fiber_t *fiber)
VALUE | rb_fiber_resume_kw (VALUE fiber_value, int argc, const VALUE *argv, int kw_splat)
VALUE | rb_fiber_resume (VALUE fiber_value, int argc, const VALUE *argv)
VALUE | rb_fiber_yield_kw (int argc, const VALUE *argv, int kw_splat)
VALUE | rb_fiber_yield (int argc, const VALUE *argv)
void | rb_fiber_reset_root_local_storage (rb_thread_t *th)
VALUE | rb_fiber_alive_p (VALUE fiber_value)
void | Init_Cont (void)
void | ruby_Init_Continuation_body (void)
void | ruby_Init_Fiber_as_Coroutine (void)

## Macro Definition Documentation

## ◆ CAPTURE_JUST_VALID_VM_STACK

#define CAPTURE_JUST_VALID_VM_STACK 1

Definition at line 47 of file cont.c.

## ◆ ERRNOMSG

#define ERRNOMSG strerror(errno)

Definition at line 264 of file cont.c.

## ◆ FIBER_CREATED_P

#define FIBER_CREATED_P | ( |  | fiber | ) | ((fiber)->status == FIBER_CREATED)

Definition at line 228 of file cont.c.

## ◆ FIBER_POOL_ALLOCATION_MAXIMUM_SIZE

#define FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 1024

Definition at line 56 of file cont.c.

## ◆ FIBER_POOL_INITIAL_SIZE

#define FIBER_POOL_INITIAL_SIZE 32

Definition at line 55 of file cont.c.

## ◆ FIBER_RESUMED_P

#define FIBER_RESUMED_P | ( |  | fiber | ) | ((fiber)->status == FIBER_RESUMED)

Definition at line 229 of file cont.c.

## ◆ FIBER_RUNNABLE_P

#define FIBER_RUNNABLE_P | ( |  | fiber | ) | (FIBER_CREATED_P(fiber) || FIBER_SUSPENDED_P(fiber))

Definition at line 232 of file cont.c.

## ◆ FIBER_STACK_FLAGS

#define FIBER_STACK_FLAGS (MAP_PRIVATE | MAP_ANON)

Definition at line 261 of file cont.c.

## ◆ FIBER_SUSPENDED_P

#define FIBER_SUSPENDED_P | ( |  | fiber | ) | ((fiber)->status == FIBER_SUSPENDED)

Definition at line 230 of file cont.c.

## ◆ FIBER_TERMINATED_P

#define FIBER_TERMINATED_P | ( |  | fiber | ) | ((fiber)->status == FIBER_TERMINATED)

Definition at line 231 of file cont.c.

## ◆ RB_PAGE_MASK

#define RB_PAGE_MASK (~(RB_PAGE_SIZE - 1))

Definition at line 36 of file cont.c.

## ◆ RB_PAGE_SIZE

#define RB_PAGE_SIZE (pagesize)

Definition at line 35 of file cont.c.

## ◆ STACK_PAD_SIZE

#define STACK_PAD_SIZE 1024

## ◆ THREAD_MUST_BE_RUNNING

#define THREAD_MUST_BE_RUNNING | ( |  | th | ) |

Value:
do { \
if (!(th)->ec->tag) rb_raise(rb_eThreadError, "not running thread"); \
} while (0)
rb_eThreadError
VALUE rb_eThreadError
Definition: eval.c:953
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2917

Definition at line 847 of file cont.c.

## Typedef Documentation

## ◆ e_proc

typedef VALUE e_proc(VALUE)

Definition at line 1558 of file cont.c.

## ◆ rb_context_t

typedef struct rb_context_struct rb_context_t

## Enumeration Type Documentation

## ◆ context_type

enum context_type

Enumerator
CONTINUATION_CONTEXT |
FIBER_CONTEXT |

Definition at line 59 of file cont.c.

## ◆ fiber_status

enum fiber_status

Enumerator
FIBER_CREATED |
FIBER_RESUMED |
FIBER_SUSPENDED |
FIBER_TERMINATED |

Definition at line 221 of file cont.c.

## Function Documentation

## ◆ Init_Cont()

void Init_Cont | ( | void |  | ) |

Definition at line 3044 of file cont.c.

References rb_vm_struct::default_params, rb_thread_struct::ec, rb_vm_struct::fiber_machine_stack_size, FIBER_POOL_INITIAL_SIZE, rb_vm_struct::fiber_vm_stack_size, fiber_pool::free_stacks, getenv, rb_execution_context_struct::machine, rb_cObject, rb_define_alias(), rb_define_alloc_func(), rb_define_class(), rb_define_class_under(), rb_define_method, rb_define_singleton_method, rb_eStandardError, rb_fiber_blocking_p(), SET_MACHINE_STACK_END, rb_execution_context_struct::stack_end, rb_thread_struct::vm, and fiber_pool::vm_stack_size.

## ◆ rb_fiber_alive_p()

VALUE rb_fiber_alive_p | ( | VALUE | fiber_value | ) |

Definition at line 2455 of file cont.c.

References FIBER_TERMINATED_P, Qfalse, and Qtrue.

Referenced by ruby_Init_Fiber_as_Coroutine().

## ◆ rb_fiber_blocking_p()

VALUE rb_fiber_blocking_p | ( | VALUE | fiber | ) |

Definition at line 2329 of file cont.c.

References Qfalse, and Qtrue.

Referenced by Init_Cont().

## ◆ rb_fiber_close()

void rb_fiber_close | ( | rb_fiber_t * | fiber | ) |

Definition at line 2365 of file cont.c.

References FIBER_TERMINATED.

## ◆ rb_fiber_current()

VALUE rb_fiber_current | ( | void |  | ) |

Definition at line 2182 of file cont.c.

References rb_fiber_struct::cont, and rb_context_struct::self.

## ◆ rb_fiber_init_mjit_cont()

void rb_fiber_init_mjit_cont | ( | struct rb_fiber_struct * | fiber | ) |

Definition at line 1165 of file cont.c.

References rb_fiber_struct::cont.

Referenced by rb_threadptr_root_fiber_setup().

## ◆ rb_fiber_mark_self()

void rb_fiber_mark_self | ( | const rb_fiber_t * | fiber | ) |

Definition at line 991 of file cont.c.

References rb_fiber_struct::cont, rb_execution_context_mark(), rb_gc_mark_movable(), rb_context_struct::saved_ec, and rb_context_struct::self.

## ◆ rb_fiber_new()

VALUE rb_fiber_new | ( | rb_block_call_func_t | func,
|  | VALUE | obj
| ) |  |

Definition at line 1902 of file cont.c.

References Qnil, and ruby::backward::cxxanyargs::rb_proc_new().

## ◆ rb_fiber_reset_root_local_storage()

void rb_fiber_reset_root_local_storage | ( | rb_thread_t * | th | ) |

Definition at line 2438 of file cont.c.

References rb_fiber_struct::cont, rb_thread_struct::ec, rb_execution_context_struct::fiber_ptr, rb_execution_context_struct::local_storage, rb_thread_struct::root_fiber, and rb_context_struct::saved_ec.

Referenced by ruby_vm_destruct().

## ◆ rb_fiber_resume()

VALUE rb_fiber_resume | ( | VALUE | fiber_value,
|  | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 2420 of file cont.c.

References argc, argv, rb_fiber_resume_kw(), and RB_NO_KEYWORDS.

## ◆ rb_fiber_resume_kw()

VALUE rb_fiber_resume_kw | ( | VALUE | fiber_value,
|  | int | argc,
|  | const VALUE * | argv,
|  | int | kw_splat
| ) |  |

Definition at line 2391 of file cont.c.

References argc, argv, FIBER_CREATED, FIBER_CREATED_P, FIBER_TERMINATED_P, NULL, rb_fiber_struct::prev, rb_raise(), rb_fiber_struct::resuming_fiber, RTEST, and rb_fiber_struct::yielding.

Referenced by rb_fiber_resume().

## ◆ rb_fiber_start()

void rb_fiber_start | ( | void |  | ) |

Definition at line 2014 of file cont.c.

References rb_context_struct::argc, argc, argv, rb_fiber_struct::blocking, rb_thread_struct::blocking, rb_thread_struct::ec, EC_EXEC_TAG, EC_POP_TAG, EC_PUSH_TAG, err, rb_execution_context_struct::errinfo, EXEC_EVENT_HOOK, rb_execution_context_struct::fiber_ptr, FIBER_RESUMED_P, rb_fiber_struct::first_proc, GetProcPtr, rb_context_struct::kw_splat, NIL_P, Qfalse, Qnil, RARRAY_CONST_PTR, rb_fiber_start(), rb_threadptr_pending_interrupt_enque(), rb_vm_invoke_proc(), rb_vm_make_jump_tag_but_local_jump(), rb_vm_proc_local_ep(), rb_execution_context_struct::root_lep, rb_execution_context_struct::root_svar, RUBY_EVENT_FIBER_SWITCH, rb_thread_struct::self, TAG_FATAL, TAG_NONE, TAG_RAISE, TRUE, rb_context_struct::value, VAR_FROM_MEMORY, VM_ASSERT, VM_BLOCK_HANDLER_NONE, and VM_UNREACHABLE.

Referenced by rb_fiber_start().

## ◆ rb_fiber_threadptr()

rb_thread_t * rb_fiber_threadptr | ( | const rb_fiber_t * | fiber | ) |

Definition at line 852 of file cont.c.

References rb_fiber_struct::cont, rb_context_struct::saved_ec, and rb_execution_context_struct::thread_ptr.

## ◆ rb_fiber_transfer()

VALUE rb_fiber_transfer | ( | VALUE | fiber_value,
|  | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 2309 of file cont.c.

References argc, argv, Qfalse, and RB_NO_KEYWORDS.

## ◆ rb_fiber_update_self()

void rb_fiber_update_self | ( | rb_fiber_t * | fiber | ) |

Definition at line 980 of file cont.c.

References rb_fiber_struct::cont, rb_execution_context_update(), rb_gc_location(), rb_context_struct::saved_ec, and rb_context_struct::self.

## ◆ rb_fiber_yield()

VALUE rb_fiber_yield | ( | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 2432 of file cont.c.

References argc, argv, Qfalse, and RB_NO_KEYWORDS.

## ◆ rb_fiber_yield_kw()

VALUE rb_fiber_yield_kw | ( | int | argc,
|  | const VALUE * | argv,
|  | int | kw_splat
| ) |  |

Definition at line 2426 of file cont.c.

References argc, argv, and Qfalse.

## ◆ rb_fiberptr_blocking()

unsigned int rb_fiberptr_blocking | ( | struct rb_fiber_struct * | fiber | ) |

Definition at line 1158 of file cont.c.

References rb_fiber_struct::blocking.

## ◆ rb_fiberptr_self()

VALUE rb_fiberptr_self | ( | struct rb_fiber_struct * | fiber | ) |

Definition at line 1153 of file cont.c.

References rb_fiber_struct::cont, and rb_context_struct::self.

## ◆ rb_obj_is_fiber()

VALUE rb_obj_is_fiber | ( | VALUE | obj | ) |

Definition at line 1060 of file cont.c.

References Qfalse, Qtrue, and rb_typeddata_is_kind_of().

Referenced by rb_objspace_call_finalizer().

## ◆ rb_threadptr_root_fiber_release()

void rb_threadptr_root_fiber_release | ( | rb_thread_t * | th | ) |

Definition at line 2110 of file cont.c.

References rb_fiber_struct::cont, rb_thread_struct::ec, FIBER_CONTEXT, rb_execution_context_struct::fiber_ptr, NULL, rb_thread_struct::ractor, rb_thread_struct::root_fiber, rb_context_struct::self, rb_context_struct::type, and VM_ASSERT.

## ◆ rb_threadptr_root_fiber_setup()

void rb_threadptr_root_fiber_setup | ( | rb_thread_t * | th | ) |

Definition at line 2091 of file cont.c.

References rb_fiber_struct::blocking, rb_fiber_struct::cont, rb_thread_struct::ec, FIBER_CONTEXT, rb_execution_context_struct::fiber_ptr, FIBER_RESUMED, MEMZERO, rb_bug(), rb_fiber_init_mjit_cont(), ruby_mimmalloc(), rb_context_struct::saved_ec, strerror(), rb_execution_context_struct::thread_ptr, and rb_context_struct::type.

## ◆ rb_threadptr_root_fiber_terminate()

void rb_threadptr_root_fiber_terminate | ( | rb_thread_t * | th | ) |

Definition at line 2130 of file cont.c.

References rb_thread_struct::ec, rb_execution_context_struct::fiber_ptr, FIBER_TERMINATED, and rb_ec_clear_vm_stack().

## ◆ ruby_Init_Continuation_body()

void ruby_Init_Continuation_body | ( | void |  | ) |

Definition at line 3111 of file cont.c.

References CLASS_OF, rb_cObject, rb_define_class(), rb_define_global_function, rb_define_method, rb_undef_alloc_func(), and rb_undef_method().

Referenced by Init_continuation().

## ◆ ruby_Init_Fiber_as_Coroutine()

void ruby_Init_Fiber_as_Coroutine | ( | void |  | ) |

Definition at line 3122 of file cont.c.

References rb_define_method, rb_define_singleton_method, rb_ext_ractor_safe(), and rb_fiber_alive_p().

Referenced by Init_fiber().

## ◆ ruby_register_rollback_func_for_ensure()

void ruby_register_rollback_func_for_ensure | ( | e_proc * | ensure_func,
|  | e_proc * | rollback_func
| ) |  |

Definition at line 1563 of file cont.c.

References NULL, st_init_numtable, st_insert, and UNLIKELY.

Referenced by Init_Hash().