Ruby  2.1.10p492(2016-04-01revision54464)
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
thread.c File Reference
#include "eval_intern.h"
#include "gc.h"
#include "timev.h"
#include "ruby/io.h"
#include "ruby/thread.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  rb_blocking_region_buffer
 
struct  rb_mutex_struct
 
struct  join_arg
 
struct  select_args
 
struct  thgroup
 
struct  thgroup_list_params
 
struct  exec_recursive_params
 

Macros

#define __USE_FORTIFY_LEVEL   0
 
#define USE_NATIVE_THREAD_PRIORITY   0
 
#define RUBY_THREAD_PRIORITY_MAX   3
 
#define RUBY_THREAD_PRIORITY_MIN   -3
 
#define THREAD_DEBUG   0
 
#define eKillSignal   INT2FIX(0)
 
#define eTerminateSignal   INT2FIX(1)
 
#define closed_stream_error   GET_VM()->special_exceptions[ruby_error_closed_stream]
 
#define THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
 
#define RB_GC_SAVE_MACHINE_REGISTER_STACK(th)
 
#define RB_GC_SAVE_MACHINE_CONTEXT(th)
 
#define GVL_UNLOCK_BEGIN()
 
#define GVL_UNLOCK_END()
 
#define only_if_constant(expr, notconst)   notconst
 
#define BLOCKING_REGION(exec, ubf, ubfarg, fail_if_interrupted)
 
#define thread_debug   if(0)printf
 
#define thread_start_func_2(th, st, rst)   thread_start_func_2(th, st)
 
#define DELAY_INFTY   1E30
 
#define rb_fd_rcopy(d, s)   (*(d) = *(s))
 
#define GetMutexPtr(obj, tobj)   TypedData_Get_Struct((obj), rb_mutex_t, &mutex_data_type, (tobj))
 
#define mutex_mark   NULL
 
#define GetThreadShieldPtr(obj)   ((VALUE)rb_check_typeddata((obj), &thread_shield_data_type))
 
#define THREAD_SHIELD_WAITING_MASK   (FL_USER0|FL_USER1|FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6|FL_USER7|FL_USER8|FL_USER9|FL_USER10|FL_USER11|FL_USER12|FL_USER13|FL_USER14|FL_USER15|FL_USER16|FL_USER17|FL_USER18|FL_USER19)
 
#define THREAD_SHIELD_WAITING_SHIFT   (FL_USHIFT)
 
#define rb_thread_shield_waiting(b)   (int)((RBASIC(b)->flags&THREAD_SHIELD_WAITING_MASK)>>THREAD_SHIELD_WAITING_SHIFT)
 
#define OBJ_ID_EQL(obj_id, other)   ((obj_id) == (other))
 
#define rb_intern(str)   rb_intern_const(str)
 

Typedefs

typedef struct rb_mutex_struct rb_mutex_t
 

Enumerations

enum  handle_interrupt_timing { INTERRUPT_NONE, INTERRUPT_IMMEDIATE, INTERRUPT_ON_BLOCKING, INTERRUPT_NEVER }
 

Functions

static void sleep_timeval (rb_thread_t *th, struct timeval time, int spurious_check)
 
static void sleep_wait_for_interrupt (rb_thread_t *th, double sleepsec, int spurious_check)
 
static void sleep_forever (rb_thread_t *th, int nodeadlock, int spurious_check)
 
static double timeofday (void)
 
static int rb_threadptr_dead (rb_thread_t *th)
 
static void rb_check_deadlock (rb_vm_t *vm)
 
static int rb_threadptr_pending_interrupt_empty_p (rb_thread_t *th)
 
static void st_delete_wrap (st_table *table, st_data_t key)
 
static int set_unblock_function (rb_thread_t *th, rb_unblock_function_t *func, void *arg, struct rb_unblock_callback *old, int fail_if_interrupted)
 
static void reset_unblock_function (rb_thread_t *th, const struct rb_unblock_callback *old)
 
static int blocking_region_begin (rb_thread_t *th, struct rb_blocking_region_buffer *region, rb_unblock_function_t *ubf, void *arg, int fail_if_interrupted)
 
static void blocking_region_end (rb_thread_t *th, struct rb_blocking_region_buffer *region)
 
 NOINLINE (static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start))
 
static void timer_thread_function (void *)
 
void rb_vm_gvl_destroy (rb_vm_t *vm)
 
void rb_nativethread_lock_initialize (rb_nativethread_lock_t *lock)
 
void rb_nativethread_lock_destroy (rb_nativethread_lock_t *lock)
 
void rb_nativethread_lock_lock (rb_nativethread_lock_t *lock)
 
void rb_nativethread_lock_unlock (rb_nativethread_lock_t *lock)
 
static void rb_threadptr_interrupt_common (rb_thread_t *th, int trap)
 
void rb_threadptr_interrupt (rb_thread_t *th)
 
void rb_threadptr_trap_interrupt (rb_thread_t *th)
 
static int terminate_i (st_data_t key, st_data_t val, rb_thread_t *main_thread)
 
static void rb_mutex_abandon_all (rb_mutex_t *mutexes)
 
static void rb_mutex_abandon_keeping_mutexes (rb_thread_t *th)
 
static void rb_mutex_abandon_locking_mutex (rb_thread_t *th)
 
static const char * rb_mutex_unlock_th (rb_mutex_t *mutex, rb_thread_t volatile *th)
 
void rb_threadptr_unlock_all_locking_mutexes (rb_thread_t *th)
 
void rb_thread_terminate_all (void)
 
static void thread_cleanup_func_before_exec (void *th_ptr)
 
static void thread_cleanup_func (void *th_ptr, int atfork)
 
static VALUE rb_threadptr_raise (rb_thread_t *, int, VALUE *)
 
void ruby_thread_init_stack (rb_thread_t *th)
 
static int thread_start_func_2 (rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start)
 
static VALUE thread_create_core (VALUE thval, VALUE args, VALUE(*fn)(ANYARGS))
 
static VALUE thread_s_new (int argc, VALUE *argv, VALUE klass)
 
static VALUE thread_start (VALUE klass, VALUE args)
 
static VALUE thread_initialize (VALUE thread, VALUE args)
 
VALUE rb_thread_create (VALUE(*fn)(ANYARGS), void *arg)
 
static VALUE remove_from_join_list (VALUE arg)
 
static VALUE thread_join_sleep (VALUE arg)
 
static VALUE thread_join (rb_thread_t *target_th, double delay)
 
static VALUE thread_join_m (int argc, VALUE *argv, VALUE self)
 
static VALUE thread_value (VALUE self)
 
static struct timeval double2timeval (double d)
 
static void getclockofday (struct timeval *tp)
 
void rb_thread_sleep_forever (void)
 
void rb_thread_sleep_deadly (void)
 
static void sleep_for_polling (rb_thread_t *th)
 
void rb_thread_wait_for (struct timeval time)
 
void rb_thread_polling (void)
 
void rb_thread_check_ints (void)
 
int rb_thread_check_trap_pending (void)
 
int rb_thread_interrupted (VALUE thval)
 
void rb_thread_sleep (int sec)
 
static void rb_thread_schedule_limits (unsigned long limits_us)
 
void rb_thread_schedule (void)
 
struct rb_blocking_region_bufferrb_thread_blocking_region_begin (void)
 
void rb_thread_blocking_region_end (struct rb_blocking_region_buffer *region)
 
static void * call_without_gvl (void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2, int fail_if_interrupted)
 
void * rb_thread_call_without_gvl2 (void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
 
void * rb_thread_call_without_gvl (void *(*func)(void *data), void *data1, rb_unblock_function_t *ubf, void *data2)
 
VALUE rb_thread_io_blocking_region (rb_blocking_function_t *func, void *data1, int fd)
 
VALUE rb_thread_blocking_region (rb_blocking_function_t *func, void *data1, rb_unblock_function_t *ubf, void *data2)
 
void * rb_thread_call_with_gvl (void *(*func)(void *), void *data1)
 
int ruby_thread_has_gvl_p (void)
 
static VALUE thread_s_pass (VALUE klass)
 
void rb_threadptr_pending_interrupt_clear (rb_thread_t *th)
 
void rb_threadptr_pending_interrupt_enque (rb_thread_t *th, VALUE v)
 
static enum handle_interrupt_timing rb_threadptr_pending_interrupt_check_mask (rb_thread_t *th, VALUE err)
 
static int rb_threadptr_pending_interrupt_include_p (rb_thread_t *th, VALUE err)
 
static VALUE rb_threadptr_pending_interrupt_deque (rb_thread_t *th, enum handle_interrupt_timing timing)
 
int rb_threadptr_pending_interrupt_active_p (rb_thread_t *th)
 
static int handle_interrupt_arg_check_i (VALUE key, VALUE val)
 
static VALUE rb_thread_s_handle_interrupt (VALUE self, VALUE mask_arg)
 
static VALUE rb_thread_pending_interrupt_p (int argc, VALUE *argv, VALUE target_thread)
 
static VALUE rb_thread_s_pending_interrupt_p (int argc, VALUE *argv, VALUE self)
 
static void rb_threadptr_to_kill (rb_thread_t *th)
 
static rb_atomic_t threadptr_get_interrupts (rb_thread_t *th)
 
void rb_threadptr_execute_interrupts (rb_thread_t *th, int blocking_timing)
 
void rb_thread_execute_interrupts (VALUE thval)
 
static void rb_threadptr_ready (rb_thread_t *th)
 
void rb_threadptr_signal_raise (rb_thread_t *th, int sig)
 
void rb_threadptr_signal_exit (rb_thread_t *th)
 
void ruby_thread_stack_overflow (rb_thread_t *th)
 
int rb_threadptr_set_raised (rb_thread_t *th)
 
int rb_threadptr_reset_raised (rb_thread_t *th)
 
static int thread_fd_close_i (st_data_t key, st_data_t val, st_data_t data)
 
void rb_thread_fd_close (int fd)
 
static VALUE thread_raise_m (int argc, VALUE *argv, VALUE self)
 
VALUE rb_thread_kill (VALUE thread)
 
static VALUE rb_thread_s_kill (VALUE obj, VALUE th)
 
static VALUE rb_thread_exit (void)
 
VALUE rb_thread_wakeup (VALUE thread)
 
VALUE rb_thread_wakeup_alive (VALUE thread)
 
VALUE rb_thread_run (VALUE thread)
 
VALUE rb_thread_stop (void)
 
static int thread_list_i (st_data_t key, st_data_t val, void *data)
 
VALUE rb_thread_list (void)
 
VALUE rb_thread_current (void)
 
static VALUE thread_s_current (VALUE klass)
 
VALUE rb_thread_main (void)
 
static VALUE rb_thread_s_main (VALUE klass)
 
static VALUE rb_thread_s_abort_exc (void)
 
static VALUE rb_thread_s_abort_exc_set (VALUE self, VALUE val)
 
static VALUE rb_thread_abort_exc (VALUE thread)
 
static VALUE rb_thread_abort_exc_set (VALUE thread, VALUE val)
 
VALUE rb_thread_group (VALUE thread)
 
static const char * thread_status_name (rb_thread_t *th)
 
static VALUE rb_thread_status (VALUE thread)
 
static VALUE rb_thread_alive_p (VALUE thread)
 
static VALUE rb_thread_stop_p (VALUE thread)
 
static VALUE rb_thread_safe_level (VALUE thread)
 
static VALUE rb_thread_inspect (VALUE thread)
 
static VALUE threadptr_local_aref (rb_thread_t *th, ID id)
 
VALUE rb_thread_local_aref (VALUE thread, ID id)
 
static VALUE rb_thread_aref (VALUE thread, VALUE key)
 
static VALUE threadptr_local_aset (rb_thread_t *th, ID id, VALUE val)
 
VALUE rb_thread_local_aset (VALUE thread, ID id, VALUE val)
 
static VALUE rb_thread_aset (VALUE self, VALUE id, VALUE val)
 
static VALUE rb_thread_variable_get (VALUE thread, VALUE key)
 
static VALUE rb_thread_variable_set (VALUE thread, VALUE id, VALUE val)
 
static VALUE rb_thread_key_p (VALUE self, VALUE key)
 
static int thread_keys_i (ID key, VALUE value, VALUE ary)
 
static int vm_living_thread_num (rb_vm_t *vm)
 
int rb_thread_alone (void)
 
static VALUE rb_thread_keys (VALUE self)
 
static int keys_i (VALUE key, VALUE value, VALUE ary)
 
static VALUE rb_thread_variables (VALUE thread)
 
static VALUE rb_thread_variable_p (VALUE thread, VALUE key)
 
static VALUE rb_thread_priority (VALUE thread)
 
static VALUE rb_thread_priority_set (VALUE thread, VALUE prio)
 
static int do_select (int n, rb_fdset_t *read, rb_fdset_t *write, rb_fdset_t *except, struct timeval *timeout)
 
static void rb_thread_wait_fd_rw (int fd, int read)
 
void rb_thread_wait_fd (int fd)
 
int rb_thread_fd_writable (int fd)
 
int rb_thread_select (int max, fd_set *read, fd_set *write, fd_set *except, struct timeval *timeout)
 
int rb_thread_fd_select (int max, rb_fdset_t *read, rb_fdset_t *write, rb_fdset_t *except, struct timeval *timeout)
 
static rb_fdset_tinit_set_fd (int fd, rb_fdset_t *fds)
 
static VALUE select_single (VALUE ptr)
 
static VALUE select_single_cleanup (VALUE ptr)
 
int rb_wait_for_single_fd (int fd, int events, struct timeval *tv)
 
void rb_gc_set_stack_end (VALUE **stack_end_p)
 
void rb_threadptr_check_signal (rb_thread_t *mth)
 
void rb_thread_stop_timer_thread (int close_anyway)
 
void rb_thread_reset_timer_thread (void)
 
void rb_thread_start_timer_thread (void)
 
static int clear_coverage_i (st_data_t key, st_data_t val, st_data_t dummy)
 
static void clear_coverage (void)
 
static void rb_thread_atfork_internal (int(*atfork)(st_data_t, st_data_t, st_data_t))
 
static int terminate_atfork_i (st_data_t key, st_data_t val, st_data_t current_th)
 
void rb_thread_atfork (void)
 
static int terminate_atfork_before_exec_i (st_data_t key, st_data_t val, st_data_t current_th)
 
void rb_thread_atfork_before_exec (void)
 
static size_t thgroup_memsize (const void *ptr)
 
static VALUE thgroup_s_alloc (VALUE klass)
 
static int thgroup_list_i (st_data_t key, st_data_t val, st_data_t data)
 
static VALUE thgroup_list (VALUE group)
 
static VALUE thgroup_enclose (VALUE group)
 
static VALUE thgroup_enclosed_p (VALUE group)
 
static VALUE thgroup_add (VALUE group, VALUE thread)
 
static void mutex_free (void *ptr)
 
static size_t mutex_memsize (const void *ptr)
 
VALUE rb_obj_is_mutex (VALUE obj)
 
static VALUE mutex_alloc (VALUE klass)
 
static VALUE mutex_initialize (VALUE self)
 
VALUE rb_mutex_new (void)
 
VALUE rb_mutex_locked_p (VALUE self)
 
static void mutex_locked (rb_thread_t *th, VALUE self)
 
VALUE rb_mutex_trylock (VALUE self)
 
static int lock_func (rb_thread_t *th, rb_mutex_t *mutex, int timeout_ms)
 
static void lock_interrupt (void *ptr)
 
VALUE rb_mutex_lock (VALUE self)
 
VALUE rb_mutex_owned_p (VALUE self)
 
VALUE rb_mutex_unlock (VALUE self)
 
static VALUE rb_mutex_sleep_forever (VALUE time)
 
static VALUE rb_mutex_wait_for (VALUE time)
 
VALUE rb_mutex_sleep (VALUE self, VALUE timeout)
 
static VALUE mutex_sleep (int argc, VALUE *argv, VALUE self)
 
VALUE rb_mutex_synchronize (VALUE mutex, VALUE(*func)(VALUE arg), VALUE arg)
 
static VALUE rb_mutex_synchronize_m (VALUE self, VALUE args)
 
void rb_mutex_allow_trap (VALUE self, int val)
 
static void thread_shield_mark (void *ptr)
 
static VALUE thread_shield_alloc (VALUE klass)
 
static void rb_thread_shield_waiting_inc (VALUE b)
 
static void rb_thread_shield_waiting_dec (VALUE b)
 
VALUE rb_thread_shield_new (void)
 
VALUE rb_thread_shield_wait (VALUE self)
 
VALUE rb_thread_shield_release (VALUE self)
 
VALUE rb_thread_shield_destroy (VALUE self)
 
static VALUE ident_hash_new (void)
 
ID rb_frame_last_func (void)
 
static VALUE recursive_list_access (VALUE sym)
 
VALUE rb_threadptr_reset_recursive_data (rb_thread_t *th)
 
void rb_threadptr_restore_recursive_data (rb_thread_t *th, VALUE old)
 
static VALUE recursive_check (VALUE list, VALUE obj_id, VALUE paired_obj_id)
 
static void recursive_push (VALUE list, VALUE obj, VALUE paired_obj)
 
static int recursive_pop (VALUE list, VALUE obj, VALUE paired_obj)
 
static VALUE exec_recursive_i (RB_BLOCK_CALL_FUNC_ARGLIST(tag, data))
 
static VALUE exec_recursive (VALUE(*func)(VALUE, VALUE, int), VALUE obj, VALUE pairid, VALUE arg, int outer)
 
VALUE rb_exec_recursive (VALUE(*func)(VALUE, VALUE, int), VALUE obj, VALUE arg)
 
VALUE rb_exec_recursive_paired (VALUE(*func)(VALUE, VALUE, int), VALUE obj, VALUE paired_obj, VALUE arg)
 
VALUE rb_exec_recursive_outer (VALUE(*func)(VALUE, VALUE, int), VALUE obj, VALUE arg)
 
VALUE rb_exec_recursive_paired_outer (VALUE(*func)(VALUE, VALUE, int), VALUE obj, VALUE paired_obj, VALUE arg)
 
static VALUE rb_thread_backtrace_m (int argc, VALUE *argv, VALUE thval)
 
static VALUE rb_thread_backtrace_locations_m (int argc, VALUE *argv, VALUE thval)
 
void Init_Thread (void)
 
int ruby_native_thread_p (void)
 
static int check_deadlock_i (st_data_t key, st_data_t val, int *found)
 
static void update_coverage (rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
 
VALUE rb_get_coverages (void)
 
void rb_set_coverages (VALUE coverages)
 
void rb_reset_coverages (void)
 
VALUE rb_uninterruptible (VALUE(*b_proc)(ANYARGS), VALUE data)
 
void ruby_kill (rb_pid_t pid, int sig)
 

Variables

VALUE rb_cMutex
 
VALUE rb_cThreadShield
 
static VALUE sym_immediate
 
static VALUE sym_on_blocking
 
static VALUE sym_never
 
static ID id_locals
 
static volatile int system_working = 1
 
static const rb_data_type_t thgroup_data_type
 
static const rb_data_type_t mutex_data_type
 
static const rb_thread_tpatrol_thread = NULL
 
static const rb_data_type_t thread_shield_data_type
 
static ID recursive_key
 
const struct st_hash_type st_hashtype_num
 

Macro Definition Documentation

◆ __USE_FORTIFY_LEVEL

#define __USE_FORTIFY_LEVEL   0

Definition at line 56 of file thread.c.

◆ BLOCKING_REGION

#define BLOCKING_REGION (   exec,
  ubf,
  ubfarg,
  fail_if_interrupted 
)
Value:
do { \
rb_thread_t *__th = GET_THREAD(); \
struct rb_blocking_region_buffer __region; \
if (blocking_region_begin(__th, &__region, (ubf), (ubfarg), fail_if_interrupted) || \
/* always return true unless fail_if_interrupted */ \
!only_if_constant(fail_if_interrupted, TRUE)) { \
exec; \
blocking_region_end(__th, &__region); \
}; \
} while(0)
static int blocking_region_begin(rb_thread_t *th, struct rb_blocking_region_buffer *region, rb_unblock_function_t *ubf, void *arg, int fail_if_interrupted)
Definition: thread.c:1204
#define only_if_constant(expr, notconst)
Definition: thread.c:149
#define TRUE
Definition: nkf.h:175
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:929

Definition at line 151 of file thread.c.

Referenced by call_without_gvl(), do_select(), and rb_thread_io_blocking_region().

◆ closed_stream_error

#define closed_stream_error   GET_VM()->special_exceptions[ruby_error_closed_stream]

Definition at line 97 of file thread.c.

Referenced by Init_Thread().

◆ DELAY_INFTY

#define DELAY_INFTY   1E30

Definition at line 752 of file thread.c.

Referenced by thread_join(), thread_join_m(), and thread_value().

◆ eKillSignal

#define eKillSignal   INT2FIX(0)

Definition at line 93 of file thread.c.

Referenced by rb_thread_kill(), and rb_threadptr_execute_interrupts().

◆ eTerminateSignal

#define eTerminateSignal   INT2FIX(1)

Definition at line 94 of file thread.c.

Referenced by rb_threadptr_execute_interrupts(), and terminate_i().

◆ GetMutexPtr

#define GetMutexPtr (   obj,
  tobj 
)    TypedData_Get_Struct((obj), rb_mutex_t, &mutex_data_type, (tobj))

