Ruby: include/ruby/thread.h Source File

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

thread.h
Go to the documentation of this file.
1#ifndef RUBY_THREAD_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_THREAD_H 1
13#include "ruby/internal/attr/nonnull.h"
14#include "ruby/internal/intern/thread.h" /* rb_unblock_function_t */
15#include "ruby/internal/dllexport.h"
16
48#define RB_NOGVL_INTR_FAIL (0x1)
49
60#define RB_NOGVL_UBF_ASYNC_SAFE (0x2)
61
64 RBIMPL_SYMBOL_EXPORT_BEGIN()
65
66 RBIMPL_ATTR_NONNULL((1))
91void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
92
93 RBIMPL_ATTR_NONNULL((1))
130void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
131 rb_unblock_function_t *ubf, void *data2);
132
133 RBIMPL_ATTR_NONNULL((1))
154void *rb_thread_call_without_gvl2(void *(*func)(void *), void *data1,
155 rb_unblock_function_t *ubf, void *data2);
156
157/*
158 * XXX: unstable/unapproved - out-of-tree code should NOT not depend
159 * on this until it hits Ruby 2.6.1
160 */
161
162 RBIMPL_ATTR_NONNULL((1))
174void *rb_nogvl(void *(*func)(void *), void *data1,
175 rb_unblock_function_t *ubf, void *data2,
176 int flags);
177
185#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_AFTER 0x01
186
191#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_
192
193#define RUBY_INTERNAL_THREAD_EVENT_STARTED 1 << 0
194#define RUBY_INTERNAL_THREAD_EVENT_READY 1 << 1
195#define RUBY_INTERNAL_THREAD_EVENT_RESUMED 1 << 2
196#define RUBY_INTERNAL_THREAD_EVENT_SUSPENDED 1 << 3
197#define RUBY_INTERNAL_THREAD_EVENT_EXITED 1 << 4
198#define RUBY_INTERNAL_THREAD_EVENT_MASK 0xff
200typedef void rb_internal_thread_event_data_t; // for future extension.
201
202typedef void (*rb_internal_thread_event_callback)(rb_event_flag_t event,
203 const rb_internal_thread_event_data_t *event_data,
204 void *user_data);
205typedef struct rb_internal_thread_event_hook rb_internal_thread_event_hook_t;
206
217rb_internal_thread_event_hook_t *rb_internal_thread_add_event_hook(
218 rb_internal_thread_event_callback func, rb_event_flag_t events,
219 void *data);
220
221
230 bool rb_internal_thread_remove_event_hook(
231 rb_internal_thread_event_hook_t * hook);
232
233 RBIMPL_SYMBOL_EXPORT_END()
234
235#endif /* RUBY_THREAD_H */
dllexport.h
Tweaking visibility of C variables/functions.
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_event_flag_t
uint32_t rb_event_flag_t
Represents event(s).
Definition event.h:103
thread.h
Public APIs related to rb_cThread.
rb_unblock_function_t
void rb_unblock_function_t(void *)
This is the type of UBFs.
Definition thread.h:336
rb_nogvl
void * rb_nogvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2, int flags)
Identical to rb_thread_call_without_gvl(), except it additionally takes "flags" that change the behav...
Definition thread.c:1541
rb_thread_call_with_gvl
void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
(Re-)acquires the GVL.
Definition thread.c:1774
rb_internal_thread_add_event_hook
rb_internal_thread_event_hook_t * rb_internal_thread_add_event_hook(rb_internal_thread_event_callback func, rb_event_flag_t events, void *data)
Registers a thread event hook function.
rb_thread_call_without_gvl2
void * rb_thread_call_without_gvl2(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
Identical to rb_thread_call_without_gvl(), except it does not interface with signals etc.
Definition thread.c:1672
rb_thread_call_without_gvl
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
Allows the passed function to run in parallel with other Ruby threads.
Definition thread.c:1679
rb_internal_thread_remove_event_hook
bool rb_internal_thread_remove_event_hook(rb_internal_thread_event_hook_t *hook)
Unregister the passed hook.
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30