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:
parent
c0d55f9183
commit
cc3b93c991
4 changed files with 101 additions and 28 deletions
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue