summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-12-24 10:30:03 +0900
committerKoichi Sasada <ko1@atdot.net>2023-12-24 10:57:27 +0900
commit82015496b924744ae3999987ba679978beb153c7 (patch)
tree3e0a62da71780c4a9ffb0138c1f57f4cb372f7df
parentdaefbf8fbfa1bd2109315bab7658f52460f7ed59 (diff)
MN: access `timer_th.waiting` with lock
`timer_th.waiting` should be protected by `timer_th.waiting_lock`
-rw-r--r--thread_pthread_mn.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/thread_pthread_mn.c b/thread_pthread_mn.c
index a9c8dae74d..c8c7d9f173 100644
--- a/thread_pthread_mn.c
+++ b/thread_pthread_mn.c
@@ -660,10 +660,6 @@ timer_thread_register_waiting(rb_thread_t *th, int fd, enum thread_sched_waiting
#if HAVE_SYS_EVENT_H
struct kevent ke[2];
int num_events = 0;
-
- if (kqueue_already_registered(fd)) {
- return false;
- }
#else
uint32_t epoll_events = 0;
#endif
@@ -708,6 +704,11 @@ timer_thread_register_waiting(rb_thread_t *th, int fd, enum thread_sched_waiting
{
#if HAVE_SYS_EVENT_H
if (num_events > 0) {
+ if (kqueue_already_registered(fd)) {
+ rb_native_mutex_unlock(&timer_th.waiting_lock);
+ return false;
+ }
+
if (kevent(timer_th.event_fd, ke, num_events, NULL, 0, NULL) == -1) {
RUBY_DEBUG_LOG("failed (%d)", errno);