Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
thread_sync.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rb_mutex_struct
 
struct  waiting_delete
 
struct  sleep_call
 

Macros

#define GetMutexPtr(obj, tobj)   TypedData_Get_Struct((obj), rb_mutex_t, &mutex_data_type, (tobj))
 
#define mutex_mark   NULL
 
#define QUEUE_CLOSED   FL_USER5
 
#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 GET_CONDVAR_WAITERS(cv)   get_array((cv), CONDVAR_WAITERS)
 
#define ALIAS_GLOBAL_CONST(name)   alias_global_const(#name, rb_c##name)
 

Typedefs

typedef struct rb_mutex_struct rb_mutex_t
 

Enumerations

enum  {
  QUEUE_QUE, QUEUE_WAITERS, SZQUEUE_WAITERS, SZQUEUE_MAX,
  END_QUEUE
}
 
enum  { CONDVAR_WAITERS, END_CONDVAR }
 

Functions

static const char * rb_mutex_unlock_th (rb_mutex_t *mutex, rb_thread_t volatile *th)
 
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 VALUE ary_buf_new (void)
 
static VALUE get_array (VALUE obj, int idx)
 
static void wakeup_first_thread (VALUE list)
 
static void wakeup_all_threads (VALUE list)
 
static unsigned long queue_length (VALUE self)
 
static unsigned long queue_num_waiting (VALUE self)
 
static unsigned long szqueue_num_waiting_producer (VALUE self)
 
static int queue_closed_p (VALUE self)
 
static void raise_closed_queue_error (VALUE self)
 
static VALUE queue_closed_result (VALUE self)
 
static VALUE queue_do_close (VALUE self, int is_szq)
 
static VALUE rb_queue_initialize (VALUE self)
 
static VALUE queue_do_push (VALUE self, VALUE obj)
 
static VALUE rb_queue_close (VALUE self)
 
static VALUE rb_queue_closed_p (VALUE self)
 
static VALUE rb_queue_push (VALUE self, VALUE obj)
 
static VALUE queue_delete_from_waiting (struct waiting_delete *p)
 
static VALUE queue_sleep (VALUE arg)
 
static VALUE queue_do_pop (VALUE self, int should_block)
 
static int queue_pop_should_block (int argc, const 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_close (VALUE self)
 
static VALUE rb_szqueue_max_get (VALUE self)
 
static VALUE rb_szqueue_max_set (VALUE self, VALUE vmax)
 
static int szqueue_push_should_block (int argc, const VALUE *argv)
 
static VALUE rb_szqueue_push (int argc, VALUE *argv, VALUE self)
 
static VALUE szqueue_do_pop (VALUE self, int 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 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 undumpable (VALUE obj)
 
static void alias_global_const (const char *name, VALUE klass)
 
static void Init_thread_sync (void)
 

Variables

static VALUE rb_cMutex
 
static VALUE rb_cQueue
 
static VALUE rb_cSizedQueue
 
static VALUE rb_cConditionVariable
 
static VALUE rb_eClosedQueueError
 
static const rb_data_type_t mutex_data_type
 
static const rb_thread_tpatrol_thread = NULL
 
static ID id_sleep
 

Macro Definition Documentation

◆ ALIAS_GLOBAL_CONST

#define ALIAS_GLOBAL_CONST (   name)    alias_global_const(#name, rb_c##name)

Referenced by Init_thread_sync().

◆ GET_CONDVAR_WAITERS

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

Definition at line 1104 of file thread_sync.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)

◆ GET_QUEUE_WAITERS

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

Definition at line 532 of file thread_sync.c.

Referenced by queue_do_close(), 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 534 of file thread_sync.c.

Referenced by rb_szqueue_max_get().

◆ GET_SZQUEUE_ULONGMAX

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

Definition at line 535 of file thread_sync.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)

◆ GetMutexPtr

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

◆ mutex_mark

#define mutex_mark   NULL

Definition at line 52 of file thread_sync.c.

◆ QUEUE_CLOSED

#define QUEUE_CLOSED   FL_USER5

Definition at line 529 of file thread_sync.c.

Referenced by queue_closed_p(), and queue_do_close().

Typedef Documentation

◆ rb_mutex_t

typedef struct rb_mutex_struct rb_mutex_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
QUEUE_QUE 
QUEUE_WAITERS 
SZQUEUE_WAITERS 
SZQUEUE_MAX 
END_QUEUE 

Definition at line 521 of file thread_sync.c.

◆ anonymous enum

anonymous enum
Enumerator
CONDVAR_WAITERS 
END_CONDVAR 

Definition at line 1099 of file thread_sync.c.

Function Documentation

◆ alias_global_const()

static void alias_global_const ( const char *  name,
VALUE  klass 
)
static

Definition at line 1231 of file thread_sync.c.

References rb_cObject, and rb_define_const().

◆ ary_buf_new()

static VALUE ary_buf_new ( void  )
static

Definition at line 538 of file thread_sync.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 1164 of file thread_sync.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 1157 of file thread_sync.c.

References sleep_call::mutex, rb_funcallv, and sleep_call::timeout.

