Ruby 4.1.0dev (2026-09-07 revision b57404b461ba8bf34e802d86b0db78388216e182)
thread_pthread.h (b57404b461ba8bf34e802d86b0db78388216e182)
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// TLS can not be accessed across .so on arm64 and perhaps ppc64le too.
24#if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__)
25# define RB_THREAD_CURRENT_EC_NOINLINE
26#endif
27
28#include "thread_sched.h"
29
30#ifdef RB_THREAD_LOCAL_SPECIFIER
31 NOINLINE(void rb_current_ec_set(struct rb_execution_context_struct *));
32
33 # ifdef RB_THREAD_CURRENT_EC_NOINLINE
34 NOINLINE(struct rb_execution_context_struct *rb_current_ec(void));
35 # else
36 RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER struct rb_execution_context_struct *ruby_current_ec;
37
38 // for RUBY_DEBUG_LOG()
39 RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER rb_atomic_t ruby_nt_serial;
40 #define RUBY_NT_SERIAL 1
41 # endif
42#else
43typedef pthread_key_t native_tls_key_t;
44
45static inline void *
46native_tls_get(native_tls_key_t key)
47{
48 // return value should be checked by caller
49 return pthread_getspecific(key);
50}
51
52static inline void
53native_tls_set(native_tls_key_t key, void *ptr)
54{
55 if (UNLIKELY(pthread_setspecific(key, ptr) != 0)) {
56 rb_bug("pthread_setspecific error");
57 }
58}
59
60RUBY_EXTERN native_tls_key_t ruby_current_ec_key;
61#endif
62
63#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