feat(util/thread): add LEAN_THREAD_PTR macro, it uses boost::thread_specific_ptr instead of thread_local keyword when we compile with Boost

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-06-07 08:16:20 -07:00
parent 6700cf1f73
commit 91df9a5550
2 changed files with 12 additions and 2 deletions

View file

@ -271,8 +271,10 @@ static bool LEAN_THREAD_LOCAL g_expr_cache_enabled = true;
typedef lru_cache<expr, expr_hash, is_bi_equal_proc> expr_cache;
inline expr cache(expr const & e) {
if (g_expr_cache_enabled) {
static expr_cache LEAN_THREAD_LOCAL g_expr_cache(LEAN_INITIAL_EXPR_CACHE_CAPACITY);
if (auto r = g_expr_cache.insert(e))
LEAN_THREAD_PTR(expr_cache) g_expr_cache;
if (!g_expr_cache.get())
g_expr_cache.reset(new expr_cache(LEAN_INITIAL_EXPR_CACHE_CAPACITY));
if (auto r = g_expr_cache->insert(e))
return *r;
}
return e;

View file

@ -146,3 +146,11 @@ public:
};
}
#endif
// LEAN_THREAD_PTR macro
#if defined(LEAN_USE_BOOST)
#include <boost/thread/tss.hpp>
#define LEAN_THREAD_PTR(T) static boost::thread_specific_ptr<T>
#else
#define LEAN_THREAD_PTR(T) static std::unique_ptr<T> LEAN_THREAD_LOCAL
#endif