◆ GetThreadShieldPtr

#define GetThreadShieldPtr (   obj)    ((VALUE)rb_check_typeddata((obj), &thread_shield_data_type))

◆ GVL_UNLOCK_BEGIN

#define GVL_UNLOCK_BEGIN ( )
Value:
do { \
rb_thread_t *_th_stored = GET_THREAD(); \
RB_GC_SAVE_MACHINE_CONTEXT(_th_stored); \
gvl_release(_th_stored->vm);
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:929

Definition at line 136 of file thread.c.

Referenced by rb_mutex_lock(), and ruby_kill().

◆ GVL_UNLOCK_END

#define GVL_UNLOCK_END ( )
Value:
gvl_acquire(_th_stored->vm, _th_stored); \
rb_thread_set_current(_th_stored); \
} while(0)

Definition at line 141 of file thread.c.

Referenced by rb_mutex_lock(), and ruby_kill().

◆ mutex_mark

#define mutex_mark   NULL

Definition at line 4189 of file thread.c.

◆ OBJ_ID_EQL

#define OBJ_ID_EQL (   obj_id,
  other 
)    ((obj_id) == (other))

Referenced by recursive_check().

◆ only_if_constant

#define only_if_constant (   expr,
  notconst 
)    notconst

Definition at line 149 of file thread.c.

◆ rb_fd_rcopy

#define rb_fd_rcopy (   d,
 
)    (*(d) = *(s))

Definition at line 3422 of file thread.c.

Referenced by rb_thread_select().

◆ RB_GC_SAVE_MACHINE_CONTEXT

#define RB_GC_SAVE_MACHINE_CONTEXT (   th)
Value:
do { \
FLUSH_REGISTER_WINDOWS; \
RB_GC_SAVE_MACHINE_REGISTER_STACK(th); \
setjmp((th)->machine.regs); \
SET_MACHINE_STACK_END(&(th)->machine.stack_end); \
} while (0)

Definition at line 128 of file thread.c.

Referenced by blocking_region_begin(), and rb_thread_schedule_limits().

◆ RB_GC_SAVE_MACHINE_REGISTER_STACK

#define RB_GC_SAVE_MACHINE_REGISTER_STACK (   th)

Definition at line 126 of file thread.c.

◆ rb_intern

#define rb_intern (   str)    rb_intern_const(str)

Referenced by Init_thread(), and Init_Thread().

◆ rb_thread_shield_waiting

#define rb_thread_shield_waiting (   b)    (int)((RBASIC(b)->flags&THREAD_SHIELD_WAITING_MASK)>>THREAD_SHIELD_WAITING_SHIFT)

◆ RUBY_THREAD_PRIORITY_MAX

#define RUBY_THREAD_PRIORITY_MAX   3

Definition at line 69 of file thread.c.

Referenced by rb_thread_priority_set().

◆ RUBY_THREAD_PRIORITY_MIN

#define RUBY_THREAD_PRIORITY_MIN   -3

Definition at line 70 of file thread.c.

Referenced by rb_thread_priority_set().

◆ THREAD_DEBUG

#define THREAD_DEBUG   0

Definition at line 74 of file thread.c.

◆ thread_debug

#define thread_debug   if(0)printf

◆ THREAD_SHIELD_WAITING_MASK

Definition at line 4676 of file thread.c.

Referenced by rb_thread_shield_waiting_dec(), and rb_thread_shield_waiting_inc().

◆ THREAD_SHIELD_WAITING_SHIFT

#define THREAD_SHIELD_WAITING_SHIFT   (FL_USHIFT)

Definition at line 4677 of file thread.c.

Referenced by rb_thread_shield_waiting_dec(), and rb_thread_shield_waiting_inc().

◆ thread_start_func_2

#define thread_start_func_2 (   th,
  st,
  rst 
)    thread_start_func_2(th, st)

Definition at line 214 of file thread.c.

◆ THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION

#define THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION

Definition at line 107 of file thread.c.

◆ USE_NATIVE_THREAD_PRIORITY

#define USE_NATIVE_THREAD_PRIORITY   0

Definition at line 68 of file thread.c.

Typedef Documentation

◆ rb_mutex_t

typedef struct rb_mutex_struct rb_mutex_t

Enumeration Type Documentation

◆ handle_interrupt_timing

Enumerator
INTERRUPT_NONE 
INTERRUPT_IMMEDIATE 
INTERRUPT_ON_BLOCKING 
INTERRUPT_NEVER 

Definition at line 1554 of file thread.c.

Function Documentation

◆ blocking_region_begin()

static int blocking_region_begin ( rb_thread_t th,
struct rb_blocking_region_buffer region,
rb_unblock_function_t ubf,
void *  arg,
int  fail_if_interrupted 
)
inlinestatic

◆ blocking_region_end()

static void blocking_region_end ( rb_thread_t th,
struct rb_blocking_region_buffer region 
)
inlinestatic

◆ call_without_gvl()

static void* call_without_gvl ( void *(*)(void *)  func,
void *  data1,
rb_unblock_function_t ubf,
void *  data2,
int  fail_if_interrupted 
)
static

◆ check_deadlock_i()

static int check_deadlock_i ( st_data_t  key,
st_data_t  val,
int *  found 
)
static

◆ clear_coverage()

static void clear_coverage ( void  )
static

◆ clear_coverage_i()

static int clear_coverage_i ( st_data_t  key,
st_data_t  val,
st_data_t  dummy 
)
static

Definition at line 3881 of file thread.c.

References INT2FIX, Qnil, RARRAY_AREF, RARRAY_ASET, RARRAY_LEN, ST_CONTINUE, and val.

