1#ifndef RUBY_THREAD_PTHREAD_H
2#define RUBY_THREAD_PTHREAD_H
13#ifdef HAVE_PTHREAD_NP_H
14#include <pthread_np.h>
17#define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
18#define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER
21#if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__)
22# define RB_THREAD_CURRENT_EC_NOINLINE
27enum thread_sched_wait_result {
28 thread_sched_wait_event,
29 thread_sched_wait_timeout,
30 thread_sched_wait_unavailable,
35 enum thread_sched_waiting_flag {
36 thread_sched_waiting_none = 0x00,
37 thread_sched_waiting_timeout = 0x01,
38 thread_sched_waiting_io_read = 0x02,
39 thread_sched_waiting_io_write = 0x08,
40 thread_sched_waiting_io_force = 0x40,
45#ifdef MY_RUBY_BUILD_MAY_TIME_TRAVEL
50 uint32_t event_serial;
56 struct ccan_list_node node;
59 struct ccan_list_node fd_node;
65 struct ccan_list_head waiters;
79 struct ccan_list_node ubf;
83 struct ccan_list_node readyq;
90 struct ccan_list_node timeslice_threads;
94 struct ccan_list_node running_threads;
99 uint32_t event_serial;
103 size_t context_stack_size;
111 rb_nativethread_id_t thread_id;
113#ifdef RB_THREAD_T_HAS_NATIVE_ID
120#if defined(__GLIBC__) || defined(__FreeBSD__)
130 rb_nativethread_cond_t intr;
131 rb_nativethread_cond_t readyq;
134#ifdef USE_SIGALTSTACK
158 rb_nativethread_lock_t lock_;
167 int runnable_hot_th_waiting;
169 bool is_running_timeslice;
170 bool enable_mn_threads;
172 struct ccan_list_head readyq;
179 struct ccan_list_node grq_node;
182struct rb_thread_context;
190#define th_has_coroutine(th) ((th)->sched.context != NULL)
192#ifdef RB_THREAD_LOCAL_SPECIFIER
195 # ifdef RB_THREAD_CURRENT_EC_NOINLINE
202 #define RUBY_NT_SERIAL 1
205typedef pthread_key_t native_tls_key_t;
208native_tls_get(native_tls_key_t key)
211 return pthread_getspecific(key);
215native_tls_set(native_tls_key_t key,
void *ptr)
217 if (UNLIKELY(pthread_setspecific(key, ptr) != 0)) {
218 rb_bug(
"pthread_setspecific error");
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
#define RUBY_EXTERN
Declaration of externally visible global variables.
void rb_unblock_function_t(void *)
This is the type of UBFs.