Skip to content

Commit

Permalink
Lock access to gROOT->fGlobalFunctions
Browse files Browse the repository at this point in the history
The list of global functions must be protected from simultaneous
writes/reads.
  • Loading branch information
Dr15Jones committed Oct 2, 2014
1 parent 933bf24 commit cc40a20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 11 additions & 7 deletions core/base/src/TROOT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1167,12 +1167,14 @@ TFunction *TROOT::GetGlobalFunction(const char *function, const char *params,
// of all currently defined global functions from CINT (more expensive).
// The param string must be of the form: "3189,\"aap\",1.3".

if (!params)
if (!params) {
R__LOCKGUARD2(gROOTMutex);
return (TFunction *)GetListOfGlobalFunctions(load)->FindObject(function);
else {
} else {
if (!fInterpreter)
Fatal("GetGlobalFunction", "fInterpreter not initialized");

R__LOCKGUARD2(gROOTMutex);
TFunction *f;
TIter next(GetListOfGlobalFunctions(load));

Expand All @@ -1194,18 +1196,20 @@ TFunction *TROOT::GetGlobalFunctionWithPrototype(const char *function,
// of all currently defined global functions from CINT (more expensive).
// The proto string must be of the form: "int, char*, float".

if (!proto)
if (!proto) {
R__LOCKGUARD2(gROOTMutex);
return (TFunction *)GetListOfGlobalFunctions(load)->FindObject(function);
else {
} else {
if (!fInterpreter)
Fatal("GetGlobalFunctionWithPrototype", "fInterpreter not initialized");

TFunction *f;
TIter next(GetListOfGlobalFunctions(load));

TString mangled = gInterpreter->GetMangledNameWithPrototype(0,
function,
proto);
R__LOCKGUARD2(gROOTMutex);
TFunction *f;
TIter next(GetListOfGlobalFunctions(load));

while ((f = (TFunction *) next())) {
if (mangled == f->GetMangledName()) return f;
}
Expand Down
14 changes: 12 additions & 2 deletions core/meta/src/TCint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -839,13 +839,23 @@ void TCint::UpdateListOfGlobalFunctions()
// Update the list of pointers to global functions. This function
// is called by TROOT::GetListOfGlobalFunctions().

if (!gROOT->fGlobalFunctions) {
bool globalFunctionsAvailable = false;
{
R__LOCKGUARD(gROOTMutex);
globalFunctionsAvailable = gROOT->fGlobalFunctions != 0;
}
if (!globalFunctionsAvailable) {
// No global functions registered yet, trigger it:
gROOT->GetListOfGlobalFunctions();
// We were already called by TROOT::GetListOfGlobalFunctions()
return;
}


//NOTE: At the moment gROOTMutex== gCINTMutex so we only need to lock one.
// In the future, if they are seperated, then the locks must be taken in
// the proper order.
// gROOTMutex is used to protect gROOT->fGlobalFunctions
//R__LOCKGUARD2(gROOTMutex);
R__LOCKGUARD2(gCINTMutex);

G__MethodInfo t, *a;
Expand Down

0 comments on commit cc40a20

Please sign in to comment.