Referenced by clear_coverage().

◆ do_select()

static int do_select ( int  n,
rb_fdset_t read,
rb_fdset_t write,
rb_fdset_t except,
struct timeval timeout 
)
static

◆ double2timeval()

static struct timeval double2timeval ( double  d)
static

Definition at line 964 of file thread.c.

References timeval::tv_sec, timeval::tv_usec, and TYPEOF_TIMEVAL_TV_SEC.

Referenced by sleep_wait_for_interrupt().

◆ exec_recursive()

static VALUE exec_recursive ( VALUE(*)(VALUE, VALUE, int)  func,
VALUE  obj,
VALUE  pairid,
VALUE  arg,
int  outer 
)
static

◆ exec_recursive_i()

static VALUE exec_recursive_i ( RB_BLOCK_CALL_FUNC_ARGLIST(tag, data)  )
static

◆ getclockofday()

static void getclockofday ( struct timeval tp)
static

◆ handle_interrupt_arg_check_i()

static int handle_interrupt_arg_check_i ( VALUE  key,
VALUE  val 
)
static

◆ ident_hash_new()

static VALUE ident_hash_new ( void  )
static

Definition at line 4763 of file thread.c.

References hash(), rb_hash_new(), rb_hash_tbl_raw(), st_hashtype_num, and st_table::type.

Referenced by recursive_list_access().

◆ init_set_fd()

static rb_fdset_t* init_set_fd ( int  fd,
rb_fdset_t fds 
)
static

Definition at line 3725 of file thread.c.

References rb_fd_init, and rb_fd_set.

Referenced by rb_wait_for_single_fd().

◆ Init_Thread()

void Init_Thread ( void  )

Definition at line 5079 of file thread.c.

References closed_stream_error, GET_THREAD(), ID2SYM, id_locals, rb_thread_struct::interrupt_cond, rb_thread_struct::interrupt_lock, rb_thread_struct::interrupt_mask, mutex_alloc(), mutex_initialize(), mutex_sleep(), OBJ_FREEZE, OBJ_TAINT, rb_thread_struct::pending_interrupt_mask_stack, rb_thread_struct::pending_interrupt_queue, rb_thread_struct::pending_interrupt_queue_checked, rb_ary_tmp_new(), rb_cMutex, rb_cObject, rb_cThread, rb_define_alloc_func(), rb_define_class(), rb_define_const(), rb_define_method(), rb_define_singleton_method(), rb_eIOError, rb_eStandardError, rb_eThreadError, rb_exc_new2, rb_intern, rb_mutex_lock(), rb_mutex_locked_p(), rb_mutex_owned_p(), rb_mutex_synchronize_m(), rb_mutex_trylock(), rb_mutex_unlock(), rb_obj_alloc(), rb_thread_abort_exc(), rb_thread_abort_exc_set(), rb_thread_alive_p(), rb_thread_aref(), rb_thread_aset(), rb_thread_backtrace_locations_m(), rb_thread_backtrace_m(), rb_thread_exit(), rb_thread_group(), rb_thread_inspect(), rb_thread_key_p(), rb_thread_keys(), rb_thread_kill(), rb_thread_list(), rb_thread_pending_interrupt_p(), rb_thread_priority(), rb_thread_priority_set(), rb_thread_run(), rb_thread_s_abort_exc(), rb_thread_s_abort_exc_set(), rb_thread_s_handle_interrupt(), rb_thread_s_kill(), rb_thread_s_main(), rb_thread_s_pending_interrupt_p(), rb_thread_safe_level(), rb_thread_stop(), rb_thread_stop_p(), rb_thread_variable_get(), rb_thread_variable_p(), rb_thread_variable_set(), rb_thread_variables(), rb_thread_wakeup(), recursive_key, sym_immediate, sym_never, sym_on_blocking, rb_thread_struct::thgroup, thgroup_add(), rb_vm_struct::thgroup_default, thgroup_enclose(), thgroup_enclosed_p(), thgroup_list(), thgroup_s_alloc(), rb_vm_struct::thread_destruct_lock, thread_initialize(), thread_join_m(), thread_raise_m(), thread_s_current(), thread_s_new(), thread_s_pass(), thread_start(), thread_value(), and rb_thread_struct::vm.

◆ keys_i()

static int keys_i ( VALUE  key,
VALUE  value,
VALUE  ary 
)
static

Definition at line 3032 of file thread.c.

References key, rb_ary_push(), and ST_CONTINUE.

Referenced by rb_thread_variables().

◆ lock_func()

static int lock_func ( rb_thread_t th,
rb_mutex_t mutex,
int  timeout_ms 
)
static

◆ lock_interrupt()

static void lock_interrupt ( void *  ptr)
static

Definition at line 4353 of file thread.c.

References rb_mutex_struct::cond, rb_mutex_struct::cond_waiting, and rb_mutex_struct::lock.

Referenced by rb_mutex_lock().

◆ mutex_alloc()

static VALUE mutex_alloc ( VALUE  klass)
static

◆ mutex_free()

static void mutex_free ( void *  ptr)
static

◆ mutex_initialize()

static VALUE mutex_initialize ( VALUE  self)
static

Definition at line 4249 of file thread.c.

Referenced by Init_Thread().

◆ mutex_locked()

static void mutex_locked ( rb_thread_t th,
VALUE  self 
)
static

◆ mutex_memsize()

static size_t mutex_memsize ( const void *  ptr)
static

Definition at line 4208 of file thread.c.

◆ mutex_sleep()

static VALUE mutex_sleep ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 4606 of file thread.c.

References argc, argv, rb_mutex_sleep(), and rb_scan_args().

Referenced by Init_Thread().

◆ NOINLINE()

NOINLINE ( static int   thread_start_func_2rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start)

◆ rb_check_deadlock()

static void rb_check_deadlock ( rb_vm_t vm)
static

◆ rb_exec_recursive()

VALUE rb_exec_recursive ( VALUE(*)(VALUE, VALUE, int)  func,
VALUE  obj,
VALUE  arg 
)

◆ rb_exec_recursive_outer()

VALUE rb_exec_recursive_outer ( VALUE(*)(VALUE, VALUE, int)  func,
VALUE  obj,
VALUE  arg 
)

Definition at line 5015 of file thread.c.

References exec_recursive_params::arg, exec_recursive(), func, and exec_recursive_params::obj.

Referenced by rb_hash().

◆ rb_exec_recursive_paired()

VALUE rb_exec_recursive_paired ( VALUE(*)(VALUE, VALUE, int)  func,
VALUE  obj,
VALUE  paired_obj,
VALUE  arg 
)

◆ rb_exec_recursive_paired_outer()

VALUE rb_exec_recursive_paired_outer ( VALUE(*)(VALUE, VALUE, int)  func,
VALUE  obj,
VALUE  paired_obj,
VALUE  arg 
)

Definition at line 5027 of file thread.c.

References exec_recursive_params::arg, exec_recursive(), func, exec_recursive_params::obj, and rb_obj_id().

Referenced by cmp_eq().

◆ rb_frame_last_func()

ID rb_frame_last_func ( void  )

◆ rb_gc_set_stack_end()

void rb_gc_set_stack_end ( VALUE **  stack_end_p)

Definition at line 3806 of file thread.c.

◆ rb_get_coverages()

VALUE rb_get_coverages ( void  )

Definition at line 5297 of file thread.c.

References GET_VM.

Referenced by clear_coverage(), coverage(), prepare_iseq_build(), rb_coverage_result(), and rb_coverage_start().

◆ rb_mutex_abandon_all()

static void rb_mutex_abandon_all ( rb_mutex_t mutexes)
static

◆ rb_mutex_abandon_keeping_mutexes()

static void rb_mutex_abandon_keeping_mutexes ( rb_thread_t th)
static

Definition at line 4521 of file thread.c.

References rb_thread_struct::keeping_mutexes, NULL, and rb_mutex_abandon_all().

Referenced by terminate_atfork_i().

◆ rb_mutex_abandon_locking_mutex()

static void rb_mutex_abandon_locking_mutex ( rb_thread_t th)
static

◆ rb_mutex_allow_trap()

void rb_mutex_allow_trap ( VALUE  self,
int  val 
)

Definition at line 4646 of file thread.c.

References rb_mutex_struct::allow_trap, GetMutexPtr, and val.

Referenced by io_binwrite().

◆ rb_mutex_lock()

VALUE rb_mutex_lock ( VALUE  self)

◆ rb_mutex_locked_p()

VALUE rb_mutex_locked_p ( VALUE  self)

Definition at line 4267 of file thread.c.

References GetMutexPtr, Qfalse, Qtrue, and rb_mutex_struct::th.

Referenced by Init_Thread().

◆ rb_mutex_new()

VALUE rb_mutex_new ( void  )

Definition at line 4255 of file thread.c.

References mutex_alloc(), and rb_cMutex.

Referenced by io_binwrite().

◆ rb_mutex_owned_p()

VALUE rb_mutex_owned_p ( VALUE  self)

Definition at line 4453 of file thread.c.

