Ruby 4.1.0dev (2026-10-27 revision cda3527671a07710b4af10209dde5e51595fb402)
thread_pthread.h (cda3527671a07710b4af10209dde5e51595fb402)
1#ifndef RUBY_THREAD_PTHREAD_H
2#define RUBY_THREAD_PTHREAD_H
3/**********************************************************************
4
5 thread_pthread.h -
6
7 $Author$
8
9 Copyright (C) 2004-2007 Koichi Sasada
10
11 This platform runs the common scheduler; see thread_sched.h for its data
12 structures and thread_sched.c for the implementation.
13
14**********************************************************************/
15
16#ifdef HAVE_PTHREAD_NP_H
17#include <pthread_np.h>
18#endif
19
20#define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
21#define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER
22
23#include "thread_sched.h"
24
25#ifdef RB_THREAD_LOCAL_SPECIFIER
26 NOINLINE(void rb_current_ec_set(struct rb_execution_context_struct *));
27
28 // Under M:N threads, a thread may move to another native thread in the middle of
29 // a C function, so the compiler must not cache the TLS address of ruby_current_ec.
30 NOINLINE(struct rb_execution_context_struct *rb_current_ec(void));
31
32 // for RUBY_DEBUG_LOG()
33 RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER rb_atomic_t ruby_nt_serial;
34 #define RUBY_NT_SERIAL 1
35#else
36typedef pthread_key_t native_tls_key_t;
37
38static inline void *
39native_tls_get(native_tls_key_t key)
40{
41 // return value should be checked by caller
42 return pthread_getspecific(key);
43}
44
45static inline void
46native_tls_set(native_tls_key_t key, void *ptr)
47{
48 if (UNLIKELY(pthread_setspecific(key, ptr) != 0)) {
49 rb_bug("pthread_setspecific error");
50 }
51}
52
53RUBY_EXTERN native_tls_key_t ruby_current_ec_key;
54#endif
55
56#endif /* RUBY_THREAD_PTHREAD_H */
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
Definition atomic.h:69
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition dllexport.h:45