-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic signal handling: allow user to request a timeout (#32)
- Loading branch information
Showing
9 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/********************* */ | ||
/*! \signalHandler SignalHandler.h | ||
** \verbatim | ||
** Top contributors (to current version): | ||
** Guy Katz | ||
** This signalHandler is part of the Marabou project. | ||
** Copyright (c) 2016-2017 by the authors listed in the signalHandler AUTHORS | ||
** in the top-level source directory) and their institutional affiliations. | ||
** All rights reserved. See the signalHandler COPYING in the top-level source | ||
** directory for licensing information.\endverbatim | ||
**/ | ||
|
||
#include "SignalHandler.h" | ||
#include <cstring> | ||
#include <signal.h> | ||
|
||
void got_signal( int signalNumber ) | ||
{ | ||
SignalHandler::getInstance()->signalReceived( signalNumber ); | ||
} | ||
|
||
SignalHandler *SignalHandler::getInstance() | ||
{ | ||
static SignalHandler handler; | ||
return &handler; | ||
} | ||
|
||
void SignalHandler::registerClient( Signalable *client ) | ||
{ | ||
_clients.append( client ); | ||
} | ||
|
||
void SignalHandler::initialize() | ||
{ | ||
struct sigaction sa; | ||
memset( &sa, 0, sizeof(sa) ); | ||
sa.sa_handler = got_signal; | ||
sigfillset( &sa.sa_mask ); | ||
sigaction( SIGQUIT, &sa, NULL ); | ||
} | ||
|
||
void SignalHandler::signalReceived( unsigned /* signalNumber */ ) | ||
{ | ||
for ( const auto &signalable : _clients ) | ||
signalable->quitSignal(); | ||
} | ||
|
||
// | ||
// Local Variables: | ||
// compile-command: "make -C ../.. " | ||
// tags-signalHandler-name: "../../TAGS" | ||
// c-basic-offset: 4 | ||
// End: | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/********************* */ | ||
/*! \file SignalHandler.h | ||
** \verbatim | ||
** Top contributors (to current version): | ||
** Guy Katz | ||
** This file is part of the Marabou project. | ||
** Copyright (c) 2016-2017 by the authors listed in the file AUTHORS | ||
** in the top-level source directory) and their institutional affiliations. | ||
** All rights reserved. See the file COPYING in the top-level source | ||
** directory for licensing information.\endverbatim | ||
**/ | ||
|
||
#ifndef __SignalHandler_h__ | ||
#define __SignalHandler_h__ | ||
|
||
#include "List.h" | ||
|
||
class SignalHandler | ||
{ | ||
public: | ||
class Signalable | ||
{ | ||
public: | ||
virtual void quitSignal() = 0; | ||
}; | ||
|
||
/* | ||
Get the singleton signal handler | ||
*/ | ||
static SignalHandler *getInstance(); | ||
|
||
/* | ||
Register a client to receive signals | ||
*/ | ||
void registerClient( Signalable *client ); | ||
|
||
/* | ||
Initialize the signal handling | ||
*/ | ||
void initialize(); | ||
|
||
/* | ||
Called when a signal is received | ||
*/ | ||
void signalReceived( unsigned signalNumber ); | ||
|
||
private: | ||
List<Signalable *> _clients; | ||
|
||
/* | ||
Prevent additional instantiations of the class | ||
*/ | ||
SignalHandler() {} | ||
SignalHandler( const SignalHandler & ) {} | ||
}; | ||
|
||
#endif // __SignalHandler_h__ | ||
|
||
// | ||
// Local Variables: | ||
// compile-command: "make -C ../.. " | ||
// tags-file-name: "../../TAGS" | ||
// c-basic-offset: 4 | ||
// End: | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters