Hand thread into thread_sched_wait_events_timeval
* When we have the thread already, it saves a lookup * `event_wait`, not `kq` Clean up the `thread_sched_wait_events_timeval` calls * By handling the PTHREAD check inside the function, all the other code can become much simpler and just call the function directly without additional checks
This commit is contained in:
parent
8782e02138
commit
256f34ab6b
28
thread.c
28
thread.c
@ -4265,12 +4265,11 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
|
|||||||
return (int)rb_ensure(do_select, (VALUE)&set, select_set_free, (VALUE)&set);
|
return (int)rb_ensure(do_select, (VALUE)&set, select_set_free, (VALUE)&set);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RUBY_THREAD_PTHREAD_H
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
thread_sched_wait_events_timeval(int fd, int events, struct timeval *timeout)
|
thread_sched_wait_events_timeval(rb_thread_t *th, int fd, int events, struct timeval *timeout)
|
||||||
{
|
{
|
||||||
rb_thread_t *th = GET_THREAD();
|
#ifdef RUBY_THREAD_PTHREAD_H
|
||||||
|
if (!th->nt->dedicated) {
|
||||||
rb_hrtime_t rel, *prel;
|
rb_hrtime_t rel, *prel;
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
@ -4282,10 +4281,11 @@ thread_sched_wait_events_timeval(int fd, int events, struct timeval *timeout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return thread_sched_wait_events(TH_SCHED(th), th, fd, waitfd_to_waiting_flag(events), prel);
|
return thread_sched_wait_events(TH_SCHED(th), th, fd, waitfd_to_waiting_flag(events), prel);
|
||||||
|
}
|
||||||
|
#endif // RUBY_THREAD_PTHREAD_H
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_POLL
|
#ifdef USE_POLL
|
||||||
|
|
||||||
/* The same with linux kernel. TODO: make platform independent definition. */
|
/* The same with linux kernel. TODO: make platform independent definition. */
|
||||||
@ -4314,13 +4314,9 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
|
|||||||
wfd.fd = fd;
|
wfd.fd = fd;
|
||||||
wfd.busy = NULL;
|
wfd.busy = NULL;
|
||||||
|
|
||||||
#ifdef RUBY_THREAD_PTHREAD_H
|
if (thread_sched_wait_events_timeval(th, fd, events, timeout)) {
|
||||||
if (!th_has_dedicated_nt(th)) {
|
|
||||||
if (thread_sched_wait_events_timeval(fd, events, timeout)) {
|
|
||||||
return 0; // timeout
|
return 0; // timeout
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RB_VM_LOCK_ENTER();
|
RB_VM_LOCK_ENTER();
|
||||||
{
|
{
|
||||||
@ -4455,15 +4451,11 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
|
|||||||
struct select_args args;
|
struct select_args args;
|
||||||
int r;
|
int r;
|
||||||
VALUE ptr = (VALUE)&args;
|
VALUE ptr = (VALUE)&args;
|
||||||
|
|
||||||
#ifdef RUBY_THREAD_PTHREAD_H
|
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
if (!th_has_dedicated_nt(th)) {
|
|
||||||
if (thread_sched_wait_events_timeval(fd, events, timeout)) {
|
if (thread_sched_wait_events_timeval(th, fd, events, timeout)) {
|
||||||
return 0; // timeout
|
return 0; // timeout
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
args.as.fd = fd;
|
args.as.fd = fd;
|
||||||
args.read = (events & RB_WAITFD_IN) ? init_set_fd(fd, &rfds) : NULL;
|
args.read = (events & RB_WAITFD_IN) ? init_set_fd(fd, &rfds) : NULL;
|
||||||
@ -4471,7 +4463,7 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
|
|||||||
args.except = (events & RB_WAITFD_PRI) ? init_set_fd(fd, &efds) : NULL;
|
args.except = (events & RB_WAITFD_PRI) ? init_set_fd(fd, &efds) : NULL;
|
||||||
args.tv = timeout;
|
args.tv = timeout;
|
||||||
args.wfd.fd = fd;
|
args.wfd.fd = fd;
|
||||||
args.wfd.th = GET_THREAD();
|
args.wfd.th = th;
|
||||||
args.wfd.busy = NULL;
|
args.wfd.busy = NULL;
|
||||||
|
|
||||||
RB_VM_LOCK_ENTER();
|
RB_VM_LOCK_ENTER();
|
||||||
|
@ -883,8 +883,8 @@ timer_thread_polling(rb_vm_t *vm)
|
|||||||
// simply retry
|
// simply retry
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
perror("kq");
|
perror("event_wait");
|
||||||
rb_bug("kq errno:%d", errno);
|
rb_bug("event_wait errno:%d", errno);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user