mirror of https://github.com/mamba-org/mamba.git
Fixed restoring the previous signal handler for example in python case (Windows only for now) (#3297)
* Fixed restoring the previous signal handler for example in python case * formatting * Fix formatting Signed-off-by: Julien Jerphanion <git@jjerphan.xyz> Co-authored-by: Klaim <Klaim@users.noreply.github.com> --------- Co-authored-by: Julien Jerphanion <git@jjerphan.xyz> Co-authored-by: Klaim <Klaim@users.noreply.github.com>
This commit is contained in:
parent
76570f83b8
commit
855b533dd1
|
@ -22,6 +22,9 @@ namespace mamba
|
|||
* thread interruption *
|
||||
***********************/
|
||||
|
||||
|
||||
using signal_handler_t = void (*)(int);
|
||||
|
||||
#ifndef _WIN32
|
||||
void set_signal_handler(const std::function<void(sigset_t)>& handler);
|
||||
|
||||
|
@ -31,11 +34,11 @@ namespace mamba
|
|||
#endif
|
||||
|
||||
void set_default_signal_handler();
|
||||
void restore_system_signal_handler();
|
||||
void restore_previous_signal_handler();
|
||||
signal_handler_t previous_signal_handler();
|
||||
bool is_sig_interrupted() noexcept;
|
||||
void set_sig_interrupted() noexcept;
|
||||
|
||||
|
||||
void interruption_point();
|
||||
|
||||
class thread_interrupted : public std::exception
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace mamba
|
|||
}
|
||||
else
|
||||
{
|
||||
restore_system_signal_handler();
|
||||
restore_previous_signal_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@ namespace mamba
|
|||
* thread interruption *
|
||||
***********************/
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
std::atomic<bool> sig_interrupted(false);
|
||||
std::atomic<signal_handler_t> previous_handler = SIG_DFL;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
@ -87,17 +89,23 @@ namespace mamba
|
|||
|
||||
void set_default_signal_handler()
|
||||
{
|
||||
previous_handler = std::signal(SIGINT, [](int) {});
|
||||
set_signal_handler(default_signal_handler);
|
||||
}
|
||||
#else
|
||||
void set_default_signal_handler()
|
||||
{
|
||||
std::signal(SIGINT, [](int /*signum*/) { set_sig_interrupted(); });
|
||||
previous_handler = std::signal(SIGINT, [](int /*signum*/) { set_sig_interrupted(); });
|
||||
}
|
||||
#endif
|
||||
void restore_system_signal_handler()
|
||||
void restore_previous_signal_handler()
|
||||
{
|
||||
std::signal(SIGINT, SIG_DFL);
|
||||
std::signal(SIGINT, previous_handler.exchange(SIG_DFL));
|
||||
}
|
||||
|
||||
signal_handler_t previous_signal_handler()
|
||||
{
|
||||
return previous_handler.load();
|
||||
}
|
||||
|
||||
bool is_sig_interrupted() noexcept
|
||||
|
|
Loading…
Reference in New Issue