References GET_THREAD(), GetMutexPtr, Qfalse, Qtrue, and rb_mutex_struct::th.

Referenced by finish_writeconv(), Init_Thread(), and io_flush_buffer().

◆ rb_mutex_sleep()

VALUE rb_mutex_sleep ( VALUE  self,
VALUE  timeout 
)

◆ rb_mutex_sleep_forever()

static VALUE rb_mutex_sleep_forever ( VALUE  time)
static

Definition at line 4556 of file thread.c.

References GET_THREAD(), Qnil, and sleep_forever().

Referenced by rb_mutex_sleep().

◆ rb_mutex_synchronize()

VALUE rb_mutex_synchronize ( VALUE  mutex,
VALUE(*)(VALUE arg)  func,
VALUE  arg 
)

◆ rb_mutex_synchronize_m()

static VALUE rb_mutex_synchronize_m ( VALUE  self,
VALUE  args 
)
static

Definition at line 4637 of file thread.c.

References Qundef, rb_block_given_p(), rb_eThreadError, rb_mutex_synchronize(), rb_raise(), and rb_yield().

Referenced by Init_Thread().

◆ rb_mutex_trylock()

VALUE rb_mutex_trylock ( VALUE  self)

◆ rb_mutex_unlock()

VALUE rb_mutex_unlock ( VALUE  self)

◆ rb_mutex_unlock_th()

static const char * rb_mutex_unlock_th ( rb_mutex_t mutex,
rb_thread_t volatile *  th 
)
static

◆ rb_mutex_wait_for()

static VALUE rb_mutex_wait_for ( VALUE  time)
static

Definition at line 4563 of file thread.c.

References GET_THREAD(), Qnil, sleep_timeval(), and t().

Referenced by rb_mutex_sleep().

◆ rb_nativethread_lock_destroy()

void rb_nativethread_lock_destroy ( rb_nativethread_lock_t lock)

Definition at line 286 of file thread.c.

Referenced by ossl_dyn_destroy_callback().

◆ rb_nativethread_lock_initialize()

void rb_nativethread_lock_initialize ( rb_nativethread_lock_t lock)

Definition at line 280 of file thread.c.

Referenced by Init_ossl_locks(), and ossl_dyn_create_callback().

◆ rb_nativethread_lock_lock()

void rb_nativethread_lock_lock ( rb_nativethread_lock_t lock)

Definition at line 292 of file thread.c.

Referenced by ossl_lock_unlock().

◆ rb_nativethread_lock_unlock()

void rb_nativethread_lock_unlock ( rb_nativethread_lock_t lock)

Definition at line 298 of file thread.c.

Referenced by ossl_lock_unlock().

◆ rb_obj_is_mutex()

VALUE rb_obj_is_mutex ( VALUE  obj)

Definition at line 4220 of file thread.c.

References mutex_data_type, Qfalse, Qtrue, and rb_typeddata_is_kind_of().

Referenced by rb_objspace_call_finalizer().

◆ rb_reset_coverages()

void rb_reset_coverages ( void  )

Definition at line 5310 of file thread.c.

References GET_VM, Qfalse, rb_remove_event_hook(), and update_coverage().

Referenced by rb_coverage_result().

◆ rb_set_coverages()

void rb_set_coverages ( VALUE  coverages)

Definition at line 5303 of file thread.c.

References GET_VM, Qnil, rb_add_event_hook(), RUBY_EVENT_COVERAGE, and update_coverage().

Referenced by rb_coverage_start().

◆ rb_thread_abort_exc()

static VALUE rb_thread_abort_exc ( VALUE  thread)
static

Definition at line 2525 of file thread.c.

References rb_thread_struct::abort_on_exception, GetThreadPtr, Qfalse, and Qtrue.

Referenced by Init_Thread().

◆ rb_thread_abort_exc_set()

static VALUE rb_thread_abort_exc_set ( VALUE  thread,
VALUE  val 
)
static

Definition at line 2549 of file thread.c.

References rb_thread_struct::abort_on_exception, GetThreadPtr, RTEST, and val.

Referenced by Init_Thread().

◆ rb_thread_alive_p()

static VALUE rb_thread_alive_p ( VALUE  thread)
static

Definition at line 2672 of file thread.c.

References GetThreadPtr, Qfalse, Qtrue, and rb_threadptr_dead().

Referenced by Init_Thread().

◆ rb_thread_alone()

int rb_thread_alone ( void  )

◆ rb_thread_aref()

static VALUE rb_thread_aref ( VALUE  thread,
VALUE  key 
)
static

Definition at line 2833 of file thread.c.

References key, Qnil, rb_check_id(), and rb_thread_local_aref().

Referenced by Init_Thread().

◆ rb_thread_aset()

static VALUE rb_thread_aset ( VALUE  self,
VALUE  id,
VALUE  val 
)
static

Definition at line 2884 of file thread.c.

References rb_thread_local_aset(), rb_to_id(), and val.

Referenced by Init_Thread().

◆ rb_thread_atfork()

void rb_thread_atfork ( void  )

◆ rb_thread_atfork_before_exec()

void rb_thread_atfork_before_exec ( void  )

Definition at line 3958 of file thread.c.

References rb_thread_atfork_internal(), and terminate_atfork_before_exec_i().

◆ rb_thread_atfork_internal()

