Skip to content

Commit

Permalink
Merge pull request root-project#31 from Dr15Jones/lockAccessToGlobalF…
Browse files Browse the repository at this point in the history
…unctionsList

Lock access to global functions list
  • Loading branch information
aledegano committed Oct 3, 2014
2 parents 281a8c7 + cc40a20 commit 5b54cf8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/base/src/TMacro.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Long_t TMacro::Exec(const char *params, Int_t* error)
// if macro has been executed, look for global function with name
// of macro and re-execute this global function, if not found then
// macro is unnamed macro, which we re-execute from file
if (gROOT->GetListOfGlobalFunctions(kTRUE)->FindObject(GetName())) {
if ( gROOT->GetGlobalFunction(GetName(), 0, kTRUE) ) {
gROOT->SetExecutingMacro(kTRUE);
TString exec = GetName();
TString p = params;
Expand Down
3 changes: 1 addition & 2 deletions core/base/src/TQObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ Int_t TQObject::CheckConnectArgs(TQObject *sender,
TFunction *slotMethod = 0;
if (!receiver_class) {
// case of slot_method is compiled/intrepreted function
slotMethod = (TFunction*)gROOT->GetListOfGlobalFunctions(kTRUE)->
FindObject(slot_method);
slotMethod = gROOT->GetGlobalFunction(slot_method,0,kTRUE);
} else {
slotMethod = !slot_params ?
GetMethodWithPrototype(receiver_class,
Expand Down
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 5b54cf8

Please sign in to comment.