Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Typedefs | Enumerations | Functions
cont.c File Reference
`#include "internal.h"`
`#include "vm_core.h"`
`#include "gc.h"`
`#include "eval_intern.h"`
`#include "mjit.h"`
`#include <unistd.h>`
`#include <sys/mman.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
#define | PASS_KW_SPLAT (rb_empty_keyword_given_p() ? RB_PASS_EMPTY_KEYWORDS : rb_keyword_given_p())

## 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
| NOINLINE (static VALUE cont_capture(volatile int *volatile stat))
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)
| NOINLINE (static void fiber_setcontext(rb_fiber_t *new_fiber, rb_fiber_t *old_fiber))
| NOINLINE (NORETURN(static void cont_restore_1(rb_context_t *)))
| NORETURN (NOINLINE(static void cont_restore_0(rb_context_t *, VALUE *)))
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)
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)
RUBY_SYMBOL_EXPORT_BEGIN 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 39 of file cont.c.

## ◆ ERRNOMSG

#define ERRNOMSG strerror(errno)

Definition at line 254 of file cont.c.

## ◆ FIBER_CREATED_P

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

Definition at line 220 of file cont.c.

## ◆ FIBER_POOL_ALLOCATION_MAXIMUM_SIZE

#define FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 1024

Definition at line 48 of file cont.c.

## ◆ FIBER_POOL_INITIAL_SIZE

#define FIBER_POOL_INITIAL_SIZE 32

Definition at line 47 of file cont.c.

## ◆ FIBER_RESUMED_P

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

Definition at line 221 of file cont.c.

## ◆ FIBER_RUNNABLE_P

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

Definition at line 224 of file cont.c.

## ◆ FIBER_STACK_FLAGS

#define FIBER_STACK_FLAGS (MAP_PRIVATE | MAP_ANON)

Definition at line 251 of file cont.c.

## ◆ FIBER_SUSPENDED_P

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

Definition at line 222 of file cont.c.

## ◆ FIBER_TERMINATED_P

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

Definition at line 223 of file cont.c.

## ◆ PASS_KW_SPLAT

#define PASS_KW_SPLAT (rb_empty_keyword_given_p() ? RB_PASS_EMPTY_KEYWORDS : rb_keyword_given_p())

Definition at line 1787 of file cont.c.

## ◆ RB_PAGE_MASK

#define RB_PAGE_MASK (~(RB_PAGE_SIZE - 1))

Definition at line 28 of file cont.c.

## ◆ RB_PAGE_SIZE

#define RB_PAGE_SIZE (pagesize)

Definition at line 27 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)

Definition at line 835 of file cont.c.

## Typedef Documentation

## ◆ e_proc

typedef VALUE e_proc(VALUE)

Definition at line 1515 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 51 of file cont.c.

## ◆ fiber_status

enum fiber_status

Enumerator
FIBER_CREATED |
FIBER_RESUMED |
FIBER_SUSPENDED |
FIBER_TERMINATED |

Definition at line 213 of file cont.c.

## Function Documentation

## ◆ Init_Cont()

void Init_Cont | ( | void |  | ) |

Definition at line 2407 of file cont.c.

References rb_vm_struct::default_params, rb_vm_struct::fiber_machine_stack_size, rb_vm_struct::fiber_vm_stack_size, GET_THREAD, rb_thread_struct::vm, and fiber_pool::vm_stack_size.

## ◆ NOINLINE() [1/3]

NOINLINE | ( | NORETURN(static void cont_restore_1(rb_context_t *)) |  | ) |

## ◆ NOINLINE() [2/3]

NOINLINE | ( | static VALUE | cont_capturevolatile int *volatile stat | ) |

## ◆ NOINLINE() [3/3]

NOINLINE | ( | static void | fiber_setcontextrb_fiber_t *new_fiber, rb_fiber_t *old_fiber | ) |

## ◆ NORETURN()

NORETURN | ( | NOINLINE(static void cont_restore_0(rb_context_t *, VALUE *)) |  | ) |

## ◆ rb_fiber_alive_p()

VALUE rb_fiber_alive_p | ( | VALUE | fiber_value | ) |

Definition at line 2137 of file cont.c.

References FIBER_TERMINATED_P.

## ◆ rb_fiber_close()

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

Definition at line 2057 of file cont.c.

## ◆ rb_fiber_current()

VALUE rb_fiber_current | ( | void |  | ) |

Definition at line 1942 of file cont.c.

## ◆ rb_fiber_mark_self()

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

Definition at line 972 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 1780 of file cont.c.

## ◆ rb_fiber_reset_root_local_storage()

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

Definition at line 2120 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 2102 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 2082 of file cont.c.

Referenced by rb_fiber_resume().

## ◆ rb_fiber_start()

void rb_fiber_start | ( | void |  | ) |

Definition at line 1790 of file cont.c.

References rb_context_struct::argc, argc, argv, 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, GET_THREAD, GetProcPtr, rb_context_struct::kw_splat, NIL_P, Qfalse, Qnil, RARRAY_CONST_PTR, rb_adjust_argv_kw_splat(), 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_current_execution_context_ptr, RUBY_EVENT_FIBER_SWITCH, rb_thread_struct::self, TAG_FATAL, TAG_NONE, TAG_RAISE, TRUE, rb_context_struct::value, VAR_FROM_MEMORY, VM_ASSERT, and VM_BLOCK_HANDLER_NONE.

## ◆ rb_fiber_transfer()

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

Definition at line 2051 of file cont.c.

## ◆ rb_fiber_update_self()

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

Definition at line 961 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 2114 of file cont.c.

## ◆ rb_fiber_yield_kw()

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

Definition at line 2108 of file cont.c.

## ◆ rb_obj_is_fiber()

VALUE rb_obj_is_fiber | ( | VALUE | obj | ) |

Definition at line 1041 of file cont.c.

References obj, and rb_typeddata_is_kind_of().

## ◆ rb_threadptr_root_fiber_release()

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

Definition at line 1880 of file cont.c.

References rb_fiber_struct::cont, rb_thread_struct::ec, FIBER_CONTEXT, rb_execution_context_struct::fiber_ptr, 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 1865 of file cont.c.

References rb_fiber_struct::cont, errno, FIBER_CONTEXT, rb_execution_context_struct::fiber_ptr, MEMZERO, rb_bug(), 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 1898 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()

RUBY_SYMBOL_EXPORT_BEGIN void ruby_Init_Continuation_body | ( | void |  | ) |

Definition at line 2450 of file cont.c.

Referenced by Init_continuation().

## ◆ ruby_Init_Fiber_as_Coroutine()

void ruby_Init_Fiber_as_Coroutine | ( | void |  | ) |

Definition at line 2461 of file cont.c.

References rb_define_method().

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 1520 of file cont.c.

References GET_VM, NULL, st_init_numtable(), st_insert(), and UNLIKELY.

rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
rb_eThreadError
VALUE rb_eThreadError
Definition: eval.c:923