-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Refactor signal handling and replace signal handlers with thread-safe functions #133
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // @(#)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_TSigHandling | ||
| #define ROOT_TSigHandling | ||
|
|
||
|
|
||
| ////////////////////////////////////////////////////////////////////////// | ||
| // // | ||
| // TSigHandling // | ||
| // // | ||
| // Abstract base class defining a generic interface to the underlying // | ||
| // Operating System. // | ||
| // // | ||
| ////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #ifndef __CINT__ | ||
| #include <stdio.h> | ||
| #include <ctype.h> | ||
| #include <fcntl.h> | ||
| #ifndef WIN32 | ||
| #include <unistd.h> | ||
| #endif | ||
| #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; | ||
|
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. Rather than global variable, it would be better to have them defined a static variable inside a getter function. For example a function like; const char *GetRootDir() { |
||
| 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 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| // @(#)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; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// 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"); | ||
| } |
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.
The ifndef CINT are no longer needed as it is (in v6) never defined