From 138c7ce79592805a565c96c06e8e3b842d3a99f3 Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Thu, 3 Nov 2016 22:56:26 +0100 Subject: [PATCH] Use a lock to protect access to collection from TROOT::GetListOfCleanups (resolve merge conflicts for 6.08) --- core/base/src/TObject.cxx | 2 ++ core/base/src/TObjectSpy.cxx | 14 +++++++++++--- hist/hist/src/THStack.cxx | 13 ++++++++++--- io/io/src/TFileMerger.cxx | 7 ++++++- net/http/src/TRootSniffer.cxx | 2 ++ tree/tree/src/TChain.cxx | 18 +++++++++++++++--- tree/tree/src/TTree.cxx | 11 +++++++++-- tree/treeplayer/src/TTreePlayer.cxx | 7 ++++++- 8 files changed, 61 insertions(+), 13 deletions(-) diff --git a/core/base/src/TObject.cxx b/core/base/src/TObject.cxx index c94ae18728b97..9eeba18ded7a0 100644 --- a/core/base/src/TObject.cxx +++ b/core/base/src/TObject.cxx @@ -48,6 +48,7 @@ class hierarchies (watch out for overlaps). #include "TObjString.h" #include "TRefTable.h" #include "TProcessID.h" +#include "TVirtualMutex.h" Long_t TObject::fgDtorOnly = 0; Bool_t TObject::fgObjectStat = kTRUE; @@ -148,6 +149,7 @@ TObject::~TObject() if (root->MustClean()) { if (root == this) return; if (TestBit(kMustCleanup)) { + R__LOCKGUARD2(gROOTMutex); root->GetListOfCleanups()->RecursiveRemove(this); } } diff --git a/core/base/src/TObjectSpy.cxx b/core/base/src/TObjectSpy.cxx index 6f6a3306a1454..1aeb4de460adb 100644 --- a/core/base/src/TObjectSpy.cxx +++ b/core/base/src/TObjectSpy.cxx @@ -11,7 +11,7 @@ #include "TObjectSpy.h" #include "TROOT.h" - +#include "TVirtualMutex.h" /** \class TObjectRefSpy \class TObjectSpy @@ -35,7 +35,10 @@ ClassImp(TObjectRefSpy) TObjectSpy::TObjectSpy(TObject *obj, Bool_t fixMustCleanupBit) : TObject(), fObj(obj), fResetMustCleanupBit(kFALSE) { - gROOT->GetListOfCleanups()->Add(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Add(this); + } if (fObj && !fObj->TestBit(kMustCleanup)) { if (fixMustCleanupBit) { fResetMustCleanupBit = kTRUE; @@ -53,6 +56,7 @@ TObjectSpy::~TObjectSpy() { if (fObj && fResetMustCleanupBit) fObj->SetBit(kMustCleanup, kFALSE); + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Remove(this); } @@ -98,7 +102,10 @@ void TObjectSpy::SetObject(TObject *obj, Bool_t fixMustCleanupBit) TObjectRefSpy::TObjectRefSpy(TObject *&obj, Bool_t fixMustCleanupBit) : fObj(obj), fResetMustCleanupBit(kFALSE) { - gROOT->GetListOfCleanups()->Add(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Add(this); + } if (fObj && !fObj->TestBit(kMustCleanup)) { if (fixMustCleanupBit) { fResetMustCleanupBit = kTRUE; @@ -116,6 +123,7 @@ TObjectRefSpy::~TObjectRefSpy() { if (fObj && fResetMustCleanupBit) fObj->SetBit(kMustCleanup, kFALSE); + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Remove(this); } diff --git a/hist/hist/src/THStack.cxx b/hist/hist/src/THStack.cxx index 10ed370eb6aa5..a269deb2a51f5 100644 --- a/hist/hist/src/THStack.cxx +++ b/hist/hist/src/THStack.cxx @@ -23,6 +23,7 @@ #include "TBrowser.h" #include "TMath.h" #include "TObjString.h" +#include "TVirtualMutex.h" ClassImp(THStack) @@ -129,6 +130,7 @@ THStack::THStack(const char *name, const char *title) fHistogram = 0; fMaximum = -1111; fMinimum = -1111; + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Add(this); } @@ -172,8 +174,10 @@ THStack::THStack(TH1* hist, Option_t *axis /*="x"*/, fHistogram = 0; fMaximum = -1111; fMinimum = -1111; - gROOT->GetListOfCleanups()->Add(this); - + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Add(this); + } if (!axis) { Warning("THStack", "Need an axis."); return; @@ -316,7 +320,10 @@ THStack::THStack(TH1* hist, Option_t *axis /*="x"*/, THStack::~THStack() { - gROOT->GetListOfCleanups()->Remove(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Remove(this); + } if (!fHists) return; fHists->Clear("nodelete"); delete fHists; diff --git a/io/io/src/TFileMerger.cxx b/io/io/src/TFileMerger.cxx index 0b1925feda37e..77cd205f8abbd 100644 --- a/io/io/src/TFileMerger.cxx +++ b/io/io/src/TFileMerger.cxx @@ -39,6 +39,7 @@ to be merged, like the standalone hadd program. #include "TClassRef.h" #include "TROOT.h" #include "TMemFile.h" +#include "TVirtualMutex.h" #ifdef WIN32 // For _getmaxstdio @@ -99,6 +100,7 @@ TFileMerger::TFileMerger(Bool_t isLocal, Bool_t histoOneGo) fExcessFiles = new TList; fExcessFiles->SetOwner(kTRUE); + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Add(this); } @@ -107,7 +109,10 @@ TFileMerger::TFileMerger(Bool_t isLocal, Bool_t histoOneGo) TFileMerger::~TFileMerger() { - gROOT->GetListOfCleanups()->Remove(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Remove(this); + } SafeDelete(fFileList); SafeDelete(fMergeList); SafeDelete(fOutputFile); diff --git a/net/http/src/TRootSniffer.cxx b/net/http/src/TRootSniffer.cxx index 253ef1918d881..0a1bf2d565da6 100644 --- a/net/http/src/TRootSniffer.cxx +++ b/net/http/src/TRootSniffer.cxx @@ -43,6 +43,7 @@ #include "TImage.h" #include "RZip.h" #include "RVersion.h" +#include "TVirtualMutex.h" #include "TRootSnifferStore.h" #include "THttpCallArg.h" @@ -1949,6 +1950,7 @@ TObject *TRootSniffer::GetItem(const char *fullname, TFolder *&parent, Bool_t fo httpfold = topf->AddFolder("http", "ROOT http server"); httpfold->SetBit(kCanDelete); // register top folder in list of cleanups + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Add(httpfold); } diff --git a/tree/tree/src/TChain.cxx b/tree/tree/src/TChain.cxx index 3958528f7afe2..55f5195ed4b87 100644 --- a/tree/tree/src/TChain.cxx +++ b/tree/tree/src/TChain.cxx @@ -53,6 +53,7 @@ the trees in the chain. #include "TEntryListFromFile.h" #include "TFileStager.h" #include "TFilePrefetch.h" +#include "TVirtualMutex.h" ClassImp(TChain) @@ -89,6 +90,7 @@ TChain::TChain() gROOT->GetListOfDataSets()->Add(this); // Make sure we are informed if the TFile is deleted. + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Add(this); } @@ -165,6 +167,7 @@ TChain::TChain(const char* name, const char* title) gROOT->GetListOfDataSets()->Add(this); // Make sure we are informed if the TFile is deleted. + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Add(this); } @@ -175,7 +178,10 @@ TChain::~TChain() { bool rootAlive = gROOT && !gROOT->TestBit(TObject::kInvalidObject); - if (rootAlive) gROOT->GetListOfCleanups()->Remove(this); + if (rootAlive) { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Remove(this); + } SafeDelete(fProofChain); fStatus->Delete(); @@ -2810,7 +2816,10 @@ void TChain::Streamer(TBuffer& b) { if (b.IsReading()) { // Remove using the 'old' name. - gROOT->GetListOfCleanups()->Remove(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Remove(this); + } UInt_t R__s, R__c; Version_t R__v = b.ReadVersion(&R__s, &R__c); @@ -2831,7 +2840,10 @@ void TChain::Streamer(TBuffer& b) //====end of old versions } // Re-add using the new name. - gROOT->GetListOfCleanups()->Add(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Add(this); + } } else { b.WriteClassBuffer(TChain::Class(),this); diff --git a/tree/tree/src/TTree.cxx b/tree/tree/src/TTree.cxx index c034ba591fec5..13eacc6d0a786 100644 --- a/tree/tree/src/TTree.cxx +++ b/tree/tree/src/TTree.cxx @@ -392,6 +392,7 @@ End_Macro #include "TSchemaRuleSet.h" #include "TFileMergeInfo.h" #include "ROOT/StringConv.hxx" +#include "TVirtualMutex.h" #include "TBranchIMTHelper.h" @@ -880,7 +881,10 @@ TTree::~TTree() } if (fClones) { // Clone trees should no longer be removed from fClones when they are deleted. - gROOT->GetListOfCleanups()->Remove(fClones); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Remove(fClones); + } // Note: fClones does not own its content. delete fClones; fClones = 0; @@ -1104,7 +1108,10 @@ void TTree::AddClone(TTree* clone) fClones->SetOwner(false); // So that the clones are automatically removed from the list when // they are deleted. - gROOT->GetListOfCleanups()->Add(fClones); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Add(fClones); + } } if (!fClones->FindObject(clone)) { fClones->Add(clone); diff --git a/tree/treeplayer/src/TTreePlayer.cxx b/tree/treeplayer/src/TTreePlayer.cxx index f0b1405b050a1..f2587aff40e38 100644 --- a/tree/treeplayer/src/TTreePlayer.cxx +++ b/tree/treeplayer/src/TTreePlayer.cxx @@ -76,6 +76,7 @@ extra libraries (Histogram, display, etc). #include "TVirtualMonitoring.h" #include "TTreeCache.h" #include "TStyle.h" +#include "TVirtualMutex.h" #include "HFitInterface.h" #include "Foption.h" @@ -112,7 +113,10 @@ TTreePlayer::TTreePlayer() fInput->Add(new TNamed("varexp","")); fInput->Add(new TNamed("selection","")); fSelector->SetInputList(fInput); - gROOT->GetListOfCleanups()->Add(this); + { + R__LOCKGUARD2(gROOTMutex); + gROOT->GetListOfCleanups()->Add(this); + } TClass::GetClass("TRef")->AdoptReferenceProxy(new TRefProxy()); TClass::GetClass("TRefArray")->AdoptReferenceProxy(new TRefArrayProxy()); } @@ -127,6 +131,7 @@ TTreePlayer::~TTreePlayer() DeleteSelectorFromFile(); fInput->Delete(); delete fInput; + R__LOCKGUARD2(gROOTMutex); gROOT->GetListOfCleanups()->Remove(this); }