Simplify usage of Thread_Specific object

This commit is contained in:
Jason Turner 2017-03-21 10:10:25 -07:00
parent 244b5b224b
commit be2fec02d9
3 changed files with 14 additions and 16 deletions

View File

@ -67,44 +67,44 @@ namespace chaiscript
class Thread_Storage class Thread_Storage
{ {
public: public:
Thread_Storage() = default;
explicit Thread_Storage(void *t_key) Thread_Storage(const Thread_Storage &) = delete;
: m_key(t_key) Thread_Storage(Thread_Storage &&) = delete;
{ Thread_Storage &operator=(const Thread_Storage &) = delete;
} Thread_Storage &operator=(Thread_Storage &&) = delete;
~Thread_Storage() ~Thread_Storage()
{ {
t().erase(m_key); t().erase(this);
} }
inline const T *operator->() const inline const T *operator->() const
{ {
return &(t()[m_key]); return &(t()[this]);
} }
inline const T &operator*() const inline const T &operator*() const
{ {
return t()[m_key]; return t()[this];
} }
inline T *operator->() inline T *operator->()
{ {
return &(t()[m_key]); return &(t()[this]);
} }
inline T &operator*() inline T &operator*()
{ {
return t()[m_key]; return t()[this];
} }
void *m_key; void *m_key;
private: private:
static std::unordered_map<void*, T> &t() static std::unordered_map<const void*, T> &t()
{ {
thread_local static std::unordered_map<void *, T> my_t; thread_local std::unordered_map<const void *, T> my_t;
return my_t; return my_t;
} }
}; };

View File

@ -452,7 +452,7 @@ namespace chaiscript
}; };
explicit Dispatch_Engine(chaiscript::parser::ChaiScript_Parser_Base &parser) explicit Dispatch_Engine(chaiscript::parser::ChaiScript_Parser_Base &parser)
: m_stack_holder(this), : m_stack_holder(),
m_parser(parser) m_parser(parser)
{ {
} }

View File

@ -338,9 +338,7 @@ namespace chaiscript
: m_mutex(), : m_mutex(),
m_conversions(), m_conversions(),
m_convertableTypes(), m_convertableTypes(),
m_num_types(0), m_num_types(0)
m_thread_cache(this),
m_conversion_saves(this)
{ {
} }