25 handler_ = [
this, f]() ->
void {
26 const int num_calls = ++num_calls_;
29 <<
"^C pressed " << num_calls <<
" times. "
30 <<
"Interrupting the solver. Press 3 times to force termination.";
31 if (num_calls == 1) f();
32 }
else if (num_calls == 3) {
33 LOG(INFO) <<
"^C pressed 3 times. Forcing termination.";
39 signal(SIGINT, &SigHandler);
44void SigintHandler::SigHandler(
int) { handler_(); }
48 if (handler_ !=
nullptr) signal(SIGINT, SIG_DFL);
51thread_local std::function<void()> SigintHandler::handler_;
54 handler_ = [f]() ->
void { f(); };
55 signal(SIGTERM, &SigHandler);
60void SigtermHandler::SigHandler(
int) { handler_(); }
64 if (handler_ !=
nullptr) signal(SIGTERM, SIG_DFL);
67thread_local std::function<void()> SigtermHandler::handler_;
~SigintHandler()
Unregister the signal handlers.
void Register(const std::function< void()> &f)
void Register(const std::function< void()> &f)
~SigtermHandler()
Unregister the signal handlers.
In SWIG mode, we don't want anything besides these top-level includes.