Added signal handler to coroutine scheduler #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added signal handler to coroutine scheduler to block and handle signals in coroutine schedule instead of naked signal handlers.
The Linux signalfd implementation is basically copied from some pretty well-tested code I've been using elsewhere for a long time. I'm not sure about the MacOS version (i.e., sigprocmask + sigpending + sigwait), since that way has not served me well in Linux systems in the past, but I don't know a better alternative for Apple.
The signal handlers are given the signal number and the coroutine scheduler that caught it in its thread/poll loop. To ignore a signal, you can just add a do-nothing handler function. Otherwise, anything goes.
I'm not 100% happy with this, because I would like to be able to add a signal handler that could do something like this:
That would seem to require a per-signal coroutine object that doesn't prevent scheduler from terminating, which I'm not sure how best to do that. (fyi, the above kind of signal handlers is how I've been doing it in my non-coroutine code, based on a more traditional event-loop system)