Ruby: include/ruby/thread_native.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

thread_native.h
Go to the documentation of this file.
1#ifndef RUBY_THREAD_NATIVE_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_THREAD_NATIVE_H 1
22#if defined(_WIN32)
23#include <windows.h>
24typedef HANDLE rb_nativethread_id_t;
25
26typedef union rb_thread_lock_union {
27 HANDLE mutex;
28 CRITICAL_SECTION crit;
29} rb_nativethread_lock_t;
30
31typedef struct rb_thread_cond_struct rb_nativethread_cond_t;
32
33#elif defined(HAVE_PTHREAD_H)
34
35#include <pthread.h>
36typedef pthread_t rb_nativethread_id_t;
37typedef pthread_mutex_t rb_nativethread_lock_t;
38typedef pthread_cond_t rb_nativethread_cond_t;
39
40#elif defined(__wasi__) // no-thread platforms
41
42typedef struct rb_nativethread_id_t *rb_nativethread_id_t;
43typedef struct rb_nativethread_lock_t *rb_nativethread_lock_t;
44typedef struct rb_nativethread_cond_t *rb_nativethread_cond_t;
45
46#elif defined(__DOXYGEN__)
47
49struct rb_nativethread_id_t;
50
52struct rb_nativethread_lock_t;
53
55struct rb_nativethread_cond_t;
56
57#else
58#error "unsupported thread type"
59
60#endif
61
62 RBIMPL_SYMBOL_EXPORT_BEGIN()
63
64
69rb_nativethread_id_t rb_nativethread_self(void);
70
83void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock);
84
102void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
103
110void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
111
119void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);
120
122 void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
123
132 int rb_native_mutex_trylock(rb_nativethread_lock_t *lock);
133
135 void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
136
138 void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
139
141 void rb_native_mutex_destroy(rb_nativethread_lock_t *lock);
142
153 void rb_native_cond_signal(rb_nativethread_cond_t *cond);
154
161 void rb_native_cond_broadcast(rb_nativethread_cond_t *cond);
162
172 void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
173
186 void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec);
187
194 void rb_native_cond_initialize(rb_nativethread_cond_t *cond);
195
202 void rb_native_cond_destroy(rb_nativethread_cond_t *cond);
203
204 RBIMPL_SYMBOL_EXPORT_END()
205#endif
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
rb_thread_cond_struct
Definition thread_win32.h:24
rb_nativethread_lock_lock
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Blocks until the current thread obtains a lock.
Definition thread.c:302
rb_nativethread_self
rb_nativethread_id_t rb_nativethread_self(void)
Queries the ID of the native thread that is calling this function.
rb_native_mutex_lock
void rb_native_mutex_lock(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_lock.
rb_native_cond_initialize
void rb_native_cond_initialize(rb_nativethread_cond_t *cond)
Fills the passed condition variable with an initial value.
rb_native_mutex_trylock
int rb_native_mutex_trylock(rb_nativethread_lock_t *lock)
Identical to rb_native_mutex_lock(), except it doesn't block in case rb_native_mutex_lock() would.
rb_native_cond_broadcast
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond)
Signals a condition variable.
rb_native_mutex_initialize
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_initialize.
rb_native_mutex_unlock
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_unlock.
rb_nativethread_lock_unlock
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Releases a lock.
Definition thread.c:308
rb_native_mutex_destroy
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_destroy.
rb_native_cond_destroy
void rb_native_cond_destroy(rb_nativethread_cond_t *cond)
Destroys the passed condition variable.
rb_native_cond_signal
void rb_native_cond_signal(rb_nativethread_cond_t *cond)
Signals a condition variable.
rb_nativethread_lock_initialize
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
Fills the passed lock with an initial value.
Definition thread.c:290
rb_native_cond_wait
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex)
Waits for the passed condition variable to be signalled.
rb_native_cond_timedwait
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec)
Identical to rb_native_cond_wait(), except it additionally takes timeout in msec resolution.
rb_nativethread_lock_destroy
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock)
Destroys the passed mutex.
Definition thread.c:296