Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

thread_pthread.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 thread_pthread.h -
4
5 $Author$
6
7 Copyright (C) 2004-2007 Koichi Sasada
8
9 **********************************************************************/
10
11 #ifndef RUBY_THREAD_PTHREAD_H
12 #define RUBY_THREAD_PTHREAD_H
13
14 #ifdef HAVE_PTHREAD_NP_H
15 #include <pthread_np.h>
16 #endif
17
18 #define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
19 #define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER
20
21 typedef pthread_cond_t rb_nativethread_cond_t;
22
23 typedef struct native_thread_data_struct {
24 union {
25 struct list_node ubf;
26 struct list_node gvl;
27 } node;
28 #if defined(__GLIBC__) || defined(__FreeBSD__)
29 union
30 #else
31 /*
32 * assume the platform condvars are badly implemented and have a
33 * "memory" of which mutex they're associated with
34 */
35 struct
36 #endif
37 {
38 rb_nativethread_cond_t intr; /* th->interrupt_lock */
39 rb_nativethread_cond_t gvlq; /* vm->gvl.lock */
40 } cond;
41 } native_thread_data_t;
42
43 #undef except
44 #undef try
45 #undef leave
46 #undef finally
47
48 typedef struct rb_global_vm_lock_struct {
49 /* fast path */
50 const struct rb_thread_struct *owner;
51 rb_nativethread_lock_t lock; /* AKA vm->gvl.lock */
52
53 /*
54 * slow path, protected by vm->gvl.lock
55 * - @waitq - FIFO queue of threads waiting for GVL
56 * - @timer - it handles timeslices for @owner. It is any one thread
57 * in @waitq, there is no @timer if @waitq is empty, but always
58 * a @timer if @waitq has entries
59 * - @timer_err tracks timeslice limit, the timeslice only resets
60 * when pthread_cond_timedwait returns ETIMEDOUT, so frequent
61 * switching between contended/uncontended GVL won't reset the
62 * timer.
63 */
64 struct list_head waitq; /* <=> native_thread_data_t.node.ubf */
65 const struct rb_thread_struct *timer;
66 int timer_err;
67
68 /* yield */
69 rb_nativethread_cond_t switch_cond;
70 rb_nativethread_cond_t switch_wait_cond;
71 int need_yield;
72 int wait_yield;
73 } rb_global_vm_lock_t;
74
75 #endif /* RUBY_THREAD_PTHREAD_H */
native_thread_data_struct::cond
struct native_thread_data_struct::@162 cond
native_thread_data_struct::intr
rb_nativethread_cond_t intr
Definition: thread_pthread.h:38
rb_global_vm_lock_struct
Definition: thread_pthread.h:48
rb_global_vm_lock_struct::switch_wait_cond
rb_nativethread_cond_t switch_wait_cond
Definition: thread_pthread.h:70
rb_global_vm_lock_struct::owner
const struct rb_thread_struct * owner
Definition: thread_pthread.h:50
native_thread_data_struct::gvl
struct list_node gvl
Definition: thread_pthread.h:26
rb_global_vm_lock_struct::need_yield
int need_yield
Definition: thread_pthread.h:71
native_thread_data_struct::ubf
struct list_node ubf
Definition: thread_pthread.h:25
native_thread_data_struct::node
union native_thread_data_struct::@161 node
native_thread_data_struct::gvlq
rb_nativethread_cond_t gvlq
Definition: thread_pthread.h:39
rb_global_vm_lock_struct::waitq
struct list_head waitq
Definition: thread_pthread.h:64
rb_global_vm_lock_struct::timer_err
int timer_err
Definition: thread_pthread.h:66
rb_global_vm_lock_struct::wait_yield
int wait_yield
Definition: thread_pthread.h:72
__pthread_mutex_t
Definition: rb_mjit_min_header-2.7.0.h:1346
list_head
Definition: rb_mjit_min_header-2.7.0.h:8975
rb_global_vm_lock_struct::switch_cond
rb_nativethread_cond_t switch_cond
Definition: thread_pthread.h:69
__pthread_cond_t
Definition: rb_mjit_min_header-2.7.0.h:1351
native_thread_data_t
struct native_thread_data_struct native_thread_data_t
rb_global_vm_lock_t
struct rb_global_vm_lock_struct rb_global_vm_lock_t
list_node
Definition: rb_mjit_min_header-2.7.0.h:8971
native_thread_data_struct
Definition: thread_pthread.h:23
rb_global_vm_lock_struct::timer
const struct rb_thread_struct * timer
Definition: thread_pthread.h:65
rb_thread_struct
Definition: vm_core.h:910
rb_nativethread_cond_t
pthread_cond_t rb_nativethread_cond_t
Definition: thread_pthread.h:21
rb_global_vm_lock_struct::lock
rb_nativethread_lock_t lock
Definition: thread_pthread.h:51