Referenced by rb_condvar_wait().

◆ get_array()

static VALUE get_array ( VALUE  obj,
int  idx 
)
static

Definition at line 544 of file thread_sync.c.

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

◆ Init_thread_sync()

static void Init_thread_sync ( void  )
static

◆ 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 217 of file thread_sync.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 112 of file thread_sync.c.

Referenced by Init_thread_sync().

◆ 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 71 of file thread_sync.c.

◆ mutex_sleep()

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

Definition at line 471 of file thread_sync.c.

References rb_mutex_sleep(), and rb_scan_args().

Referenced by Init_thread_sync().

◆ queue_closed_p()

static int queue_closed_p ( VALUE  self)
static

◆ queue_closed_result()

static VALUE queue_closed_result ( VALUE  self)
static

Definition at line 610 of file thread_sync.c.

References assert, Qnil, and queue_length().

Referenced by queue_do_pop().

◆ queue_delete_from_waiting()

static VALUE queue_delete_from_waiting ( struct waiting_delete p)
static

Definition at line 767 of file thread_sync.c.

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

Referenced by queue_do_pop(), and rb_szqueue_push().

◆ queue_do_close()

static VALUE queue_do_close ( VALUE  self,
int  is_szq 
)
static

◆ queue_do_pop()

static VALUE queue_do_pop ( VALUE  self,
int  should_block 
)
static

◆ queue_do_push()

static VALUE queue_do_push ( VALUE  self,
VALUE  obj 
)
static

◆ queue_length()

static unsigned long queue_length ( VALUE  self)
static

◆ queue_num_waiting()

static unsigned long queue_num_waiting ( VALUE  self)
static

Definition at line 584 of file thread_sync.c.

References GET_QUEUE_WAITERS, and RARRAY_LEN.

Referenced by queue_do_close(), rb_queue_num_waiting(), and rb_szqueue_num_waiting().

◆ queue_pop_should_block()

static int queue_pop_should_block ( int  argc,
const VALUE argv 
)
static

Definition at line 807 of file thread_sync.c.

References rb_check_arity, and RTEST.

Referenced by rb_queue_pop(), and rb_szqueue_pop().

◆ queue_sleep()

static VALUE queue_sleep ( VALUE  arg)
static

Definition at line 774 of file thread_sync.c.

References Qnil, and rb_thread_sleep_deadly_allow_spurious_wakeup().

Referenced by queue_do_pop(), and rb_szqueue_push().

◆ raise_closed_queue_error()

static void raise_closed_queue_error ( VALUE  self)
static

Definition at line 604 of file thread_sync.c.

References rb_eClosedQueueError, and rb_raise().

Referenced by queue_do_push(), and rb_szqueue_push().

◆ rb_condvar_broadcast()

static VALUE rb_condvar_broadcast ( VALUE  self)
static

Definition at line 1216 of file thread_sync.c.

References GET_CONDVAR_WAITERS, and wakeup_all_threads().

Referenced by Init_thread_sync().

◆ rb_condvar_initialize()

static VALUE rb_condvar_initialize ( VALUE  self)
static

Definition at line 1143 of file thread_sync.c.

References ary_buf_new(), CONDVAR_WAITERS, and RSTRUCT_SET.

Referenced by Init_thread_sync().

◆ rb_condvar_signal()

static VALUE rb_condvar_signal ( VALUE  self)
static

Definition at line 1203 of file thread_sync.c.

References GET_CONDVAR_WAITERS, and wakeup_first_thread().

Referenced by Init_thread_sync().

◆ rb_condvar_wait()

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

◆ rb_mutex_allow_trap()

void rb_mutex_allow_trap ( VALUE  self,
int  val 
)

Definition at line 511 of file thread_sync.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 130 of file thread_sync.c.

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

Referenced by Init_thread_sync().

◆ rb_mutex_new()

VALUE rb_mutex_new ( void  )

Definition at line 118 of file thread_sync.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 316 of file thread_sync.c.

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

Referenced by finish_writeconv(), Init_thread_sync(), 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 421 of file thread_sync.c.

References Qnil, and rb_thread_sleep_deadly_allow_spurious_wakeup().

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

◆ 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 428 of file thread_sync.c.

References GET_THREAD, Qnil, and sleep_timeval().

Referenced by rb_mutex_sleep().

◆ rb_obj_is_mutex()

VALUE rb_obj_is_mutex ( VALUE  obj)

Definition at line 83 of file thread_sync.c.

References Qfalse, Qtrue, and rb_typeddata_is_kind_of().

Referenced by rb_objspace_call_finalizer().

◆ rb_queue_clear()

static VALUE rb_queue_clear ( VALUE  self)
static

Definition at line 858 of file thread_sync.c.

References GET_QUEUE_QUE, and rb_ary_clear().

Referenced by Init_thread_sync().

◆ rb_queue_close()

static VALUE rb_queue_close ( VALUE  self)
static

Definition at line 727 of file thread_sync.c.

References FALSE, and queue_do_close().

Referenced by Init_thread_sync().

