Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
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
22
23typedef struct native_thread_data_struct {
24 union {
25 struct list_node ubf;
26 struct list_node gvl;
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 */
42
44
45#undef except
46#undef try
47#undef leave
48#undef finally
49
50typedef struct rb_global_vm_lock_struct {
51 /* fast path */
52 const struct rb_thread_struct *owner;
53 rb_nativethread_lock_t lock; /* AKA vm->gvl.lock */
54
55 /*
56 * slow path, protected by vm->gvl.lock
57 * - @waitq - FIFO queue of threads waiting for GVL
58 * - @timer - it handles timeslices for @owner. It is any one thread
59 * in @waitq, there is no @timer if @waitq is empty, but always
60 * a @timer if @waitq has entries
61 * - @timer_err tracks timeslice limit, the timeslice only resets
62 * when pthread_cond_timedwait returns ETIMEDOUT, so frequent
63 * switching between contended/uncontended GVL won't reset the
64 * timer.
65 */
66 struct list_head waitq; /* <=> native_thread_data_t.node.ubf */
67 const struct rb_thread_struct *timer;
68 int timer_err;
69
70 /* yield */
73 int need_yield;
74 int wait_yield;
76
77#endif /* RUBY_THREAD_PTHREAD_H */
struct native_thread_data_struct::@43 cond
union native_thread_data_struct::@42 node
rb_nativethread_cond_t switch_wait_cond
const struct rb_thread_struct * owner
rb_nativethread_cond_t switch_cond
const struct rb_thread_struct * timer
pthread_cond_t rb_nativethread_cond_t
struct native_thread_data_struct native_thread_data_t
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock)
struct rb_global_vm_lock_struct rb_global_vm_lock_t