Skip to content

Commit

Permalink
Make function static return values thread_safe
Browse files Browse the repository at this point in the history
Funciton level statics which are being used as return values from
the function are changed to thread_local. This is needed to avoid
multiple threads changing the values while they are being used.
  • Loading branch information
Dr15Jones committed Sep 24, 2014
1 parent 6849d19 commit 61ffa7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 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

0 comments on commit 61ffa7f

Please sign in to comment.