Include conceptual change from PR 2001.
This commit is contained in:
parent
4695953567
commit
88f8ddd70c
@ -1230,19 +1230,29 @@ public:
|
|||||||
else {
|
else {
|
||||||
RAPIDJSON_ASSERT(false); // see above note
|
RAPIDJSON_ASSERT(false); // see above note
|
||||||
|
|
||||||
#if defined(__cplusplus) && (__cplusplus >= 201103L)
|
// Use thread-local storage to prevent races between threads.
|
||||||
// This will generate -Wexit-time-destructors in clang
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
// static GenericValue NullValue;
|
// MSVC 2013 or earlier does not support `thread_local` attribute even in C++11
|
||||||
// return NullValue;
|
// mode.
|
||||||
|
#define RAPIDJSON_THREAD_LOCAL __declspec(thread)
|
||||||
|
#elif RAPIDJSON_HAS_CXX11
|
||||||
|
#define RAPIDJSON_THREAD_LOCAL thread_local
|
||||||
|
#elif defined(__GNUC__) || defined(__clang__)
|
||||||
|
#define RAPIDJSON_THREAD_LOCAL __thread
|
||||||
|
#else
|
||||||
|
#define RAPIDJSON_THREAD_LOCAL
|
||||||
|
#endif
|
||||||
|
|
||||||
// Use static buffer and placement-new to prevent destruction
|
#if RAPIDJSON_HAS_CXX11
|
||||||
alignas(GenericValue) static char buffer[sizeof(GenericValue)];
|
// Use static buffer and placement-new to prevent destruction.
|
||||||
|
alignas(GenericValue) RAPIDJSON_THREAD_LOCAL static char buffer[sizeof(GenericValue)];
|
||||||
return *new (buffer) GenericValue();
|
return *new (buffer) GenericValue();
|
||||||
#else
|
#else
|
||||||
static GenericValue buffer;
|
// This will generate -Wexit-time-destructors in clang.
|
||||||
return *new (reinterpret_cast<char *>(&buffer)) GenericValue();
|
RAPIDJSON_THREAD_LOCAL static GenericValue buffer;
|
||||||
|
return buffer;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename SourceAllocator>
|
template <typename SourceAllocator>
|
||||||
const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
|
const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user