Revert "Work around possible hang of CFRunLoop with pending kqueue events."

This reverts commit decbe7f6bd.

Using level triggered events resulted in 100% CPU usage, because sockets receive a constant write-ready event. They register themselves with the event loop only once in the beginning for efficiency reasons and thus may receive these events without any active waiters.

In case of kqueue it would be possible to register dynamically only when waiting, without a big performance impact, but in case of the epoll API this would result in am excessive growth of kernel calls.
This commit is contained in:
Sönke Ludwig 2020-05-27 12:26:48 +02:00
parent fb62ba3ff2
commit a9344c8490
2 changed files with 3 additions and 9 deletions

View file

@ -25,11 +25,6 @@ final class CFRunLoopEventLoop : KqueueEventLoopBase {
@trusted @nogc {
super();
// Edge-triggred mode is not fully reliable w.r.t. the CFFileDescriptor
// firing the callback for some reason. Always using level-triggered
// kqueue events avoids possible hangs during CFRunLoopInMode
m_forceLevelTriggered = true;
CFFileDescriptorContext ctx;
ctx.info = cast(void*)this;

View file

@ -45,7 +45,6 @@ abstract class KqueueEventLoopBase : PosixEventLoop {
size_t m_changeCount = 0;
kevent_t[100] m_changes;
kevent_t[100] m_events;
bool m_forceLevelTriggered = false;
}
this()
@ -102,7 +101,7 @@ abstract class KqueueEventLoopBase : PosixEventLoop {
kevent_t ev;
ev.ident = fd;
ev.flags = EV_ADD|EV_ENABLE;
if (edge_triggered && !m_forceLevelTriggered) ev.flags |= EV_CLEAR;
if (edge_triggered) ev.flags |= EV_CLEAR;
if (mask & EventMask.read) {
ev.filter = EVFILT_READ;
putChange(ev);
@ -131,14 +130,14 @@ abstract class KqueueEventLoopBase : PosixEventLoop {
if (changes & EventMask.read) {
ev.filter = EVFILT_READ;
ev.flags = new_mask & EventMask.read ? EV_ADD : EV_DELETE;
if (edge_triggered && !m_forceLevelTriggered) ev.flags |= EV_CLEAR;
if (edge_triggered) ev.flags |= EV_CLEAR;
putChange(ev);
}
if (changes & EventMask.write) {
ev.filter = EVFILT_WRITE;
ev.flags = new_mask & EventMask.write ? EV_ADD : EV_DELETE;
if (edge_triggered && !m_forceLevelTriggered) ev.flags |= EV_CLEAR;
if (edge_triggered) ev.flags |= EV_CLEAR;
putChange(ev);
}