I am trying to transfer the source code of caffe (developed for Linux) to a Windows environment. The problem is the structure sigactionin signal_handler.cppand signal_handler.h. Source codes are shown below. My request is which library or code replacement can be done to make it sigactionwork on Windows.
/// Header file
#ifndef INCLUDE_CAFFE_UTIL_SIGNAL_HANDLER_H_
#define INCLUDE_CAFFE_UTIL_SIGNAL_HANDLER_H_
#include "caffe/proto/caffe.pb.h"
#include "caffe/solver.hpp"
namespace caffe {
class SignalHandler {
public:
SignalHandler(SolverAction::Enum SIGINT_action,
SolverAction::Enum SIGHUP_action);
~SignalHandler();
ActionCallback GetActionFunction();
private:
SolverAction::Enum CheckForSignals() const;
SolverAction::Enum SIGINT_action_;
SolverAction::Enum SIGHUP_action_;
};
}
#endif
///Original file
#include <boost/bind.hpp>
#include <glog/logging.h>
#include <signal.h>
#include <csignal>
#include "caffe/util/signal_handler.h"
namespace {
static volatile sig_atomic_t got_sigint = false;
static volatile sig_atomic_t got_sighup = false;
static bool already_hooked_up = false;
void handle_signal(int signal) {
switch (signal) {
case SIGHUP:
got_sighup = true;
break;
case SIGINT:
got_sigint = true;
break;
}
}
void HookupHandler() {
if (already_hooked_up) {
LOG(FATAL) << "Tried to hookup signal handlers more than once.";
}
already_hooked_up = true;
struct sigaction sa;
sa.sa_handler = &handle_signal;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
if (sigaction(SIGHUP, &sa, NULL) == -1) {
LOG(FATAL) << "Cannot install SIGHUP handler.";
}
if (sigaction(SIGINT, &sa, NULL) == -1) {
LOG(FATAL) << "Cannot install SIGINT handler.";
}
}
void UnhookHandler() {
if (already_hooked_up) {
struct sigaction sa;
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
if (sigaction(SIGHUP, &sa, NULL) == -1) {
LOG(FATAL) << "Cannot uninstall SIGHUP handler.";
}
if (sigaction(SIGINT, &sa, NULL) == -1) {
LOG(FATAL) << "Cannot uninstall SIGINT handler.";
}
already_hooked_up = false;
}
}
bool GotSIGINT() {
bool result = got_sigint;
got_sigint = false;
return result;
}
bool GotSIGHUP() {
bool result = got_sighup;
got_sighup = false;
return result;
}
}
namespace caffe {
SignalHandler::SignalHandler(SolverAction::Enum SIGINT_action,
SolverAction::Enum SIGHUP_action):
SIGINT_action_(SIGINT_action),
SIGHUP_action_(SIGHUP_action) {
HookupHandler();
}
SignalHandler::~SignalHandler() {
UnhookHandler();
}
SolverAction::Enum SignalHandler::CheckForSignals() const {
if (GotSIGHUP()) {
return SIGHUP_action_;
}
if (GotSIGINT()) {
return SIGINT_action_;
}
return SolverAction::NONE;
}
ActionCallback SignalHandler::GetActionFunction() {
return boost::bind(&SignalHandler::CheckForSignals, this);
}
}
Mistakes
.\src\caffe\util\signal_handler.cpp(39): error C2065: 'SIGHUP' : undeclared identifier
1>..\src\caffe\util\signal_handler.cpp(42): error C2514: '`anonymous-namespace'::HookupHandler::sigaction' : class has no constructors
1> ..\src\caffe\util\signal_handler.cpp(31) : see declaration of '`anonymous-namespace'::HookupHandler::sigaction'
1>..\src\caffe\util\signal_handler.cpp(50): error C2079: 'sa' uses undefined struct '`anonymous-namespace'::UnhookHandler::sigaction'
1>..\src\caffe\util\signal_handler.cpp(52): error C2228: left of '.sa_handler' must have class/struct/union
1> type is 'int'
1>..\src\caffe\util\signal_handler.cpp(54): error C2228: left of '.sa_flags' must have class/struct/union
1> type is 'int'
1>..\src\caffe\util\signal_handler.cpp(54): error C2065: 'SA_RESTART' : undeclared identifier
1>..\src\caffe\util\signal_handler.cpp(56): error C2228: left of '.sa_mask' must have class/struct/union
source
share