diff options
| author | Koichi Sasada <ko1@atdot.net> | 2024-02-20 19:09:23 +0900 |
|---|---|---|
| committer | Koichi Sasada <ko1@atdot.net> | 2024-02-21 15:38:29 +0900 |
| commit | d578684989fd2d75f086a259719e3eb0fe57ccb2 (patch) | |
| tree | 182d720a6c0a63a7bcc1f6c48c276d082d074c05 /thread_pthread.c | |
| parent | 91cb30353178004ba57acacf1c39d9c02beff86e (diff) | |
`rb_thread_lock_native_thread()`
Introduce `rb_thread_lock_native_thread()` to allocate dedicated
native thread to the current Ruby thread for M:N threads.
This C API is similar to Go's `runtime.LockOSThread()`.
Accepted at https://github.com/ruby/dev-meeting-log/blob/master/2023/DevMeeting-2023-08-24.md
(and missed to implement on Ruby 3.3.0)
Diffstat (limited to 'thread_pthread.c')
| -rw-r--r-- | thread_pthread.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index 580df826da..fb446eee82 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -2304,6 +2304,11 @@ nt_start(void *ptr) // timeout -> deleted. break; } + + if (nt->dedicated) { + // SNT becomes DNT while running + break; + } } } @@ -3422,4 +3427,16 @@ rb_thread_execute_hooks(rb_event_flag_t event, rb_thread_t *th) } } +// return true if the current thread acquires DNT. +// return false if the current thread already acquires DNT. +bool +rb_thread_lock_native_thread(void) +{ + rb_thread_t *th = GET_THREAD(); + bool is_snt = th->nt->dedicated == 0; + native_thread_dedicated_inc(th->vm, th->ractor, th->nt); + + return is_snt; +} + #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ |
