Skip to content

Conversation

@mikael-s-persson
Copy link
Contributor

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:

  co::CoroutineScheduler scheduler;
  auto server = ... attached to scheduler ...;
  scheduler.AddSignalHandler(SIGINT, [&](int, Coroutine* c) {
    server.Stop(); // <-- I don't trust this entirely.
    c->Sleep(10);
    std::cerr << "Termination deadline expired! Aborting..." << std::endl;
    abort();
  });

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)

@dallison
Copy link
Owner

Unfortunately this is broken on Mac OS. There are syntax errors. I'll work on fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants