Skip to content

Commit

Permalink
Merge pull request root-project#39 from Dr15Jones/lockConstOfTApplica…
Browse files Browse the repository at this point in the history
…tion

Synchronize construction of TApplication
  • Loading branch information
ktf committed Oct 15, 2014
2 parents f8a6ace + 8ade45a commit 81205c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions core/base/inc/TROOT.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#ifndef ROOT_TList
#include "TList.h"
#endif
#if __cplusplus >= 201103L
#include <atomic>
#endif

class TClass;
class TCanvas;
Expand Down Expand Up @@ -84,7 +87,11 @@ friend class TCintWithCling;
TString fGitBranch; //Git branch
TString fGitDate; //Date and time when make was run
Int_t fTimer; //Timer flag
#if __cplusplus >= 201103L
std::atomic<TApplication*> fApplication; //Pointer to current application
#else
TApplication *fApplication; //Pointer to current application
#endif
TInterpreter *fInterpreter; //Command interpreter
Bool_t fBatch; //True if session without graphics
Bool_t fEditHistograms; //True if histograms can be edited with the mouse
Expand Down
8 changes: 6 additions & 2 deletions core/base/src/TApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "TClassTable.h"
#include "TBrowser.h"
#include "TUrl.h"
#include "TVirtualMutex.h"

#include <stdlib.h>

Expand Down Expand Up @@ -115,7 +116,7 @@ TApplication::TApplication(const char *appClassName, Int_t *argc, char **argv,
// except if you want to by-pass the argv processing by GetOptions()
// in which case you should specify numOptions<0. All options will
// still be available via the Argv() method for later use.

R__LOCKGUARD2(gCINTMutex);
if (gApplication && gApplication->TestBit(kDefaultApplication)) {
// allow default TApplication to be replaced by a "real" TApplication
delete gApplication;
Expand All @@ -140,7 +141,6 @@ TApplication::TApplication(const char *appClassName, Int_t *argc, char **argv,
atexit(CallEndOfProcessCleanups);
}
gApplication = this;
gROOT->SetApplication(this);
gROOT->SetName(appClassName);

// Create the list of applications the first time
Expand Down Expand Up @@ -200,6 +200,10 @@ TApplication::TApplication(const char *appClassName, Int_t *argc, char **argv,
gROOT->ProcessLine(Form("new TMemStat(\"%s\",%d,%d);",ssystem,buffersize,maxcalls));
}
}

//Needs to be done last
gROOT->SetApplication(this);

}

//______________________________________________________________________________
Expand Down
8 changes: 4 additions & 4 deletions core/base/src/TROOT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,9 @@ void TROOT::Idle(UInt_t idleTimeInSec, const char *command)
TApplication::CreateApplication();

if (idleTimeInSec <= 0)
fApplication->RemoveIdleTimer();
(*fApplication).RemoveIdleTimer();
else
fApplication->SetIdleTimer(idleTimeInSec, command);
(*fApplication).SetIdleTimer(idleTimeInSec, command);
}

//______________________________________________________________________________
Expand Down Expand Up @@ -1733,7 +1733,7 @@ Long_t TROOT::ProcessLine(const char *line, Int_t *error)
if (!fApplication)
TApplication::CreateApplication();

return fApplication->ProcessLine(sline, kFALSE, error);
return (*fApplication).ProcessLine(sline, kFALSE, error);
}

//______________________________________________________________________________
Expand All @@ -1753,7 +1753,7 @@ Long_t TROOT::ProcessLineSync(const char *line, Int_t *error)
if (!fApplication)
TApplication::CreateApplication();

return fApplication->ProcessLine(sline, kTRUE, error);
return (*fApplication).ProcessLine(sline, kTRUE, error);
}

//______________________________________________________________________________
Expand Down

0 comments on commit 81205c9

Please sign in to comment.