Enable thread local in MSVC 2015
This commit is contained in:
@@ -51,8 +51,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (defined(CHAISCRIPT_MSVC) && !defined(CHAISCRIPT_MSVC_12)) || (defined(__GNUC__) && __GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || (defined(__llvm__) && !defined(CHAISCRIPT_LIBCPP))
|
||||||
#if (defined(__GNUC__) && __GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || (defined(__llvm__) && !defined(CHAISCRIPT_LIBCPP))
|
|
||||||
/// Currently only g++>=4.8 supports this natively
|
/// Currently only g++>=4.8 supports this natively
|
||||||
/// \todo Make this support other compilers when possible
|
/// \todo Make this support other compilers when possible
|
||||||
#define CHAISCRIPT_HAS_THREAD_LOCAL
|
#define CHAISCRIPT_HAS_THREAD_LOCAL
|
||||||
|
@@ -49,13 +49,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
lib->add(standard_library::future_type<std::future<chaiscript::Boxed_Value>>("future"));
|
lib->add(standard_library::future_type<std::future<chaiscript::Boxed_Value>>("future"));
|
||||||
#ifdef CHAISCRIPT_MSVC
|
|
||||||
/// this is to work around an issue that seems to only come up on single CPU hosts on MSVC 2015 Update 1
|
|
||||||
/// \todo reevaluate this later
|
|
||||||
lib->add(chaiscript::fun([](const std::function<chaiscript::Boxed_Value ()> &t_func){ return std::async(std::thread::hardware_concurrency() <= 1 ? std::launch::deferred : std::launch::async, t_func);}), "async");
|
|
||||||
#else
|
|
||||||
lib->add(chaiscript::fun([](const std::function<chaiscript::Boxed_Value ()> &t_func){ return std::async(std::launch::async, t_func);}), "async");
|
lib->add(chaiscript::fun([](const std::function<chaiscript::Boxed_Value ()> &t_func){ return std::async(std::launch::async, t_func);}), "async");
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lib->add(json_wrap::library());
|
lib->add(json_wrap::library());
|
||||||
|
@@ -160,13 +160,14 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
unique_lock<mutex> lock(m_mutex);
|
unique_lock<mutex> lock(m_mutex);
|
||||||
|
|
||||||
auto itr = m_instances.find(std::this_thread::get_id());
|
const auto id = std::this_thread::get_id();
|
||||||
|
auto itr = m_instances.find(id);
|
||||||
|
|
||||||
if (itr != m_instances.end()) { return itr->second; }
|
if (itr != m_instances.end()) { return itr->second; }
|
||||||
|
|
||||||
std::shared_ptr<T> new_instance(std::make_shared<T>());
|
std::shared_ptr<T> new_instance(std::make_shared<T>());
|
||||||
|
|
||||||
m_instances.insert(std::make_pair(std::this_thread::get_id(), new_instance));
|
m_instances.insert(std::make_pair(id, new_instance));
|
||||||
|
|
||||||
return new_instance;
|
return new_instance;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user