-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Refactor signal handling and replace signal handlers with thread-safe functions #1053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pcanal
wants to merge
14
commits into
root-project:master
Choose a base branch
from
pcanal:zzxuanyuan-sigtest-sept
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fabd0dc
Created a new class TSigHandling out of TSystem and TSigHandling is d…
zzxuanyuan 4607986
Change functions in signal handlers to be thread-safe
zzxuanyuan 1ebb53f
Change auxiliary functions in TUnixSigHandling to gSystem functions
zzxuanyuan ea4472d
Changed Author and removed type cast and includes handling kSigFloati…
zzxuanyuan c637b65
Type casting gSystem to TUnixSystem and directly call DispatchTimers(…
zzxuanyuan c112524
Update signal handling setup calls for MacOSX
pcanal 275d3db
Avoid code duplication.
pcanal 4ae76d1
Use proper glob supporting setter
pcanal fa50533
Remove redundant code guard. Sort include.
pcanal 93b4643
Remove #ifdef __CINT__
pcanal b6bbe3a
White space
pcanal 81b94c9
TFdSet deduplication (now just in TUnixSystem.h)
pcanal 6c238e3
Remove unnecessary include, forward decl
pcanal 90767fe
Rename TSigHandling* to TSignalManager*
pcanal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,75 @@ | ||
| // @(#)root/base:$Id$ | ||
| // Author: Fons Rademakers 15/09/95 | ||
|
|
||
| /************************************************************************* | ||
| * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * | ||
| * All rights reserved. * | ||
| * * | ||
| * For the licensing terms see $ROOTSYS/LICENSE. * | ||
| * For the list of contributors see $ROOTSYS/README/CREDITS. * | ||
| *************************************************************************/ | ||
|
|
||
| #ifndef ROOT_TSignalManager | ||
| #define ROOT_TSignalManager | ||
|
|
||
|
|
||
| ////////////////////////////////////////////////////////////////////////// | ||
| // // | ||
| // TSignalManager // | ||
| // // | ||
| // Abstract base class defining a generic interface to the underlying // | ||
| // Operating System. // | ||
| // // | ||
| ////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #include <stdio.h> | ||
| #include <ctype.h> | ||
| #include <fcntl.h> | ||
| #ifndef WIN32 | ||
| #include <unistd.h> | ||
| #endif | ||
|
|
||
| #include "TInetAddress.h" | ||
| #include "TNamed.h" | ||
| #include "ThreadLocalStorage.h" | ||
| #include "TString.h" | ||
| #include "TTimer.h" | ||
|
|
||
| class TSeqCollection; | ||
| class TFdSet; | ||
|
|
||
| typedef void ((*Func_t)()); | ||
|
|
||
| class TSignalManager : public TNamed { | ||
|
|
||
| protected: | ||
| TFdSet *fSignals; //!Signals that were trapped | ||
| Int_t fSigcnt; //Number of pending signals | ||
| TSeqCollection *fSignalHandler; //List of signal handlers | ||
|
|
||
| public: | ||
| TSignalManager(const char *name = "Generic", const char *title = "Generic Signal Handling"); | ||
| virtual ~TSignalManager(); | ||
|
|
||
| //---- Misc | ||
| virtual void Init(); | ||
| virtual void StackTrace(); | ||
|
|
||
| //---- Handling of system signals | ||
| virtual Bool_t HaveTrappedSignal(Bool_t pendingOnly); | ||
| virtual void DispatchSignals(ESignals sig); | ||
| virtual void AddSignalHandler(TSignalHandler *sh); | ||
| virtual TSignalHandler *RemoveSignalHandler(TSignalHandler *sh); | ||
| virtual void ResetSignal(ESignals sig, Bool_t reset = kTRUE); | ||
| virtual void ResetSignals(); | ||
| virtual void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE); | ||
| virtual void IgnoreInterrupt(Bool_t ignore = kTRUE); | ||
| virtual TSeqCollection *GetListOfSignalHandlers(); | ||
| virtual void SigAlarmInterruptsSyscalls(Bool_t) { } | ||
|
|
||
| ClassDef(TSignalManager,0) | ||
| }; | ||
|
|
||
| R__EXTERN TSignalManager *gSignalManager; | ||
|
|
||
| #endif |
This file contains hidden or 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 hidden or 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 hidden or 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,171 @@ | ||
| // @(#)root/base:$Id: 8944840ba34631ec28efc779647618db43c0eee5 $ | ||
| // Author: Fons Rademakers 15/09/95 | ||
|
|
||
| /************************************************************************* | ||
| * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * | ||
| * All rights reserved. * | ||
| * * | ||
| * For the licensing terms see $ROOTSYS/LICENSE. * | ||
| * For the list of contributors see $ROOTSYS/README/CREDITS. * | ||
| *************************************************************************/ | ||
|
|
||
| /** \class TSystem | ||
|
|
||
| Abstract base class defining a generic interface to the underlying | ||
| Operating System. | ||
| This is not an ABC in the strict sense of the (C++) word. For | ||
| every member function there is an implementation (often not more | ||
| than a call to AbstractMethod() which prints a warning saying | ||
| that the method should be overridden in a derived class), which | ||
| allows a simple partial implementation for new OS'es. | ||
| */ | ||
|
|
||
| #ifdef WIN32 | ||
| #include <io.h> | ||
| #endif | ||
| #include <stdlib.h> | ||
| #include <errno.h> | ||
| #include <algorithm> | ||
| #include <sys/stat.h> | ||
|
|
||
| #include "Riostream.h" | ||
| #include "TSystem.h" | ||
| #include "TSignalManager.h" | ||
| #include "TApplication.h" | ||
| #include "TException.h" | ||
| #include "TROOT.h" | ||
| #include "TClass.h" | ||
| #include "TClassTable.h" | ||
| #include "TEnv.h" | ||
| #include "TBrowser.h" | ||
| #include "TString.h" | ||
| #include "TOrdCollection.h" | ||
| #include "TInterpreter.h" | ||
| #include "TRegexp.h" | ||
| #include "TTimer.h" | ||
| #include "TObjString.h" | ||
| #include "TError.h" | ||
| #include "TPluginManager.h" | ||
| #include "TUrl.h" | ||
| #include "TVirtualMutex.h" | ||
| #include "compiledata.h" | ||
| #include "RConfigure.h" | ||
|
|
||
| TSignalManager *gSignalManager = 0; | ||
|
|
||
| ClassImp(TSignalManager) | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Create a new OS interface. | ||
|
|
||
| TSignalManager::TSignalManager(const char *name, const char *title) : TNamed(name, title) | ||
| { | ||
| fSignals = 0; | ||
| fSigcnt = 0; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Delete the OS interface. | ||
|
|
||
| TSignalManager::~TSignalManager() | ||
| { | ||
| if (fSignalHandler) { | ||
| fSignalHandler->Delete(); | ||
| SafeDelete(fSignalHandler); | ||
| } | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Init the OS interface. | ||
| void TSignalManager::Init() | ||
| { | ||
| fSignalHandler = new TOrdCollection; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Add a signal handler to list of system signal handlers. Only adds | ||
| /// the handler if it is not already in the list of signal handlers. | ||
|
|
||
| Bool_t TSignalManager::HaveTrappedSignal(Bool_t) | ||
| { | ||
| AbstractMethod("HaveTrappedSignal"); | ||
| return kFALSE; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Dispatch signals. | ||
|
|
||
| void TSignalManager::DispatchSignals(ESignals /*sig*/) | ||
| { | ||
| AbstractMethod("DispatchSignals"); | ||
| } | ||
|
|
||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Add a signal handler to list of system signal handlers. Only adds | ||
| /// the handler if it is not already in the list of signal handlers. | ||
|
|
||
| void TSignalManager::AddSignalHandler(TSignalHandler *) | ||
| { | ||
| AbstractMethod("AddSignalHandler"); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Remove a signal handler from list of signal handlers. Returns | ||
| /// the handler or 0 if the handler was not in the list of signal handlers. | ||
|
|
||
| TSignalHandler *TSignalManager::RemoveSignalHandler(TSignalHandler *) | ||
| { | ||
| AbstractMethod("RemoveSignalHandler"); | ||
| return 0; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// If reset is true reset the signal handler for the specified signal | ||
| /// to the default handler, else restore previous behaviour. | ||
|
|
||
| void TSignalManager::ResetSignal(ESignals /*sig*/, Bool_t /*reset*/) | ||
| { | ||
| AbstractMethod("ResetSignal"); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Reset signals handlers to previous behaviour. | ||
|
|
||
| void TSignalManager::ResetSignals() | ||
| { | ||
| AbstractMethod("ResetSignals"); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// If ignore is true ignore the specified signal, else restore previous | ||
| /// behaviour. | ||
|
|
||
| void TSignalManager::IgnoreSignal(ESignals /*sig*/, Bool_t /*ignore*/) | ||
| { | ||
| AbstractMethod("IgnoreSignal"); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// If ignore is true ignore the interrupt signal, else restore previous | ||
| /// behaviour. Typically call ignore interrupt before writing to disk. | ||
|
|
||
| void TSignalManager::IgnoreInterrupt(Bool_t ignore) | ||
| { | ||
| IgnoreSignal(kSigInterrupt, ignore); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Obtain the current signal handlers | ||
| TSeqCollection *TSignalManager::GetListOfSignalHandlers() | ||
| { | ||
| return fSignalHandler; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Print a stack trace. | ||
|
|
||
| void TSignalManager::StackTrace() | ||
| { | ||
| AbstractMethod("StackTrace"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please amend the original commit instead of adding it with one name and then renaming.