-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Refactor signal handling and replace signal handlers with thread-safe functions #134
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
af454fe
Created a new class TSigHandling out of TSystem and TSigHandling is d…
zzxuanyuan e82976e
Change functions in signal handlers to be thread-safe
zzxuanyuan 56b6049
Change auxiliary functions in TUnixSigHandling to gSystem functions
zzxuanyuan 1fcbcd3
Changed Author and removed type cast and includes handling kSigFloati…
zzxuanyuan 1e32968
Type casting gSystem to TUnixSystem and directly call DispatchTimers(…
zzxuanyuan 8da3187
Fixup cmake glob that breaks newer versions of cmake.
bbockelm 022b503
Fix macosx compilation
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,93 @@ | ||
| // @(#)root/base:$Id$ | ||
| // Author: Fons Rademakers 15/09/95 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update to your name and current month |
||
|
|
||
| /************************************************************************* | ||
| * 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_TSigHandling | ||
| #define ROOT_TSigHandling | ||
|
|
||
|
|
||
| ////////////////////////////////////////////////////////////////////////// | ||
| // // | ||
| // TSigHandling // | ||
| // // | ||
| // 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 | ||
|
|
||
| #ifndef ROOT_TNamed | ||
| #include "TNamed.h" | ||
| #endif | ||
| #ifndef ROOT_TString | ||
| #include "TString.h" | ||
| #endif | ||
| #ifndef ROOT_TInetAddress | ||
| #include "TInetAddress.h" | ||
| #endif | ||
| #ifndef ROOT_TTimer | ||
| #include "TTimer.h" | ||
| #endif | ||
| #ifndef ROOT_ThreadLocalStorage | ||
| #include "ThreadLocalStorage.h" | ||
| #endif | ||
|
|
||
| class TSeqCollection; | ||
| class TFdSet; | ||
| class TVirtualMutex; | ||
|
|
||
| #ifdef __CINT__ | ||
| typedef void *Func_t; | ||
| #else | ||
| typedef void ((*Func_t)()); | ||
| #endif | ||
|
|
||
| R__EXTERN const char *gRootDir; | ||
| R__EXTERN TVirtualMutex *gSystemMutex; | ||
|
|
||
| class TSigHandling : public TNamed { | ||
|
|
||
| protected: | ||
| TFdSet *fSignals; //!Signals that were trapped | ||
| Int_t fSigcnt; //Number of pending signals | ||
| TSeqCollection *fSignalHandler; //List of signal handlers | ||
|
|
||
| public: | ||
| TSigHandling(const char *name = "Generic", const char *title = "Generic Signal Handling"); | ||
| virtual ~TSigHandling(); | ||
|
|
||
| //---- 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(TSigHandling,0) | ||
| }; | ||
|
|
||
| R__EXTERN TSigHandling *gSigHandling; | ||
|
|
||
| #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 "TSigHandling.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" | ||
|
|
||
| TSigHandling *gSigHandling = 0; | ||
|
|
||
| ClassImp(TSigHandling) | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Create a new OS interface. | ||
|
|
||
| TSigHandling::TSigHandling(const char *name, const char *title) : TNamed(name, title) | ||
| { | ||
| fSignals = 0; | ||
| fSigcnt = 0; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Delete the OS interface. | ||
|
|
||
| TSigHandling::~TSigHandling() | ||
| { | ||
| if (fSignalHandler) { | ||
| fSignalHandler->Delete(); | ||
| SafeDelete(fSignalHandler); | ||
| } | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Init the OS interface. | ||
| void TSigHandling::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 TSigHandling::HaveTrappedSignal(Bool_t) | ||
| { | ||
| AbstractMethod("HaveTrappedSignal"); | ||
| return kFALSE; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Dispatch signals. | ||
|
|
||
| void TSigHandling::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 TSigHandling::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 *TSigHandling::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 TSigHandling::ResetSignal(ESignals /*sig*/, Bool_t /*reset*/) | ||
| { | ||
| AbstractMethod("ResetSignal"); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Reset signals handlers to previous behaviour. | ||
|
|
||
| void TSigHandling::ResetSignals() | ||
| { | ||
| AbstractMethod("ResetSignals"); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// If ignore is true ignore the specified signal, else restore previous | ||
| /// behaviour. | ||
|
|
||
| void TSigHandling::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 TSigHandling::IgnoreInterrupt(Bool_t ignore) | ||
| { | ||
| IgnoreSignal(kSigInterrupt, ignore); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Obtain the current signal handlers | ||
| TSeqCollection *TSigHandling::GetListOfSignalHandlers() | ||
| { | ||
| return fSignalHandler; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Print a stack trace. | ||
|
|
||
| void TSigHandling::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.
Is there a reason you preferred TSigHandling over TSigHandler?
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.
There exists TSignalHandler (https://github.com/root-project/root/blob/8f66431755137822f726c4594b680997324439b5/core/base/inc/TSysEvtHandler.h). I feel TSigHandler is so close to TSignalHandler that it could be difficult to distinguish.
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.
I personally find this very confusing. What is the difference between the two?
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.
What is the reason which brought you to create a dictionary for the class(es)?