static void rb_thread_atfork_internal ( int(*)(st_data_t, st_data_t, st_data_t atfork)
static

◆ rb_thread_backtrace_locations_m()

static VALUE rb_thread_backtrace_locations_m ( int  argc,
VALUE argv,
VALUE  thval 
)
static

Definition at line 5058 of file thread.c.

References argc, argv, and rb_vm_thread_backtrace_locations().

Referenced by Init_Thread().

◆ rb_thread_backtrace_m()

static VALUE rb_thread_backtrace_m ( int  argc,
VALUE argv,
VALUE  thval 
)
static

Definition at line 5041 of file thread.c.

References argc, argv, and rb_vm_thread_backtrace().

Referenced by Init_Thread().

◆ rb_thread_blocking_region()

VALUE rb_thread_blocking_region ( rb_blocking_function_t func,
void *  data1,
rb_unblock_function_t ubf,
void *  data2 
)

Definition at line 1417 of file thread.c.

References f, func, and rb_thread_call_without_gvl().

Referenced by rb_waitpid().

◆ rb_thread_blocking_region_begin()

struct rb_blocking_region_buffer* rb_thread_blocking_region_begin ( void  )

Definition at line 1236 of file thread.c.

References ALLOC, blocking_region_begin(), FALSE, and GET_THREAD().

◆ rb_thread_blocking_region_end()

void rb_thread_blocking_region_end ( struct rb_blocking_region_buffer region)

Definition at line 1245 of file thread.c.

References blocking_region_end(), errno, RUBY_VM_CHECK_INTS_BLOCKING, and xfree().

◆ rb_thread_call_with_gvl()

void* rb_thread_call_with_gvl ( void *(*)(void *)  func,
void *  data1 
)

◆ rb_thread_call_without_gvl()

void* rb_thread_call_without_gvl ( void *(*)(void *data)  func,
void *  data1,
rb_unblock_function_t ubf,
void *  data2 
)

Definition at line 1377 of file thread.c.

References call_without_gvl(), FALSE, and func.

Referenced by rb_thread_blocking_region().

◆ rb_thread_call_without_gvl2()

void* rb_thread_call_without_gvl2 ( void *(*)(void *)  func,
void *  data1,
rb_unblock_function_t ubf,
void *  data2 
)

Definition at line 1370 of file thread.c.

References call_without_gvl(), func, and TRUE.

Referenced by io_flush_buffer_async2(), and rb_write_internal2().

◆ rb_thread_check_ints()

void rb_thread_check_ints ( void  )

◆ rb_thread_check_trap_pending()

int rb_thread_check_trap_pending ( void  )

Definition at line 1153 of file thread.c.

References rb_signal_buff_size().

◆ rb_thread_create()

VALUE rb_thread_create ( VALUE(*)(ANYARGS fn,
void *  arg 
)

◆ rb_thread_current()

VALUE rb_thread_current ( void  )

◆ rb_thread_execute_interrupts()

void rb_thread_execute_interrupts ( VALUE  thval)

◆ rb_thread_exit()

static VALUE rb_thread_exit ( void  )
static

Definition at line 2252 of file thread.c.

References GET_THREAD(), rb_thread_kill(), and rb_thread_struct::self.

Referenced by Init_Thread().

◆ rb_thread_fd_close()

void rb_thread_fd_close ( int  fd)

Definition at line 2135 of file thread.c.

References GET_THREAD(), st_foreach(), and thread_fd_close_i().

Referenced by io_reopen(), and rb_io_close().

◆ rb_thread_fd_select()

int rb_thread_fd_select ( int  max,
rb_fdset_t read,
rb_fdset_t write,
rb_fdset_t except,
struct timeval timeout 
)

◆ rb_thread_fd_writable()

int rb_thread_fd_writable ( int  fd)

Definition at line 3529 of file thread.c.

References rb_thread_wait_fd_rw(), and TRUE.

Referenced by rb_io_wait_writable(), rsock_bsock_send(), and udp_send().

◆ rb_thread_group()

VALUE rb_thread_group ( VALUE  thread)

Definition at line 2570 of file thread.c.

References GetThreadPtr, Qnil, and rb_thread_struct::thgroup.

Referenced by Init_Thread().

◆ rb_thread_inspect()

static VALUE rb_thread_inspect ( VALUE  thread)
static

Definition at line 2738 of file thread.c.

References GetThreadPtr, OBJ_INFECT, rb_obj_classname(), rb_sprintf(), and thread_status_name().

Referenced by Init_Thread().

◆ rb_thread_interrupted()

int rb_thread_interrupted ( VALUE  thval)

Definition at line 1160 of file thread.c.

References GetThreadPtr, and RUBY_VM_INTERRUPTED.

Referenced by maygvl_copy_stream_continue_p().

◆ rb_thread_io_blocking_region()

VALUE rb_thread_io_blocking_region ( rb_blocking_function_t func,
void *  data1,
int  fd 
)

◆ rb_thread_key_p()

static VALUE rb_thread_key_p ( VALUE  self,
VALUE  key 
)
static

Definition at line 2964 of file thread.c.

References GetThreadPtr, key, rb_thread_struct::local_storage, Qfalse, Qtrue, rb_check_id(), and st_lookup().

Referenced by Init_Thread().

◆ rb_thread_keys()

static VALUE rb_thread_keys ( VALUE  self)
static

Definition at line 3019 of file thread.c.

References GetThreadPtr, rb_thread_struct::local_storage, rb_ary_new(), st_foreach(), and thread_keys_i().

Referenced by Init_Thread().

◆ rb_thread_kill()

VALUE rb_thread_kill ( VALUE  thread)

◆ rb_thread_list()

VALUE rb_thread_list ( void  )

Definition at line 2397 of file thread.c.

References GET_THREAD(), rb_ary_new(), st_foreach(), and thread_list_i().

Referenced by Init_Thread().

◆ rb_thread_local_aref()

VALUE rb_thread_local_aref ( VALUE  thread,
ID  id 
)

◆ rb_thread_local_aset()

VALUE rb_thread_local_aset ( VALUE  thread,
ID  id,
VALUE  val 
)

◆ rb_thread_main()

VALUE rb_thread_main ( void  )

◆ rb_thread_pending_interrupt_p()

static VALUE rb_thread_pending_interrupt_p ( int  argc,
VALUE argv,
VALUE  target_thread 
)
static

◆ rb_thread_polling()

void rb_thread_polling ( void  )

◆ rb_thread_priority()

static VALUE rb_thread_priority ( VALUE  thread)
static

Definition at line 3120 of file thread.c.

References GetThreadPtr, INT2NUM, and rb_thread_struct::priority.

Referenced by Init_Thread().

◆ rb_thread_priority_set()

static VALUE rb_thread_priority_set ( VALUE  thread,
VALUE  prio 
)
static

◆ rb_thread_reset_timer_thread()

void rb_thread_reset_timer_thread ( void  )

Definition at line 3868 of file thread.c.

Referenced by after_exec_non_async_signal_safe().

◆ rb_thread_run()

VALUE rb_thread_run ( VALUE  thread)

◆ rb_thread_s_abort_exc()

static VALUE rb_thread_s_abort_exc ( void  )
static

Definition at line 2466 of file thread.c.

References GET_THREAD(), Qfalse, Qtrue, rb_vm_struct::thread_abort_on_exception, and rb_thread_struct::vm.

Referenced by Init_Thread().

◆ rb_thread_s_abort_exc_set()

static VALUE rb_thread_s_abort_exc_set ( VALUE  self,
VALUE  val 
)
static

Definition at line 2502 of file thread.c.

References GET_THREAD(), RTEST, rb_vm_struct::thread_abort_on_exception, val, and rb_thread_struct::vm.

Referenced by Init_Thread().

◆ rb_thread_s_handle_interrupt()

static VALUE rb_thread_s_handle_interrupt ( VALUE  self,
VALUE  mask_arg 
)
static

◆ rb_thread_s_kill()

static VALUE rb_thread_s_kill ( VALUE  obj,
VALUE  th 
)
static

Definition at line 2233 of file thread.c.

References rb_thread_kill().

Referenced by Init_Thread().

◆ rb_thread_s_main()

static VALUE rb_thread_s_main ( VALUE  klass)
static

Definition at line 2439 of file thread.c.

References rb_thread_main().

Referenced by Init_Thread().

◆ rb_thread_s_pending_interrupt_p()

static VALUE rb_thread_s_pending_interrupt_p ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1928 of file thread.c.

References argc, argv, GET_THREAD(), and rb_thread_pending_interrupt_p().

Referenced by Init_Thread().

◆ rb_thread_safe_level()

static VALUE rb_thread_safe_level ( VALUE  thread)
static

Definition at line 2722 of file thread.c.

References GetThreadPtr, INT2NUM, and rb_thread_struct::safe_level.

Referenced by Init_Thread().

◆ rb_thread_schedule()

void rb_thread_schedule ( void  )

◆ rb_thread_schedule_limits()

static void rb_thread_schedule_limits ( unsigned long  limits_us)
static

◆ rb_thread_select()

int rb_thread_select ( int  max,
fd_set *  read,
fd_set *  write,
fd_set *  except,
struct timeval timeout 
)

Definition at line 3536 of file thread.c.

References max(), NULL, rb_fd_copy, rb_fd_init, rb_fd_rcopy, rb_fd_term, and rb_thread_fd_select().

◆ rb_thread_shield_destroy()

VALUE rb_thread_shield_destroy ( VALUE  self)

◆ rb_thread_shield_new()

VALUE rb_thread_shield_new ( void  )

Definition at line 4702 of file thread.c.

References DATA_PTR, rb_cThreadShield, rb_mutex_lock(), and thread_shield_alloc().

Referenced by load_lock().

◆ rb_thread_shield_release()

VALUE rb_thread_shield_release ( VALUE  self)

Definition at line 4738 of file thread.c.

References GetThreadShieldPtr, Qfalse, Qtrue, rb_mutex_unlock(), and rb_thread_shield_waiting.

Referenced by release_thread_shield().

◆ rb_thread_shield_wait()

VALUE rb_thread_shield_wait ( VALUE  self)

◆ rb_thread_shield_waiting_dec()

static void rb_thread_shield_waiting_dec ( VALUE  b)
inlinestatic

◆ rb_thread_shield_waiting_inc()

static void rb_thread_shield_waiting_inc ( VALUE  b)
inlinestatic

◆ rb_thread_sleep()

void rb_thread_sleep ( int  sec)

Definition at line 1168 of file thread.c.

References INT2FIX, rb_thread_wait_for(), and rb_time_timeval().

Referenced by pipe_open().

◆ rb_thread_sleep_deadly()

void rb_thread_sleep_deadly ( void  )

Definition at line 1080 of file thread.c.

References GET_THREAD(), sleep_forever(), and thread_debug.

Referenced by queue_sleep(), rb_szqueue_push(), and rb_thread_stop().

◆ rb_thread_sleep_forever()

void rb_thread_sleep_forever ( void  )

Definition at line 1073 of file thread.c.

References GET_THREAD(), sleep_forever(), and thread_debug.

Referenced by lib_eventloop_core(), rb_f_sleep(), and rb_thread_fd_select().

◆ rb_thread_start_timer_thread()

void rb_thread_start_timer_thread ( void  )

Definition at line 3874 of file thread.c.

References system_working.

Referenced by after_exec_non_async_signal_safe().

◆ rb_thread_status()

static VALUE rb_thread_status ( VALUE  thread)
static

◆ rb_thread_stop()

VALUE rb_thread_stop ( void  )

Definition at line 2346 of file thread.c.

References Qnil, rb_eThreadError, rb_raise(), rb_thread_alone(), and rb_thread_sleep_deadly().

Referenced by Init_Thread().

◆ rb_thread_stop_p()

static VALUE rb_thread_stop_p ( VALUE  thread)
static

◆ rb_thread_stop_timer_thread()

void rb_thread_stop_timer_thread ( int  close_anyway)

Definition at line 3860 of file thread.c.

Referenced by before_exec_non_async_signal_safe(), and ruby_cleanup().

◆ rb_thread_terminate_all()

void rb_thread_terminate_all ( void  )

◆ rb_thread_variable_get()

static VALUE rb_thread_variable_get ( VALUE  thread,
VALUE  key 
)
static

Definition at line 2918 of file thread.c.

References ID2SYM, id_locals, key, Qnil, rb_check_id(), rb_hash_aref(), and rb_ivar_get().

Referenced by Init_Thread().

◆ rb_thread_variable_p()

static VALUE rb_thread_variable_p ( VALUE  thread,
VALUE  key 
)
static

Definition at line 3085 of file thread.c.

References ID2SYM, id_locals, key, Qfalse, Qtrue, rb_check_id(), rb_ivar_get(), RHASH, and st_lookup().

Referenced by Init_Thread().

◆ rb_thread_variable_set()

static VALUE rb_thread_variable_set ( VALUE  thread,
VALUE  id,
VALUE  val 
)
static

Definition at line 2938 of file thread.c.

References ID2SYM, id_locals, OBJ_FROZEN, rb_error_frozen(), rb_hash_aset(), rb_ivar_get(), rb_to_id(), and val.

Referenced by Init_Thread().

◆ rb_thread_variables()

static VALUE rb_thread_variables ( VALUE  thread)
static

Definition at line 3056 of file thread.c.

References id_locals, keys_i(), rb_ary_new(), rb_hash_foreach(), and rb_ivar_get().

Referenced by Init_Thread().

◆ rb_thread_wait_fd()

void rb_thread_wait_fd ( int  fd)

◆ rb_thread_wait_fd_rw()

static void rb_thread_wait_fd_rw ( int  fd,
int  read 
)
static

◆ rb_thread_wait_for()

void rb_thread_wait_for ( struct timeval  time)

◆ rb_thread_wakeup()

VALUE rb_thread_wakeup ( VALUE  thread)

◆ rb_thread_wakeup_alive()

VALUE rb_thread_wakeup_alive ( VALUE  thread)

◆ rb_threadptr_check_signal()

void rb_threadptr_check_signal ( rb_thread_t mth)

Definition at line 3819 of file thread.c.

References rb_signal_buff_size(), and rb_threadptr_trap_interrupt().

Referenced by rb_f_kill(), ruby_cleanup(), and timer_thread_function().

◆ rb_threadptr_dead()

static int rb_threadptr_dead ( rb_thread_t th)
static

◆ rb_threadptr_execute_interrupts()

void rb_threadptr_execute_interrupts ( rb_thread_t th,
int  blocking_timing 
)

◆ rb_threadptr_interrupt()

void rb_threadptr_interrupt ( rb_thread_t th)

◆ rb_threadptr_interrupt_common()

static void rb_threadptr_interrupt_common ( rb_thread_t th,
int  trap 
)
static

◆ rb_threadptr_pending_interrupt_active_p()

int rb_threadptr_pending_interrupt_active_p ( rb_thread_t th)

◆ rb_threadptr_pending_interrupt_check_mask()

static enum handle_interrupt_timing rb_threadptr_pending_interrupt_check_mask ( rb_thread_t th,
VALUE  err 
)
static

◆ rb_threadptr_pending_interrupt_clear()

void rb_threadptr_pending_interrupt_clear ( rb_thread_t th)

Definition at line 1542 of file thread.c.

References rb_thread_struct::pending_interrupt_queue, and rb_ary_clear().

Referenced by rb_threadptr_to_kill().

◆ rb_threadptr_pending_interrupt_deque()

static VALUE rb_threadptr_pending_interrupt_deque ( rb_thread_t th,
enum handle_interrupt_timing  timing 
)
static

◆ rb_threadptr_pending_interrupt_empty_p()

static int rb_threadptr_pending_interrupt_empty_p ( rb_thread_t th)
static

◆ rb_threadptr_pending_interrupt_enque()

void rb_threadptr_pending_interrupt_enque ( rb_thread_t th,
VALUE  v 
)

◆ rb_threadptr_pending_interrupt_include_p()

static int rb_threadptr_pending_interrupt_include_p ( rb_thread_t th,
VALUE  err 
)
static

◆ rb_threadptr_raise()

static VALUE rb_threadptr_raise ( rb_thread_t th,
int  argc,
VALUE argv 
)
static

◆ rb_threadptr_ready()

static void rb_threadptr_ready ( rb_thread_t th)
static

Definition at line 2038 of file thread.c.

References rb_threadptr_interrupt().

Referenced by rb_thread_wakeup_alive().

◆ rb_threadptr_reset_raised()

int rb_threadptr_reset_raised ( rb_thread_t th)

◆ rb_threadptr_reset_recursive_data()

VALUE rb_threadptr_reset_recursive_data ( rb_thread_t th)

◆ rb_threadptr_restore_recursive_data()

void rb_threadptr_restore_recursive_data ( rb_thread_t th,
VALUE  old 
)

Definition at line 4807 of file thread.c.

References recursive_key, and threadptr_local_aset().

Referenced by rb_threadptr_exec_event_hooks_orig().

◆ rb_threadptr_set_raised()

int rb_threadptr_set_raised ( rb_thread_t th)

◆ rb_threadptr_signal_exit()

void rb_threadptr_signal_exit ( rb_thread_t th)

◆ rb_threadptr_signal_raise()

void rb_threadptr_signal_raise ( rb_thread_t th,
int  sig 
)

◆ rb_threadptr_to_kill()

static void rb_threadptr_to_kill ( rb_thread_t th)
static

◆ rb_threadptr_trap_interrupt()

void rb_threadptr_trap_interrupt ( rb_thread_t th)

Definition at line 365 of file thread.c.

References rb_threadptr_interrupt_common().

Referenced by rb_threadptr_check_signal().

◆ rb_threadptr_unlock_all_locking_mutexes()

void rb_threadptr_unlock_all_locking_mutexes ( rb_thread_t th)

◆ rb_uninterruptible()

VALUE rb_uninterruptible ( VALUE(*)(ANYARGS b_proc,
VALUE  data 
)

◆ rb_vm_gvl_destroy()

void rb_vm_gvl_destroy ( rb_vm_t vm)

Definition at line 272 of file thread.c.

References rb_vm_struct::thread_destruct_lock.

Referenced by ruby_vm_destruct().

◆ rb_wait_for_single_fd()

int rb_wait_for_single_fd ( int  fd,
int  events,
struct timeval tv 
)

◆ recursive_check()

static VALUE recursive_check ( VALUE  list,
VALUE  obj_id,
VALUE  paired_obj_id 
)
static

Definition at line 4819 of file thread.c.

References list, NIL_P, OBJ_ID_EQL, Qfalse, Qtrue, Qundef, rb_hash_lookup, rb_hash_lookup2(), RB_TYPE_P, and T_HASH.

Referenced by exec_recursive().

◆ recursive_list_access()

static VALUE recursive_list_access ( VALUE  sym)
static

◆ recursive_pop()

static int recursive_pop ( VALUE  list,
VALUE  obj,
VALUE  paired_obj 
)
static

Definition at line 4884 of file thread.c.

References list, Qundef, rb_hash_delete(), rb_hash_lookup2(), RB_TYPE_P, RHASH_EMPTY_P, and T_HASH.

Referenced by exec_recursive().

◆ recursive_push()

static void recursive_push ( VALUE  list,
VALUE  obj,
VALUE  paired_obj 
)
static

Definition at line 4854 of file thread.c.

References list, Qtrue, Qundef, rb_hash_aset(), rb_hash_lookup2(), rb_hash_new(), RB_TYPE_P, and T_HASH.

Referenced by exec_recursive().

◆ remove_from_join_list()

static VALUE remove_from_join_list ( VALUE  arg)
static

◆ reset_unblock_function()

static void reset_unblock_function ( rb_thread_t th,
const struct rb_unblock_callback old 
)
static

Definition at line 333 of file thread.c.

References rb_thread_struct::interrupt_lock, and rb_thread_struct::unblock.

Referenced by blocking_region_end(), and rb_mutex_lock().

◆ ruby_kill()

void ruby_kill ( rb_pid_t  pid,
int  sig 
)

◆ ruby_native_thread_p()

int ruby_native_thread_p ( void  )

Definition at line 5200 of file thread.c.

◆ ruby_thread_has_gvl_p()

int ruby_thread_has_gvl_p ( void  )

◆ ruby_thread_init_stack()

void ruby_thread_init_stack ( rb_thread_t th)

Definition at line 497 of file thread.c.

References rb_mutex_struct::th.

Referenced by Init_BareVM().

◆ ruby_thread_stack_overflow()

void ruby_thread_stack_overflow ( rb_thread_t th)

◆ select_single()

static VALUE select_single ( VALUE  ptr)
static

◆ select_single_cleanup()

static VALUE select_single_cleanup ( VALUE  ptr)
static

Definition at line 3767 of file thread.c.

References select_args::except, rb_fd_term, select_args::read, and select_args::write.

Referenced by rb_wait_for_single_fd().

◆ set_unblock_function()

static int set_unblock_function ( rb_thread_t th,
rb_unblock_function_t func,
void *  arg,
struct rb_unblock_callback old,
int  fail_if_interrupted 
)
static

◆ sleep_for_polling()

static void sleep_for_polling ( rb_thread_t th)
static

Definition at line 1110 of file thread.c.

References sleep_timeval(), timeval::tv_sec, and timeval::tv_usec.

Referenced by rb_thread_polling().

◆ sleep_forever()

static void sleep_forever ( rb_thread_t th,
int  nodeadlock,
int  spurious_check 
)
static

◆ sleep_timeval()

static void sleep_timeval ( rb_thread_t th,
struct timeval  time,
int  spurious_check 
)
static

◆ sleep_wait_for_interrupt()

static void sleep_wait_for_interrupt ( rb_thread_t th,
double  sleepsec,
int  spurious_check 
)
static

Definition at line 1104 of file thread.c.

References double2timeval(), and sleep_timeval().

Referenced by thread_join_sleep().

◆ st_delete_wrap()

static void st_delete_wrap ( st_table table,
st_data_t  key 
)
inlinestatic

Definition at line 100 of file thread.c.

References key, and st_delete().

Referenced by thread_start_func_2(), and threadptr_local_aset().

◆ terminate_atfork_before_exec_i()

static int terminate_atfork_before_exec_i ( st_data_t  key,
st_data_t  val,
st_data_t  current_th 
)
static

Definition at line 3945 of file thread.c.

References GetThreadPtr, key, ST_CONTINUE, and thread_cleanup_func_before_exec().

Referenced by rb_thread_atfork_before_exec().

◆ terminate_atfork_i()

static int terminate_atfork_i ( st_data_t  key,
st_data_t  val,
st_data_t  current_th 
)
static

◆ terminate_i()

static int terminate_i ( st_data_t  key,
st_data_t  val,
rb_thread_t main_thread 
)
static

◆ thgroup_add()

static VALUE thgroup_add ( VALUE  group,
VALUE  thread 
)
static

◆ thgroup_enclose()

static VALUE thgroup_enclose ( VALUE  group)
static

Definition at line 4071 of file thread.c.

References thgroup::enclosed, thgroup::group, thgroup_data_type, and TypedData_Get_Struct.

Referenced by Init_Thread().

◆ thgroup_enclosed_p()

static VALUE thgroup_enclosed_p ( VALUE  group)
static

Definition at line 4090 of file thread.c.

References thgroup::enclosed, thgroup::group, Qfalse, Qtrue, thgroup_data_type, and TypedData_Get_Struct.

Referenced by Init_Thread().

◆ thgroup_list()

static VALUE thgroup_list ( VALUE  group)
static

◆ thgroup_list_i()

static int thgroup_list_i ( st_data_t  key,
st_data_t  val,
st_data_t  data 
)
static

◆ thgroup_memsize()

static size_t thgroup_memsize ( const void *  ptr)
static

Definition at line 3969 of file thread.c.

◆ thgroup_s_alloc()

static VALUE thgroup_s_alloc ( VALUE  klass)
static

Definition at line 4000 of file thread.c.

References thgroup::enclosed, thgroup::group, thgroup_data_type, and TypedData_Make_Struct.

Referenced by Init_Thread().

◆ thread_cleanup_func()

static void thread_cleanup_func ( void *  th_ptr,
int  atfork 
)
static

◆ thread_cleanup_func_before_exec()

static void thread_cleanup_func_before_exec ( void *  th_ptr)
static

◆ thread_create_core()

static VALUE thread_create_core ( VALUE  thval,
VALUE  args,
VALUE(*)(ANYARGS fn 
)
static

◆ thread_fd_close_i()

static int thread_fd_close_i ( st_data_t  key,
st_data_t  val,
st_data_t  data 
)
static

◆ thread_initialize()

static VALUE thread_initialize ( VALUE  thread,
VALUE  args 
)
static

◆ thread_join()

static VALUE thread_join ( rb_thread_t target_th,
double  delay 
)
static

◆ thread_join_m()

static VALUE thread_join_m ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 899 of file thread.c.

References argc, argv, DELAY_INFTY, GetThreadPtr, join_arg::limit, NIL_P, rb_num2dbl(), rb_scan_args(), and thread_join().

Referenced by Init_Thread().

◆ thread_join_sleep()

static VALUE thread_join_sleep ( VALUE  arg)
static

◆ thread_keys_i()

static int thread_keys_i ( ID  key,
VALUE  value,
VALUE  ary 
)
static

Definition at line 2981 of file thread.c.

References ID2SYM, key, rb_ary_push(), and ST_CONTINUE.

Referenced by rb_thread_keys().

◆ thread_list_i()

static int thread_list_i ( st_data_t  key,
st_data_t  val,
void *  data 
)
static

◆ thread_raise_m()

static VALUE thread_raise_m ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 2162 of file thread.c.

References argc, argv, GET_THREAD(), GetThreadPtr, Qnil, rb_threadptr_raise(), and RUBY_VM_CHECK_INTS.

Referenced by Init_Thread().

◆ thread_s_current()

static VALUE thread_s_current ( VALUE  klass)
static

Definition at line 2420 of file thread.c.

References rb_thread_current().

Referenced by Init_Thread().

◆ thread_s_new()

static VALUE thread_s_new ( int  argc,
VALUE argv,
VALUE  klass 
)
static

◆ thread_s_pass()

static VALUE thread_s_pass ( VALUE  klass)
static

Definition at line 1517 of file thread.c.

References Qnil, and rb_thread_schedule().

Referenced by Init_Thread().

◆ thread_shield_alloc()

static VALUE thread_shield_alloc ( VALUE  klass)
static

Definition at line 4670 of file thread.c.

References mutex_alloc(), thread_shield_data_type, and TypedData_Wrap_Struct.

Referenced by rb_thread_shield_new().

◆ thread_shield_mark()

static void thread_shield_mark ( void *  ptr)
static

Definition at line 4658 of file thread.c.

References rb_gc_mark().

◆ thread_start()

static VALUE thread_start ( VALUE  klass,
VALUE  args 
)
static

Definition at line 713 of file thread.c.

References rb_thread_alloc(), and thread_create_core().

Referenced by Init_Thread().

◆ thread_start_func_2()

static int thread_start_func_2 ( rb_thread_t th,
VALUE stack_start,
VALUE register_stack_start 
)
static

◆ thread_status_name()

static const char* thread_status_name ( rb_thread_t th)
static

◆ thread_value()

static VALUE thread_value ( VALUE  self)
static

Definition at line 930 of file thread.c.

References DELAY_INFTY, GetThreadPtr, thread_join(), and rb_thread_struct::value.

Referenced by Init_Thread().

◆ threadptr_get_interrupts()

static rb_atomic_t threadptr_get_interrupts ( rb_thread_t th)
inlinestatic

◆ threadptr_local_aref()

static VALUE threadptr_local_aref ( rb_thread_t th,
ID  id 
)
static

◆ threadptr_local_aset()

static VALUE threadptr_local_aset ( rb_thread_t th,
ID  id,
VALUE  val 
)
static

◆ timeofday()

static double timeofday ( void  )
static

◆ timer_thread_function()

static void timer_thread_function ( void *  arg)
static

◆ update_coverage()

static void update_coverage ( rb_event_flag_t  event,
VALUE  proc,
VALUE  self,
ID  id,
VALUE  klass 
)
static

◆ vm_living_thread_num()

static int vm_living_thread_num ( rb_vm_t vm)
static

Variable Documentation

◆ id_locals

ID id_locals
static

◆ mutex_data_type

const rb_data_type_t mutex_data_type
static
Initial value:
= {
"mutex",
}
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
#define mutex_mark
Definition: thread.c:4189
static size_t mutex_memsize(const void *ptr)
Definition: thread.c:4208
#define NULL
Definition: _sdbm.c:102
static void mutex_free(void *ptr)
Definition: thread.c:4192

Definition at line 4213 of file thread.c.

Referenced by mutex_alloc(), and rb_obj_is_mutex().

◆ patrol_thread

const rb_thread_t* patrol_thread = NULL
static

Definition at line 4367 of file thread.c.

Referenced by rb_check_deadlock(), and rb_mutex_lock().

◆ rb_cMutex

VALUE rb_cMutex

Definition at line 77 of file thread.c.

Referenced by Init_Thread(), and rb_mutex_new().

◆ rb_cThreadShield

VALUE rb_cThreadShield

Definition at line 78 of file thread.c.

Referenced by rb_thread_shield_new().

◆ recursive_key

ID recursive_key
static

◆ st_hashtype_num

const struct st_hash_type st_hashtype_num

Referenced by ident_hash_new().

◆ sym_immediate

VALUE sym_immediate
static

◆ sym_never

VALUE sym_never
static

◆ sym_on_blocking

VALUE sym_on_blocking
static

◆ system_working

volatile int system_working = 1
static

Definition at line 95 of file thread.c.

Referenced by rb_thread_start_timer_thread().

◆ thgroup_data_type

const rb_data_type_t thgroup_data_type
static
Initial value:
= {
"thgroup",
}
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
static size_t thgroup_memsize(const void *ptr)
Definition: thread.c:3969
#define RUBY_TYPED_DEFAULT_FREE
Definition: ruby.h:1011
#define NULL
Definition: _sdbm.c:102

Definition at line 3974 of file thread.c.

Referenced by thgroup_add(), thgroup_enclose(), thgroup_enclosed_p(), and thgroup_s_alloc().

◆ thread_shield_data_type

const rb_data_type_t thread_shield_data_type
static
Initial value:
= {
"thread_shield",
}
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
static void thread_shield_mark(void *ptr)
Definition: thread.c:4658
#define NULL
Definition: _sdbm.c:102

Definition at line 4663 of file thread.c.

Referenced by thread_shield_alloc().