Ruby: include/ruby/thread_native.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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
14/*
15 * This file contains wrapper APIs for native thread primitives
16 * which Ruby interpreter uses.
17 *
18 * Now, we only support pthread and Windows threads.
19 *
20 * If you want to use Ruby's Mutex and so on to synchronize Ruby Threads,
21 * please use Mutex directly.
22 */
23
24
25#if defined(_WIN32)
26#include <windows.h>
27typedef HANDLE rb_nativethread_id_t;
28
29typedef union rb_thread_lock_union {
30 HANDLE mutex;
31 CRITICAL_SECTION crit;
32} rb_nativethread_lock_t;
33
34typedef struct rb_thread_cond_struct rb_nativethread_cond_t;
35
36#elif defined(HAVE_PTHREAD_H)
37
38#include <pthread.h>
39typedef pthread_t rb_nativethread_id_t;
40typedef pthread_mutex_t rb_nativethread_lock_t;
41typedef pthread_cond_t rb_nativethread_cond_t;
42
43#else
44#error "unsupported thread type"
45
46#endif
47
48RUBY_SYMBOL_EXPORT_BEGIN
49
50rb_nativethread_id_t rb_nativethread_self();
51
52void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock);
53void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
54void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
55void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);
56
57 void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
58 int rb_native_mutex_trylock(rb_nativethread_lock_t *lock);
59 void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
60 void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
61 void rb_native_mutex_destroy(rb_nativethread_lock_t *lock);
62
63 void rb_native_cond_signal(rb_nativethread_cond_t *cond);
64 void rb_native_cond_broadcast(rb_nativethread_cond_t *cond);
65 void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
66 void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec);
67 void rb_native_cond_initialize(rb_nativethread_cond_t *cond);
68 void rb_native_cond_destroy(rb_nativethread_cond_t *cond);
69
70RUBY_SYMBOL_EXPORT_END
71
72#endif
rb_thread_cond_struct
Definition: thread_win32.h:24
rb_nativethread_self
rb_nativethread_id_t rb_nativethread_self()
rb_nativethread_lock_lock
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Definition: thread.c:442
rb_native_mutex_lock
void rb_native_mutex_lock(rb_nativethread_lock_t *lock)
rb_native_cond_initialize
void rb_native_cond_initialize(rb_nativethread_cond_t *cond)
rb_native_mutex_trylock
int rb_native_mutex_trylock(rb_nativethread_lock_t *lock)
rb_native_cond_broadcast
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond)
rb_native_mutex_initialize
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock)
rb_native_mutex_unlock
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
rb_nativethread_lock_unlock
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Definition: thread.c:448
rb_native_mutex_destroy
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock)
rb_native_cond_destroy
void rb_native_cond_destroy(rb_nativethread_cond_t *cond)
rb_native_cond_signal
void rb_native_cond_signal(rb_nativethread_cond_t *cond)
rb_nativethread_lock_initialize
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
Definition: thread.c:430
rb_native_cond_wait
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex)
rb_native_cond_timedwait
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec)
rb_nativethread_lock_destroy
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock)
Definition: thread.c:436
rb_nativethread_cond_t
struct rb_thread_cond_struct rb_nativethread_cond_t