Commit 8c776c19 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding better ctrl-c handling


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 0cbe9b0d
......@@ -12,6 +12,8 @@
*******************************************************************************/
#include "XACC.hpp"
#include "InstructionIterator.hpp"
#include <signal.h>
#include <cstdlib>
namespace xacc {
......@@ -45,6 +47,12 @@ bool isInitialized() {
return xaccFrameworkInitialized;
}
void ctrl_c_handler(int signal) {
error("Caught CTRL-C, exiting the framework.");
Finalize();
exit(1);
}
void Initialize(int arc, char** arv) {
if (!xaccFrameworkInitialized) {
......@@ -61,7 +69,7 @@ void Initialize(int arc, char** arv) {
XACCLogger::instance()->error("Failure initializing XACC Plugin Registry - " +
std::string(e.what()));
Finalize();
exit(-1);
exit(1);
}
// Parse any user-supplied command line options
......@@ -80,6 +88,11 @@ void Initialize(int arc, char** arv) {
"[xacc::plugins] XACC has " + std::to_string(a) + " Accelerator"
+ ((s == 0 || s == 1) ? "" : "s") + " available.");
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = ctrl_c_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
}
// We're good if we make it here, so indicate that we've been
......
......@@ -221,6 +221,18 @@ std::shared_ptr<Compiler> getCompiler();
*/
bool hasCompiler(const std::string& name);
template<typename Service>
std::shared_ptr<Service> getService(const std::string& serviceName) {
auto service = ServiceRegistry::instance()->getService<Service>(
serviceName);
if (!service) {
error(
"Invalid XACC Service. Could not find " + serviceName
+ " in Service Registry.");
}
return service;
}
std::shared_ptr<IRTransformation> getIRTransformation(const std::string& name);
const std::string translate(const std::string& original, const std::string& originalLanguageName,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment