feat(util/thread): add custom MK_THREAD_LOCAL_GET macros for when LEAN_MULTI_THREAD is not defined
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
15f0899efb
commit
5bf4138a4f
1 changed files with 6 additions and 0 deletions
|
@ -166,6 +166,7 @@ public:
|
|||
#define LEAN_THREAD_PTR(T) static thread_specific_ptr<T> LEAN_THREAD_LOCAL
|
||||
#endif
|
||||
|
||||
#if defined(LEAN_MULTI_THREAD)
|
||||
#define MK_THREAD_LOCAL_GET(T, GETTER_NAME, DEF_VALUE) \
|
||||
static T & GETTER_NAME() { \
|
||||
LEAN_THREAD_PTR(T) tlocal; \
|
||||
|
@ -181,3 +182,8 @@ static T & GETTER_NAME() { \
|
|||
tlocal.reset(new T()); \
|
||||
return *tlocal; \
|
||||
}
|
||||
#else
|
||||
// MK_THREAD_LOCAL_GET_DEF and MK_THREAD_LOCAL_GET when LEAN_MULTI_THREAD is OFF
|
||||
#define MK_THREAD_LOCAL_GET(T, GETTER_NAME, DEF_VALUE) static T & GETTER_NAME() { static T r(DEF_VALUE); return r; }
|
||||
#define MK_THREAD_LOCAL_GET_DEF(T, GETTER_NAME) static T & GETTER_NAME() { static T r; return r; }
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue