Skip to content

Commit 98fc7e1

Browse files
Dr15Jonespcanal
authored andcommitted
Protect concurrent access to gROOT->GetListOfFiles()
Use the gROOTMutex to protect access to possible concurrent accesses to gROOT->GetListOfFiles(). Note: this would be superseded by making the list itself thread-safe. Signed-off-by: Philippe Canal <[email protected]>
1 parent b97b34b commit 98fc7e1

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

core/base/src/TROOT.cxx

+2
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ TObject *TROOT::FindObjectAnyFile(const char *name) const
10631063
{
10641064
// Scan the memory lists of all files for an object with name
10651065

1066+
R__LOCKGUARD(gROOTMutex);
10661067
TDirectory *d;
10671068
TIter next(GetListOfFiles());
10681069
while ((d = (TDirectory*)next())) {
@@ -1196,6 +1197,7 @@ TFile *TROOT::GetFile(const char *name) const
11961197
{
11971198
// Return pointer to file with name.
11981199

1200+
R__LOCKGUARD(gROOTMutex);
11991201
return (TFile*)GetListOfFiles()->FindObject(name);
12001202
}
12011203

io/sql/src/TSQLFile.cxx

+5-1
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ void TSQLFile::Close(Option_t *option)
706706
}
707707
pidDeleted.Delete();
708708

709+
R__LOCKGUARD(gROOTMutex);
709710
gROOT->GetListOfFiles()->Remove(this);
710711
}
711712

@@ -1049,7 +1050,10 @@ void TSQLFile::InitSqlDatabase(Bool_t create)
10491050
}
10501051
}
10511052

1052-
gROOT->GetListOfFiles()->Add(this);
1053+
{
1054+
R__LOCKGUARD(gROOTMutex);
1055+
gROOT->GetListOfFiles()->Add(this);
1056+
}
10531057
cd();
10541058

10551059
fNProcessIDs = 0;

io/xml/src/TXMLFile.cxx

+5-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ void TXMLFile::InitXmlFile(Bool_t create)
295295
ReadFromFile();
296296
}
297297

298-
gROOT->GetListOfFiles()->Add(this);
298+
{
299+
R__LOCKGUARD(gROOTMutex);
300+
gROOT->GetListOfFiles()->Add(this);
301+
}
299302
cd();
300303

301304
fNProcessIDs = 0;
@@ -358,6 +361,7 @@ void TXMLFile::Close(Option_t *option)
358361
}
359362
pidDeleted.Delete();
360363

364+
R__LOCKGUARD(gROOTMutex);
361365
gROOT->GetListOfFiles()->Remove(this);
362366
}
363367

tree/treeplayer/src/TTreePlayer.cxx

+14-8
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,13 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option)
11631163
fprintf(fp," // of trees.\n");
11641164
fprintf(fp," TChain * chain = new TChain(\"%s\",\"%s\");\n",
11651165
fTree->GetName(),fTree->GetTitle());
1166-
TIter next(((TChain*)fTree)->GetListOfFiles());
1167-
TChainElement *element;
1168-
while ((element = (TChainElement*)next())) {
1169-
fprintf(fp," chain->Add(\"%s/%s\");\n",element->GetTitle(),element->GetName());
1166+
{
1167+
R__LOCKGUARD(gROOTMutex);
1168+
TIter next(((TChain*)fTree)->GetListOfFiles());
1169+
TChainElement *element;
1170+
while ((element = (TChainElement*)next())) {
1171+
fprintf(fp," chain->Add(\"%s/%s\");\n",element->GetTitle(),element->GetName());
1172+
}
11701173
}
11711174
fprintf(fp," tree = chain;\n");
11721175
fprintf(fp,"#endif // SINGLE_TREE\n\n");
@@ -1604,10 +1607,13 @@ Int_t TTreePlayer::MakeCode(const char *filename)
16041607
fprintf(fp," // of trees.\n");
16051608
fprintf(fp," TChain *%s = new TChain(\"%s\",\"%s\");\n",
16061609
fTree->GetName(),fTree->GetName(),fTree->GetTitle());
1607-
TIter next(((TChain*)fTree)->GetListOfFiles());
1608-
TChainElement *element;
1609-
while ((element = (TChainElement*)next())) {
1610-
fprintf(fp," %s->Add(\"%s/%s\");\n",fTree->GetName(),element->GetTitle(),element->GetName());
1610+
{
1611+
R__LOCKGUARD(gROOTMutex);
1612+
TIter next(((TChain*)fTree)->GetListOfFiles());
1613+
TChainElement *element;
1614+
while ((element = (TChainElement*)next())) {
1615+
fprintf(fp," %s->Add(\"%s/%s\");\n",fTree->GetName(),element->GetTitle(),element->GetName());
1616+
}
16111617
}
16121618
fprintf(fp,"#endif // SINGLE_TREE\n\n");
16131619
}

0 commit comments

Comments
 (0)