◆ rb_queue_closed_p()

static VALUE rb_queue_closed_p ( VALUE  self)
static

Definition at line 740 of file thread_sync.c.

References Qfalse, Qtrue, and queue_closed_p().

Referenced by Init_thread_sync().

◆ rb_queue_empty_p()

static VALUE rb_queue_empty_p ( VALUE  self)
static

Definition at line 846 of file thread_sync.c.

References Qfalse, Qtrue, and queue_length().

Referenced by Init_thread_sync().

◆ rb_queue_initialize()

static VALUE rb_queue_initialize ( VALUE  self)
static

Definition at line 677 of file thread_sync.c.

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

Referenced by Init_thread_sync().

◆ rb_queue_length()

static VALUE rb_queue_length ( VALUE  self)
static

Definition at line 874 of file thread_sync.c.

References len, queue_length(), and ULONG2NUM.

Referenced by Init_thread_sync().

◆ rb_queue_num_waiting()

static VALUE rb_queue_num_waiting ( VALUE  self)
static

Definition at line 887 of file thread_sync.c.

References len, queue_num_waiting(), and ULONG2NUM.

Referenced by Init_thread_sync().

◆ rb_queue_pop()

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

Definition at line 832 of file thread_sync.c.

References queue_do_pop(), and queue_pop_should_block().

Referenced by Init_thread_sync().

◆ rb_queue_push()

static VALUE rb_queue_push ( VALUE  self,
VALUE  obj 
)
static

Definition at line 756 of file thread_sync.c.

References queue_do_push().

Referenced by Init_thread_sync().

◆ rb_szqueue_clear()

static VALUE rb_szqueue_clear ( VALUE  self)
static

Definition at line 1077 of file thread_sync.c.

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

Referenced by Init_thread_sync().

◆ rb_szqueue_close()

static VALUE rb_szqueue_close ( VALUE  self)
static

Definition at line 940 of file thread_sync.c.

References queue_do_close(), and TRUE.

Referenced by Init_thread_sync().

◆ 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 952 of file thread_sync.c.

References GET_SZQUEUE_MAX.

Referenced by Init_thread_sync().

◆ 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 1091 of file thread_sync.c.

References len, queue_num_waiting(), szqueue_num_waiting_producer(), and ULONG2NUM.

Referenced by Init_thread_sync().

◆ rb_szqueue_pop()

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

Definition at line 1064 of file thread_sync.c.

References queue_pop_should_block(), and szqueue_do_pop().

Referenced by Init_thread_sync().

◆ rb_szqueue_push()

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

◆ szqueue_do_pop()

static VALUE szqueue_do_pop ( VALUE  self,
int  should_block 
)
static

◆ szqueue_num_waiting_producer()

static unsigned long szqueue_num_waiting_producer ( VALUE  self)
static

Definition at line 591 of file thread_sync.c.

References GET_SZQUEUE_WAITERS, and RARRAY_LEN.

Referenced by queue_do_close(), and rb_szqueue_num_waiting().

◆ szqueue_push_should_block()

static int szqueue_push_should_block ( int  argc,
const VALUE argv 
)
static

Definition at line 984 of file thread_sync.c.

References rb_check_arity, and RTEST.

Referenced by rb_szqueue_push().

◆ undumpable()

static VALUE undumpable ( VALUE  obj)
static

Definition at line 1224 of file thread_sync.c.

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

Referenced by Init_thread_sync().

◆ wakeup_all_threads()

static void wakeup_all_threads ( VALUE  list)
static

◆ wakeup_first_thread()

static void wakeup_first_thread ( VALUE  list)
static

Definition at line 554 of file thread_sync.c.

References 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 1154 of file thread_sync.c.

◆ mutex_data_type

const rb_data_type_t mutex_data_type
static
Initial value:
= {
"mutex",
}
static size_t mutex_memsize(const void *ptr)
Definition: thread_sync.c:71
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1145
static void mutex_free(void *ptr)
Definition: thread_sync.c:55
#define mutex_mark
Definition: thread_sync.c:52

Definition at line 76 of file thread_sync.c.

◆ patrol_thread

const rb_thread_t* patrol_thread = NULL
static

Definition at line 231 of file thread_sync.c.

Referenced by rb_check_deadlock().

◆ rb_cConditionVariable

VALUE rb_cConditionVariable
static

Definition at line 3 of file thread_sync.c.

Referenced by Init_thread_sync().

◆ rb_cMutex

VALUE rb_cMutex
static

Definition at line 3 of file thread_sync.c.

Referenced by Init_thread_sync(), and rb_mutex_new().

◆ rb_cQueue

VALUE rb_cQueue
static

Definition at line 3 of file thread_sync.c.

Referenced by Init_thread_sync().

◆ rb_cSizedQueue

VALUE rb_cSizedQueue
static

Definition at line 3 of file thread_sync.c.

Referenced by Init_thread_sync().

◆ rb_eClosedQueueError

VALUE rb_eClosedQueueError
static

Definition at line 4 of file thread_sync.c.

Referenced by Init_thread_sync(), and raise_closed_queue_error().