Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Typedefs | Enumerations | Functions
cont.c File Reference
#include "internal.h"
#include "vm_core.h"
#include "gc.h"
#include "eval_intern.h"

Go to the source code of this file.

Data Structures

struct  cont_saved_vm_stack
 
struct  rb_context_struct
 
struct  rb_fiber_struct
 

Macros

#define FIBER_USE_NATIVE   0
 
#define CAPTURE_JUST_VALID_VM_STACK   1
 
#define FIBER_CREATED_P(fib)   ((fib)->status == FIBER_CREATED)
 
#define FIBER_RESUMED_P(fib)   ((fib)->status == FIBER_RESUMED)
 
#define FIBER_SUSPENDED_P(fib)   ((fib)->status == FIBER_SUSPENDED)
 
#define FIBER_TERMINATED_P(fib)   ((fib)->status == FIBER_TERMINATED)
 
#define FIBER_RUNNABLE_P(fib)   (FIBER_CREATED_P(fib) || FIBER_SUSPENDED_P(fib))
 
#define GetContPtr(obj, ptr)   TypedData_Get_Struct((obj), rb_context_t, &cont_data_type, (ptr))
 
#define GetFiberPtr(obj, ptr)
 
#define THREAD_MUST_BE_RUNNING(th)
 
#define STACK_PAD_SIZE   1024
 

Typedefs

typedef struct rb_context_struct rb_context_t
 

Enumerations

enum  context_type { CONTINUATION_CONTEXT = 0, FIBER_CONTEXT = 1, ROOT_FIBER_CONTEXT = 2 }
 
enum  fiber_status { FIBER_CREATED, FIBER_RESUMED, FIBER_SUSPENDED, FIBER_TERMINATED }
 

Functions

 NOINLINE (static VALUE cont_capture(volatile int *volatile stat))
 
void rb_fiber_mark_self (const rb_fiber_t *fib)
 
VALUE rb_obj_is_fiber (VALUE obj)
 
 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 (VALUE(*ensure_func)(ANYARGS), VALUE(*rollback_func)(ANYARGS))
 
rb_control_frame_trb_vm_push_frame (rb_execution_context_t *sec, const rb_iseq_t *iseq, VALUE type, VALUE self, VALUE specval, VALUE cref_or_me, const VALUE *pc, VALUE *sp, int local_size, int stack_max)
 
VALUE rb_fiber_new (VALUE(*func)(ANYARGS), VALUE obj)
 
void rb_fiber_start (void)
 
VALUE rb_fiber_current (void)
 
VALUE rb_fiber_transfer (VALUE fibval, int argc, const VALUE *argv)
 
VALUE rb_fiber_resume (VALUE fibval, int argc, const VALUE *argv)
 
VALUE rb_fiber_yield (int argc, const VALUE *argv)
 
void rb_fiber_reset_root_local_storage (VALUE thval)
 
VALUE rb_fiber_alive_p (VALUE fibval)
 
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 75 of file cont.c.

◆ FIBER_CREATED_P

#define FIBER_CREATED_P (   fib)    ((fib)->status == FIBER_CREATED)

Definition at line 136 of file cont.c.

◆ FIBER_RESUMED_P

#define FIBER_RESUMED_P (   fib)    ((fib)->status == FIBER_RESUMED)

Definition at line 137 of file cont.c.

Referenced by rb_fiber_start().

◆ FIBER_RUNNABLE_P

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

Definition at line 140 of file cont.c.

◆ FIBER_SUSPENDED_P

#define FIBER_SUSPENDED_P (   fib)    ((fib)->status == FIBER_SUSPENDED)

Definition at line 138 of file cont.c.

◆ FIBER_TERMINATED_P

#define FIBER_TERMINATED_P (   fib)    ((fib)->status == FIBER_TERMINATED)

Definition at line 139 of file cont.c.

Referenced by rb_fiber_alive_p().

◆ FIBER_USE_NATIVE

#define FIBER_USE_NATIVE   0

Definition at line 61 of file cont.c.

◆ GetContPtr

#define GetContPtr (   obj,
  ptr 
)    TypedData_Get_Struct((obj), rb_context_t, &cont_data_type, (ptr))

Definition at line 206 of file cont.c.

