mirror of
https://github.com/janet-lang/janet
synced 2024-12-22 22:40:26 +00:00
Fix #1321, poll event loop CPU usage issue
A stream may have a fiber attached for memory management purposes, but not actually be waiting on anything. Be more seletive with poll, which is not edge-triggered, to not poll for readiness on these streams.
This commit is contained in:
parent
609b629c22
commit
3b189eab64
@ -1818,8 +1818,8 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
|
||||
JanetStream *stream = janet_vm.streams[i];
|
||||
janet_vm.fds[i + 1].events = 0;
|
||||
janet_vm.fds[i + 1].revents = 0;
|
||||
if (stream->read_fiber) janet_vm.fds[i + 1].events |= POLLIN;
|
||||
if (stream->write_fiber) janet_vm.fds[i + 1].events |= POLLOUT;
|
||||
if (stream->read_fiber && stream->read_fiber->ev_callback) janet_vm.fds[i + 1].events |= POLLIN;
|
||||
if (stream->write_fiber && stream->write_fiber->ev_callback) janet_vm.fds[i + 1].events |= POLLOUT;
|
||||
}
|
||||
|
||||
/* Poll for events */
|
||||
|
@ -125,7 +125,7 @@ void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
|
||||
default:
|
||||
break;
|
||||
#ifndef JANET_WINDOWS
|
||||
/* Wait until we have an actually event before checking.
|
||||
/* Wait until we have an actual event before checking.
|
||||
* Windows doesn't support async connect with this, just try immediately.*/
|
||||
case JANET_ASYNC_EVENT_INIT:
|
||||
#endif
|
||||
@ -160,7 +160,7 @@ void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
|
||||
janet_async_end(fiber);
|
||||
}
|
||||
|
||||
static void net_sched_connect(JanetStream *stream) {
|
||||
static JANET_NO_RETURN void net_sched_connect(JanetStream *stream) {
|
||||
NetStateConnect *state = janet_malloc(sizeof(NetStateConnect));
|
||||
state->did_connect = 0;
|
||||
janet_async_start(stream, JANET_ASYNC_LISTEN_WRITE, net_callback_connect, state);
|
||||
@ -575,7 +575,6 @@ JANET_CORE_FN(cfun_net_connect,
|
||||
}
|
||||
|
||||
net_sched_connect(stream);
|
||||
janet_await();
|
||||
}
|
||||
|
||||
static const char *serverify_socket(JSock sfd) {
|
||||
|
Loading…
Reference in New Issue
Block a user