Ruby  2.1.10p492(2016-04-01revision54464)
Data Structures | Macros | Enumerations | Functions | Variables
thread.c File Reference
#include <ruby.h>

Go to the source code of this file.

Data Structures

struct  sleep_call
 
struct  waiting_delete
 

Macros

#define GET_CONDVAR_WAITERS(cv)   get_array((cv), CONDVAR_WAITERS)
 
#define GET_QUEUE_QUE(q)   get_array((q), QUEUE_QUE)
 
#define GET_QUEUE_WAITERS(q)   get_array((q), QUEUE_WAITERS)
 
#define GET_SZQUEUE_WAITERS(q)   get_array((q), SZQUEUE_WAITERS)
 
#define GET_SZQUEUE_MAX(q)   RSTRUCT_GET((q), SZQUEUE_MAX)
 
#define GET_SZQUEUE_ULONGMAX(q)   NUM2ULONG(GET_SZQUEUE_MAX(q))
 
#define UNDER_THREAD   1
 
#define ALIAS_GLOBAL_CONST(name)
 
#define OUTER   rb_cThread
 

Enumerations

enum  { CONDVAR_WAITERS = 0 }
 
enum  { QUEUE_QUE = 0, QUEUE_WAITERS = 1, SZQUEUE_WAITERS = 2, SZQUEUE_MAX = 3 }
 

Functions

static VALUE get_array (VALUE obj, int idx)
 
static VALUE ary_buf_new (void)
 
static void wakeup_first_thread (VALUE list)
 
static void wakeup_all_threads (VALUE list)
 
static VALUE rb_condvar_initialize (VALUE self)
 
static VALUE do_sleep (VALUE args)
 
static VALUE delete_current_thread (VALUE ary)
 
static VALUE rb_condvar_wait (int argc, VALUE *argv, VALUE self)
 
static VALUE rb_condvar_signal (VALUE self)
 
static VALUE rb_condvar_broadcast (VALUE self)
 
static VALUE rb_queue_initialize (VALUE self)
 
static VALUE queue_do_push (VALUE self, VALUE obj)
 
static VALUE rb_queue_push (VALUE self, VALUE obj)
 
static unsigned long queue_length (VALUE self)
 
static unsigned long queue_num_waiting (VALUE self)
 
static VALUE queue_delete_from_waiting (struct waiting_delete *p)
 
static VALUE queue_sleep (VALUE arg)
 
static VALUE queue_do_pop (VALUE self, VALUE should_block)
 
static VALUE queue_pop_should_block (int argc, VALUE *argv)
 
static VALUE rb_queue_pop (int argc, VALUE *argv, VALUE self)
 
static VALUE rb_queue_empty_p (VALUE self)
 
static VALUE rb_queue_clear (VALUE self)
 
static VALUE rb_queue_length (VALUE self)
 
static VALUE rb_queue_num_waiting (VALUE self)
 
static VALUE rb_szqueue_initialize (VALUE self, VALUE vmax)
 
static VALUE rb_szqueue_max_get (VALUE self)
 
static VALUE rb_szqueue_max_set (VALUE self, VALUE vmax)
 
static VALUE rb_szqueue_push (VALUE self, VALUE obj)
 
static VALUE szqueue_do_pop (VALUE self, VALUE should_block)
 
static VALUE rb_szqueue_pop (int argc, VALUE *argv, VALUE self)
 
static VALUE rb_szqueue_clear (VALUE self)
 
static VALUE rb_szqueue_num_waiting (VALUE self)
 
static VALUE undumpable (VALUE obj)
 
void Init_thread (void)
 

Variables

static ID id_sleep
 

Macro Definition Documentation

◆ ALIAS_GLOBAL_CONST

