Handle SIGINT etc. via a sigwait() signal handler thread

This allows other threads to install callbacks that run in a regular,
non-signal context. In particular, we can use this to signal the
downloader thread to quit.

Closes #1183.
This commit is contained in:
Eelco Dolstra 2017-01-17 18:21:02 +01:00
parent c0d55f9183
commit cc3b93c991
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
4 changed files with 101 additions and 28 deletions

View file

@ -263,7 +263,7 @@ void restoreSIGPIPE();
/* User interruption. */
extern volatile sig_atomic_t _isInterrupted;
extern bool _isInterrupted;
extern thread_local bool interruptThrown;
@ -416,4 +416,19 @@ void callSuccess(
}
/* Start a thread that handles various signals. Also block those signals
on the current thread (and thus any threads created by it). */
void startSignalHandlerThread();
struct InterruptCallback
{
virtual ~InterruptCallback() { };
};
/* Register a function that gets called on SIGINT (in a non-signal
context). */
std::unique_ptr<InterruptCallback> createInterruptCallback(
std::function<void()> callback);
}