feat(util/thread): add simpler MK_THREAD_LOCAL_GET macro for when BOOST=OFF and MULTI_THREAD=ON
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
8d1ec69599
commit
482f5b01e9
1 changed files with 6 additions and 4 deletions
|
@ -166,7 +166,7 @@ public:
|
|||
#define LEAN_THREAD_PTR(T) static thread_specific_ptr<T> LEAN_THREAD_LOCAL
|
||||
#endif
|
||||
|
||||
#if defined(LEAN_MULTI_THREAD)
|
||||
#if defined(LEAN_USE_BOOST) && defined(LEAN_MULTI_THREAD)
|
||||
#define MK_THREAD_LOCAL_GET(T, GETTER_NAME, DEF_VALUE) \
|
||||
static T & GETTER_NAME() { \
|
||||
LEAN_THREAD_PTR(T) tlocal; \
|
||||
|
@ -183,7 +183,9 @@ static T & GETTER_NAME() { \
|
|||
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; }
|
||||
// MK_THREAD_LOCAL_GET_DEF and MK_THREAD_LOCAL_GET when LEAN_USE_BOOST is not defined
|
||||
// REMARK: LEAN_THREAD_LOCAL is a 'blank' when LEAN_MULTI_THREAD is not defined.
|
||||
// So, the getter is just returning a reference to a global variable if LEAN_MULTI_THREAD is not defined.
|
||||
#define MK_THREAD_LOCAL_GET(T, GETTER_NAME, DEF_VALUE) static T & GETTER_NAME() { static T LEAN_THREAD_LOCAL r(DEF_VALUE); return r; }
|
||||
#define MK_THREAD_LOCAL_GET_DEF(T, GETTER_NAME) static T & GETTER_NAME() { static T LEAN_THREAD_LOCAL r; return r; }
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue