Skip to content

Commit

Permalink
Merge pull request #715 from Dr15Jones/signalHandlersUseAtomics
Browse files Browse the repository at this point in the history
Signal handlers use atomics
  • Loading branch information
nclopezo committed Sep 4, 2013
2 parents 182a6ff + 87c1583 commit 1e891db
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 40 deletions.
1 change: 0 additions & 1 deletion FWCore/Framework/interface/EventProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ namespace edm {
std::auto_ptr<SubProcess> subProcess_;
std::unique_ptr<HistoryAppender> historyAppender_;

int my_sig_num_;
std::unique_ptr<FileBlock> fb_;
boost::shared_ptr<EDLooperBase> looper_;

Expand Down
13 changes: 3 additions & 10 deletions FWCore/Framework/src/EventProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ namespace edm {
schedule_(),
subProcess_(),
historyAppender_(new HistoryAppender),
my_sig_num_(getSigNum()),
fb_(),
looper_(),
principalCache_(),
Expand Down Expand Up @@ -255,7 +254,6 @@ namespace edm {
schedule_(),
subProcess_(),
historyAppender_(new HistoryAppender),
my_sig_num_(getSigNum()),
fb_(),
looper_(),
principalCache_(),
Expand Down Expand Up @@ -299,7 +297,6 @@ namespace edm {
schedule_(),
subProcess_(),
historyAppender_(new HistoryAppender),
my_sig_num_(getSigNum()),
fb_(),
looper_(),
principalCache_(),
Expand Down Expand Up @@ -339,7 +336,6 @@ namespace edm {
schedule_(),
subProcess_(),
historyAppender_(new HistoryAppender),
my_sig_num_(getSigNum()),
fb_(),
looper_(),
principalCache_(),
Expand Down Expand Up @@ -1244,12 +1240,9 @@ namespace edm {
bool returnValue = false;

// Look for a shutdown signal
{
boost::mutex::scoped_lock sl(usr2_lock);
if(shutdown_flag) {
returnValue = true;
returnCode = epSignal;
}
if(shutdown_flag.load(std::memory_order_relaxed)) {
returnValue = true;
returnCode = epSignal;
}
return returnValue;
}
Expand Down
5 changes: 2 additions & 3 deletions FWCore/Utilities/interface/UnixSignalHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ and manipulate Unix-style signal handling.
----------------------------------------------------------------------*/

#include <signal.h>
#include <atomic>
#include "boost/thread/thread.hpp"

namespace edm {

extern boost::mutex usr2_lock;
extern volatile bool shutdown_flag;
extern volatile std::atomic<bool> shutdown_flag;

extern "C" {
void ep_sigusr2(int,siginfo_t*,void*);
typedef void(*CFUNC)(int,siginfo_t*,void*);
}

int getSigNum();
void disableAllSigs(sigset_t* oldset);
void disableRTSigs();
void enableSignal(sigset_t* newset, int signum);
Expand Down
29 changes: 3 additions & 26 deletions FWCore/Utilities/src/UnixSignalHandlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,19 @@

namespace edm {

boost::mutex usr2_lock;

//--------------------------------------------------------------

volatile bool shutdown_flag = false;
volatile std::atomic<bool> shutdown_flag{false};

extern "C" {
void ep_sigusr2(int,siginfo_t*,void*)
{
FDEBUG(1) << "in sigusr2 handler\n";
shutdown_flag = true;
shutdown_flag.store(true);
}
}

//--------------------------------------------------------------

boost::mutex signum_lock;
volatile int signum_value =
#if defined(__linux__)
SIGRTMIN;
#else
0;
#endif

//--------------------------------------------------------------

int getSigNum()
{
boost::mutex::scoped_lock sl(signum_lock);
int rc = signum_value;
++signum_value;
return rc;
}

#define MUST_BE_ZERO(fun) if((fun) != 0) \
{ perror("UnixSignalHandlers::setupSignal: sig function failed"); abort(); }
{ perror("UnixSignalHandlers::setupSignal: sig function failed"); abort(); }

//--------------------------------------------------------------

Expand Down

0 comments on commit 1e891db

Please sign in to comment.