Skip to content

Commit

Permalink
Merge pull request root-project#26 from Dr15Jones/anotherFixForTFormu…
Browse files Browse the repository at this point in the history
…la_5_34_21

Another thread safety fix for TFormula
  • Loading branch information
aledegano committed Sep 29, 2014
2 parents faec90e + 85117b7 commit 1e86f98
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
10 changes: 8 additions & 2 deletions cint/cint/src/Method.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

extern "C" int G__xrefflag;

#if __cplusplus >= 201103L
#define THREAD_LOCAL thread_local
#else
#define THREAD_LOCAL
#endif

/*********************************************************************
* class G__MethodInfo
*
Expand Down Expand Up @@ -163,7 +169,7 @@ struct G__ifunc_table* Cint::G__MethodInfo::ifunc()
///////////////////////////////////////////////////////////////////////////
const char* Cint::G__MethodInfo::Title()
{
static char buf[G__INFO_TITLELEN];
THREAD_LOCAL static char buf[G__INFO_TITLELEN];
buf[0]='\0';
if(IsValid()) {
struct G__ifunc_table_internal *ifunc2;
Expand Down Expand Up @@ -594,7 +600,7 @@ int Cint::G__MethodInfo::IsBusy()
///////////////////////////////////////////////////////////////////////////
char* Cint::G__MethodInfo::GetPrototype()
{
static G__FastAllocString *buf_ptr = new G__FastAllocString(G__LONGLINE);
THREAD_LOCAL static G__FastAllocString *buf_ptr = new G__FastAllocString(G__LONGLINE);
G__FastAllocString &buf(*buf_ptr); // valid until the next call of GetPrototype, just like any static

if (!IsValid()) return 0;
Expand Down
9 changes: 7 additions & 2 deletions cint/cint/src/Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include "common.h"
#include "FastAllocString.h"

#if __cplusplus >= 201103L
#define THREAD_LOCAL thread_local
#else
#define THREAD_LOCAL
#endif
/*********************************************************************
* class G__TypeInfo
*
Expand Down Expand Up @@ -117,7 +122,7 @@ int Cint::G__TypeInfo::operator!=(const G__TypeInfo& a)
///////////////////////////////////////////////////////////////////////////
const char* Cint::G__TypeInfo::TrueName()
{
static G__FastAllocString *buf_ptr = new G__FastAllocString(G__ONELINE);
THREAD_LOCAL static G__FastAllocString *buf_ptr = new G__FastAllocString(G__ONELINE);
G__FastAllocString &buf(*buf_ptr);

buf = G__type2string((int)type,(int)tagnum,-1,(int)reftype,(int)isconst);
Expand All @@ -126,7 +131,7 @@ const char* Cint::G__TypeInfo::TrueName()
///////////////////////////////////////////////////////////////////////////
const char* Cint::G__TypeInfo::Name()
{
static G__FastAllocString *buf_ptr = new G__FastAllocString(G__ONELINE);
THREAD_LOCAL static G__FastAllocString *buf_ptr = new G__FastAllocString(G__ONELINE);
G__FastAllocString &buf(*buf_ptr);

buf = G__type2string((int)type,(int)tagnum,(int)typenum,(int)reftype
Expand Down
19 changes: 15 additions & 4 deletions core/meta/src/TCint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ int TCint_GenerateDictionary(const std::vector<std::string> &classes,
// vector::iterator is a typedef to pointer or a
// class.

#if __cplusplus >= 201103L
static std::set<std::string> sSTLTypes;
if (sSTLTypes.empty()) {
sSTLTypes.insert("vector");
Expand All @@ -151,7 +152,9 @@ int TCint_GenerateDictionary(const std::vector<std::string> &classes,
sSTLTypes.insert("stack");
sSTLTypes.insert("iterator");
}

#else
static const std::set<std::string> sSTLTypes {"vector","list","deque","map","multimap","set","multiset","queue","priority_queue","stack","iterator"};
#endif
std::vector<std::string>::const_iterator it;
std::string fileContent ("");

Expand Down Expand Up @@ -1546,10 +1549,13 @@ const char *TCint::TypeName(const char *typeDesc)

if (typeDesc == 0) return "";

#if __cplusplus >= 201103L
static char *t = 0;
static unsigned int tlen = 0;

R__LOCKGUARD(gCINTMutex); // Because of the static array.
#else
thread_local static char *t = 0;
thread_local static unsigned int tlen = 0;
#endif

unsigned int dlen = strlen(typeDesc);
if (dlen > tlen) {
Expand Down Expand Up @@ -2088,6 +2094,7 @@ void *TCint::FindSpecialObject(const char *item, G__ClassInfo *type,
// This functions has been registered by the TCint ctor.

if (!*prevObj || *assocPtr != gDirectory) {
R__LOCKGUARD(gCINTMutex);
*prevObj = gROOT->FindSpecialObject(item, *assocPtr);
if (!fgSetOfSpecials) fgSetOfSpecials = new std::set<TObject*>;
if (*prevObj) ((std::set<TObject*>*)fgSetOfSpecials)->insert((TObject*)*prevObj);
Expand Down Expand Up @@ -2230,7 +2237,7 @@ const char* TCint::GetSharedLibs()
Bool_t needToSkip = kFALSE;
if ( len>5 && ( (strcmp(end-4,".dll") == 0 ) || (strstr(filename,"Dict.")!=0) || (strstr(filename,"MetaTCint")!=0) ) ) {
// Filter out the cintdlls
static const char *excludelist [] = {
static const char * const excludelist [] = {
"stdfunc.dll","stdcxxfunc.dll","posix.dll","ipc.dll","posix.dll"
"string.dll","vector.dll","vectorbool.dll","list.dll","deque.dll",
"map.dll", "map2.dll","set.dll","multimap.dll","multimap2.dll",
Expand Down Expand Up @@ -2414,7 +2421,11 @@ const char *TCint::GetIncludePath()
const char *TCint::GetSTLIncludePath() const
{
// Return the directory containing CINT's stl cintdlls.
#if __cplusplus >= 201103L
thread_local static TString stldir;
#else
static TString stldir;
#endif
if (!stldir.Length()) {
#ifdef CINTINCDIR
stldir = CINTINCDIR;
Expand Down
3 changes: 3 additions & 0 deletions core/meta/src/TDataType.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "TDataType.h"
#include "TInterpreter.h"
#include "TCollection.h"
#include "TVirtualMutex.h"
#ifdef R__SOLARIS
#include <typeinfo>
#endif
Expand All @@ -38,6 +39,7 @@ TDataType::TDataType(TypedefInfo_t *info) : TDictionary()
fInfo = info;

if (fInfo) {
R__LOCKGUARD2(gCINTMutex);
SetName(gCint->TypedefInfo_Name(fInfo));
SetTitle(gCint->TypedefInfo_Title(fInfo));
SetType(gCint->TypedefInfo_TrueName(fInfo));
Expand Down Expand Up @@ -350,6 +352,7 @@ void TDataType::CheckInfo()

// This intentionally cast the constness away so that
// we can call CheckInfo from const data members.
R__LOCKGUARD2(gCINTMutex);

if (!gCint->TypedefInfo_IsValid(fInfo) ||
strcmp(gCint->TypedefInfo_Name(fInfo),fName.Data())!=0) {
Expand Down

0 comments on commit 1e86f98

Please sign in to comment.