#define ALIAS_GLOBAL_CONST (   name)
Value:
do { \
ID id = rb_intern_const(#name); \
rb_const_set(rb_cObject, id, rb_c##name); \
} \
} while (0)
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1561
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:2133
const char * name
Definition: nkf.c:208
#define rb_intern_const(str)
Definition: ruby.h:1450

Referenced by Init_thread().

◆ GET_CONDVAR_WAITERS

#define GET_CONDVAR_WAITERS (   cv)    get_array((cv), CONDVAR_WAITERS)

Definition at line 14 of file thread.c.

Referenced by rb_condvar_broadcast(), rb_condvar_signal(), and rb_condvar_wait().

◆ GET_QUEUE_QUE

#define GET_QUEUE_QUE (   q)    get_array((q), QUEUE_QUE)

Definition at line 16 of file thread.c.

Referenced by queue_do_pop(), queue_do_push(), queue_length(), rb_queue_clear(), and rb_szqueue_clear().

◆ GET_QUEUE_WAITERS

#define GET_QUEUE_WAITERS (   q)    get_array((q), QUEUE_WAITERS)

Definition at line 17 of file thread.c.

Referenced by queue_do_pop(), queue_do_push(), and queue_num_waiting().

◆ GET_SZQUEUE_MAX

#define GET_SZQUEUE_MAX (   q)    RSTRUCT_GET((q), SZQUEUE_MAX)

Definition at line 19 of file thread.c.

Referenced by rb_szqueue_max_get().

◆ GET_SZQUEUE_ULONGMAX

#define GET_SZQUEUE_ULONGMAX (   q)    NUM2ULONG(GET_SZQUEUE_MAX(q))

Definition at line 20 of file thread.c.

Referenced by rb_szqueue_max_set(), rb_szqueue_push(), and szqueue_do_pop().

◆ GET_SZQUEUE_WAITERS

#define GET_SZQUEUE_WAITERS (   q)    get_array((q), SZQUEUE_WAITERS)

◆ OUTER

#define OUTER   rb_cThread

Referenced by Init_thread().

◆ UNDER_THREAD

#define UNDER_THREAD   1

Definition at line 544 of file thread.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CONDVAR_WAITERS 

Definition at line 3 of file thread.c.

◆ anonymous enum

anonymous enum
Enumerator
QUEUE_QUE 
QUEUE_WAITERS 
SZQUEUE_WAITERS 
SZQUEUE_MAX 

Definition at line 7 of file thread.c.

Function Documentation

◆ ary_buf_new()

static VALUE ary_buf_new ( void  )
static

Definition at line 33 of file thread.c.

References rb_ary_tmp_new().

Referenced by rb_condvar_initialize(), rb_queue_initialize(), and rb_szqueue_initialize().

◆ delete_current_thread()

static VALUE delete_current_thread ( VALUE  ary)
static

Definition at line 119 of file thread.c.

References rb_ary_delete(), and rb_thread_current().

Referenced by rb_condvar_wait().

◆ do_sleep()

static VALUE do_sleep ( VALUE  args)
static

Definition at line 112 of file thread.c.

References id_sleep, sleep_call::mutex, rb_funcall2, and sleep_call::timeout.

Referenced by rb_condvar_wait().

◆ get_array()

static VALUE get_array ( VALUE  obj,
int  idx 
)
static

Definition at line 23 of file thread.c.

References PRIsVALUE, rb_eTypeError, rb_raise(), RB_TYPE_P, RSTRUCT_GET, and T_ARRAY.

◆ Init_thread()

void Init_thread ( void  )

◆ queue_delete_from_waiting()

static VALUE queue_delete_from_waiting ( struct waiting_delete p)
static

Definition at line 261 of file thread.c.

References Qnil, rb_ary_delete(), waiting_delete::th, and waiting_delete::waiting.

Referenced by queue_do_pop(), and rb_szqueue_push().

◆ queue_do_pop()

static VALUE queue_do_pop ( VALUE  self,
VALUE  should_block 
)
static

◆ queue_do_push()

static VALUE queue_do_push ( VALUE  self,
VALUE  obj 
)
static

Definition at line 220 of file thread.c.

References GET_QUEUE_QUE, GET_QUEUE_WAITERS, rb_ary_push(), and wakeup_first_thread().

Referenced by rb_queue_push(), and rb_szqueue_push().

◆ queue_length()

static unsigned long queue_length ( VALUE  self)
static

Definition at line 244 of file thread.c.

References GET_QUEUE_QUE, and RARRAY_LEN.

Referenced by queue_do_pop(), rb_queue_empty_p(), rb_queue_length(), rb_szqueue_push(), and szqueue_do_pop().

◆ queue_num_waiting()

static unsigned long queue_num_waiting ( VALUE  self)
static

Definition at line 250 of file thread.c.

References GET_QUEUE_WAITERS, and RARRAY_LEN.

Referenced by rb_queue_num_waiting(), and rb_szqueue_num_waiting().

◆ queue_pop_should_block()

static VALUE queue_pop_should_block ( int  argc,
VALUE argv 
)
static

Definition at line 293 of file thread.c.

References argc, argv, Qfalse, Qtrue, rb_eArgError, rb_raise(), and RTEST.

Referenced by rb_queue_pop(), and rb_szqueue_pop().

◆ queue_sleep()

static VALUE queue_sleep ( VALUE  arg)
static

Definition at line 268 of file thread.c.

References Qnil, and rb_thread_sleep_deadly().

Referenced by queue_do_pop().

◆ rb_condvar_broadcast()

static VALUE rb_condvar_broadcast ( VALUE  self)
static

Definition at line 171 of file thread.c.

References GET_CONDVAR_WAITERS, and wakeup_all_threads().

Referenced by Init_thread().

◆ rb_condvar_initialize()

static VALUE rb_condvar_initialize ( VALUE  self)
static

Definition at line 98 of file thread.c.

References ary_buf_new(), CONDVAR_WAITERS, and RSTRUCT_SET.

Referenced by Init_thread().

◆ rb_condvar_signal()

static VALUE rb_condvar_signal ( VALUE  self)
static

Definition at line 158 of file thread.c.

References GET_CONDVAR_WAITERS, and wakeup_first_thread().

Referenced by Init_thread().

◆ rb_condvar_wait()

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

◆ rb_queue_clear()

static VALUE rb_queue_clear ( VALUE  self)
static

Definition at line 349 of file thread.c.

References GET_QUEUE_QUE, and rb_ary_clear().

Referenced by Init_thread().

◆ rb_queue_empty_p()

static VALUE rb_queue_empty_p ( VALUE  self)
static

Definition at line 337 of file thread.c.

References Qfalse, Qtrue, and queue_length().

Referenced by Init_thread().

◆ rb_queue_initialize()

static VALUE rb_queue_initialize ( VALUE  self)
static

Definition at line 212 of file thread.c.

References ary_buf_new(), QUEUE_QUE, QUEUE_WAITERS, and RSTRUCT_SET.

Referenced by Init_thread().

◆ rb_queue_length()

static VALUE rb_queue_length ( VALUE  self)
static

Definition at line 365 of file thread.c.

References queue_length(), and ULONG2NUM.

Referenced by Init_thread().

◆ rb_queue_num_waiting()

static VALUE rb_queue_num_waiting ( VALUE  self)
static

Definition at line 378 of file thread.c.

References queue_num_waiting(), and ULONG2NUM.

Referenced by Init_thread().

◆ rb_queue_pop()

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

Definition at line 323 of file thread.c.

References argc, argv, queue_do_pop(), and queue_pop_should_block().

Referenced by Init_thread().

◆ rb_queue_push()

static VALUE rb_queue_push ( VALUE  self,
VALUE  obj 
)
static

Definition at line 238 of file thread.c.

References queue_do_push().

Referenced by Init_thread().

◆ rb_szqueue_clear()

static VALUE rb_szqueue_clear ( VALUE  self)
static

Definition at line 522 of file thread.c.

References GET_QUEUE_QUE, GET_SZQUEUE_WAITERS, rb_ary_clear(), and wakeup_all_threads().

Referenced by Init_thread().

◆ rb_szqueue_initialize()

static VALUE rb_szqueue_initialize ( VALUE  self,
VALUE  vmax 
)
static

◆ rb_szqueue_max_get()

static VALUE rb_szqueue_max_get ( VALUE  self)
static

Definition at line 425 of file thread.c.

References GET_SZQUEUE_MAX.

Referenced by Init_thread().

◆ rb_szqueue_max_set()

static VALUE rb_szqueue_max_set ( VALUE  self,
VALUE  vmax 
)
static

◆ rb_szqueue_num_waiting()

static VALUE rb_szqueue_num_waiting ( VALUE  self)
static

Definition at line 536 of file thread.c.

References GET_SZQUEUE_WAITERS, queue_num_waiting(), RARRAY_LEN, and ULONG2NUM.

Referenced by Init_thread().

◆ rb_szqueue_pop()

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

Definition at line 509 of file thread.c.

References argc, argv, queue_pop_should_block(), and szqueue_do_pop().

Referenced by Init_thread().

◆ rb_szqueue_push()

static VALUE rb_szqueue_push ( VALUE  self,
VALUE  obj 
)
static

◆ szqueue_do_pop()

static VALUE szqueue_do_pop ( VALUE  self,
VALUE  should_block 
)
static

◆ undumpable()

static VALUE undumpable ( VALUE  obj)
static

Definition at line 548 of file thread.c.

References PRIsVALUE, rb_eTypeError, rb_obj_class(), rb_raise(), and UNREACHABLE.

Referenced by Init_thread().

◆ wakeup_all_threads()

static void wakeup_all_threads ( VALUE  list)
static

Definition at line 49 of file thread.c.

References list, RARRAY_AREF, RARRAY_LEN, rb_ary_clear(), and rb_thread_wakeup_alive().

Referenced by rb_condvar_broadcast(), and rb_szqueue_clear().

◆ wakeup_first_thread()

static void wakeup_first_thread ( VALUE  list)
static

Definition at line 39 of file thread.c.

References list, NIL_P, rb_ary_shift(), rb_thread_wakeup_alive(), and RTEST.

Referenced by queue_do_push(), rb_condvar_signal(), and szqueue_do_pop().

Variable Documentation

◆ id_sleep

ID id_sleep
static

Definition at line 109 of file thread.c.

Referenced by do_sleep(), and Init_thread().