◆ GetFiberPtr

#define GetFiberPtr (   obj,
  ptr 
)
Value:
do {\
TypedData_Get_Struct((obj), rb_fiber_t, &fiber_data_type, (ptr)); \
if (!(ptr)) rb_raise(rb_eFiberError, "uninitialized fiber"); \
} while (0)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284

Definition at line 209 of file cont.c.

Referenced by rb_fiber_alive_p(), rb_fiber_resume(), and rb_fiber_transfer().

◆ 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)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
VALUE rb_eThreadError
Definition: eval.c:857

Definition at line 216 of file cont.c.

Typedef Documentation

◆ rb_context_t

Enumeration Type Documentation

◆ context_type

Enumerator
CONTINUATION_CONTEXT 
FIBER_CONTEXT 
ROOT_FIBER_CONTEXT 

Definition at line 77 of file cont.c.

◆ fiber_status

Enumerator
FIBER_CREATED 
FIBER_RESUMED 
FIBER_SUSPENDED 
FIBER_TERMINATED 

Definition at line 129 of file cont.c.

Function Documentation

◆ Init_Cont()

void Init_Cont ( void  )

◆ NOINLINE() [1/2]

NOINLINE ( static VALUE   cont_capturevolatile int *volatile stat)

◆ NOINLINE() [2/2]

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

◆ NORETURN()

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

◆ rb_fiber_alive_p()

VALUE rb_fiber_alive_p ( VALUE  fibval)

Definition at line 1631 of file cont.c.

References FIBER_TERMINATED_P, GetFiberPtr, Qfalse, and Qtrue.

◆ rb_fiber_current()

VALUE rb_fiber_current ( void  )

Definition at line 1419 of file cont.c.

◆ rb_fiber_mark_self()

void rb_fiber_mark_self ( const rb_fiber_t fib)

Definition at line 377 of file cont.c.

References rb_fiber_struct::cont, rb_gc_mark(), and rb_context_struct::self.

◆ rb_fiber_new()

VALUE rb_fiber_new ( VALUE(*)(ANYARGS func,
VALUE  obj 
)

Definition at line 1317 of file cont.c.

◆ rb_fiber_reset_root_local_storage()

void rb_fiber_reset_root_local_storage ( VALUE  thval)

Definition at line 1612 of file cont.c.

Referenced by ruby_vm_destruct().

◆ rb_fiber_resume()

VALUE rb_fiber_resume ( VALUE  fibval,
int  argc,
const VALUE argv 
)

◆ rb_fiber_start()

void rb_fiber_start ( void  )

◆ rb_fiber_transfer()

VALUE rb_fiber_transfer ( VALUE  fibval,
int  argc,
const VALUE argv 
)

Definition at line 1563 of file cont.c.

References GetFiberPtr.

◆ rb_fiber_yield()

VALUE rb_fiber_yield ( int  argc,
const VALUE argv 
)

Definition at line 1606 of file cont.c.

◆ rb_obj_is_fiber()

VALUE rb_obj_is_fiber ( VALUE  obj)

Definition at line 425 of file cont.c.

References Qfalse, Qtrue, and rb_typeddata_is_kind_of().

◆ rb_vm_push_frame()

rb_control_frame_t* rb_vm_push_frame ( rb_execution_context_t sec,
const rb_iseq_t iseq,
VALUE  type,
VALUE  self,
VALUE  specval,
VALUE  cref_or_me,
const VALUE pc,
VALUE sp,
int  local_size,
int  stack_max 
)

Definition at line 273 of file vm_insnhelper.c.

◆ ruby_Init_Continuation_body()

RUBY_SYMBOL_EXPORT_BEGIN void ruby_Init_Continuation_body ( void  )

Definition at line 1813 of file cont.c.

Referenced by Init_continuation().

◆ ruby_Init_Fiber_as_Coroutine()

void ruby_Init_Fiber_as_Coroutine ( void  )

Definition at line 1824 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 ( VALUE(*)(ANYARGS ensure_func,
VALUE(*)(ANYARGS rollback_func 
)

Definition at line 1034 of file cont.c.

References GET_VM, NULL, st_data_t, st_init_numtable, st_insert, and UNLIKELY.