Skip to content

Commit

Permalink
[MERGE #3489 @obastemur] Convert internal static initializer (thread …
Browse files Browse the repository at this point in the history
…safe) to global

Merge pull request #3489 from obastemur:fix_br_tls

MSVC uses TLS for internal thread safe static initializers. Use static class constructor. Fixes build break with Full.
  • Loading branch information
obastemur committed Aug 7, 2017
2 parents 1b94b57 + 6c6e9eb commit 895f892
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/Runtime/Library/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,17 @@ namespace JSON

// -------- StringifySession implementation ------------//

static char16 gapStringBuffer[JSONspaceSize];
static char16* GetGapStringInternal()
class JSONSpace
{
wmemset(gapStringBuffer, _u(' '), JSONspaceSize);
return gapStringBuffer;
}
public:
static char16 Buffer[JSONspaceSize];
JSONSpace() { wmemset(Buffer, _u(' '), JSONspaceSize); }
};
char16 JSONSpace::Buffer[JSONspaceSize];
static JSONSpace jsonSpace;

void StringifySession::CompleteInit(Js::Var space, ArenaAllocator* tempAlloc)
{
//set the stack, gap
static const char16* spaceBuffer = GetGapStringInternal(); // multi threading safe

charcount_t len = 0;
switch (Js::JavascriptOperators::GetTypeId(space))
{
Expand All @@ -352,7 +351,7 @@ namespace JSON
len = max(0, min(JSONspaceSize, static_cast<int>(Js::TaggedInt::ToInt32(space))));
if (len)
{
gap = Js::JavascriptString::NewCopyBuffer(spaceBuffer, len, scriptContext);
gap = Js::JavascriptString::NewCopyBuffer(jsonSpace.Buffer, len, scriptContext);
}
break;
}
Expand All @@ -364,7 +363,7 @@ namespace JSON
len = max(0, static_cast<int>(min(static_cast<double>(JSONspaceSize), Js::JavascriptConversion::ToInteger(space, scriptContext))));
if (len)
{
gap = Js::JavascriptString::NewCopyBuffer(spaceBuffer, len, scriptContext);
gap = Js::JavascriptString::NewCopyBuffer(jsonSpace.Buffer, len, scriptContext);
}
break;
}
Expand Down

0 comments on commit 895f892

Please sign in to comment.