/* Headers Exposing a little more of the 1.9 runtime and some method prototypes for extensions to the Thread class. */ #include #include #include "thread_pthread.h" /* From vm_core.h: */ #define GET_VM() ruby_current_vm #define GET_THREAD() ruby_current_thread #if 1 #define GetCoreDataFromValue(obj, type, ptr) do { \ ptr = (type*)DATA_PTR(obj); \ } while (0) #else #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct(obj, type, ptr) #endif #if 1 #define GetCoreDataFromValue(obj, type, ptr) do { \ ptr = (type*)DATA_PTR(obj); \ } while (0) #else #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct(obj, type, ptr) #endif /* Opaque types (for now at least) */ typedef struct rb_iseq_struct rb_iseq_t; typedef struct rb_method_entry_struct rb_method_entry_t; typedef struct rb_proc_struct rb_proc_t; typedef struct { VALUE *pc; /* cfp[0] */ VALUE *sp; /* cfp[1] */ VALUE *bp; /* cfp[2] */ rb_iseq_t *iseq; /* cfp[3] */ VALUE flag; /* cfp[4] */ VALUE self; /* cfp[5] / block[0] */ VALUE *lfp; /* cfp[6] / block[1] */ VALUE *dfp; /* cfp[7] / block[2] */ rb_iseq_t *block_iseq; /* cfp[8] / block[3] */ VALUE proc; /* cfp[9] / block[4] */ const rb_method_entry_t *me;/* cfp[10] */ } rb_control_frame_t; enum ruby_special_exceptions { ruby_error_reenter, ruby_error_nomemory, ruby_error_sysstack, ruby_special_error_count }; #define GetThreadPtr(obj, ptr) \ GetCoreDataFromValue(obj, rb_thread_t, ptr) #define GetProcPtr(obj, ptr) \ GetCoreDataFromValue(obj, rb_proc_t, ptr) #ifndef NSIG # define NSIG (_SIGMAX + 1) /* For QNX */ #endif #define RUBY_NSIG NSIG typedef struct rb_vm_struct { VALUE self; rb_thread_lock_t global_vm_lock; struct rb_thread_struct *main_thread; struct rb_thread_struct *running_thread; st_table *living_threads; VALUE thgroup_default; int running; int thread_abort_on_exception; unsigned long trace_flag; volatile int sleeper; /* object management */ VALUE mark_object_ary; VALUE special_exceptions[ruby_special_error_count]; /* load */ VALUE top_self; VALUE load_path; VALUE loaded_features; struct st_table *loading_table; /* signal */ struct { VALUE cmd; int safe; } trap_list[RUBY_NSIG]; /* hook */ rb_event_hook_t *event_hooks; int src_encoding_index; VALUE verbose, debug, progname; VALUE coverages; #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE struct rb_objspace *objspace; #endif } rb_vm_t; typedef struct rb_thread_struct { VALUE self; rb_vm_t *vm; /* execution information */ VALUE *stack; /* must free, must mark. rb: seems to be nil. */ unsigned long stack_size; /* Number of stack (or rb_control_frame_t) entries */ rb_control_frame_t *cfp; int safe_level; int raised_flag; VALUE last_status; /* $? */ /* passing state */ int state; /* Lot's of other stuff ... */ } rb_thread_t; extern rb_thread_t *ruby_current_thread;