Add missing chaiscript_threading.hpp
This commit is contained in:
parent
3094ff6e3b
commit
46cdb89921
68
include/chaiscript/chaiscript_threading.hpp
Normal file
68
include/chaiscript/chaiscript_threading.hpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#ifndef __chaiscript_threading_hpp__
|
||||||
|
#define __chaiscript_threading_hpp__
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
#else
|
||||||
|
#warning "ChaiScript is compiling without thread safety."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace chaiscript
|
||||||
|
{
|
||||||
|
namespace threading
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Thread_Storage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline T *operator->() const
|
||||||
|
{
|
||||||
|
if (!m_thread_storage.get())
|
||||||
|
{
|
||||||
|
m_thread_storage.reset(new T());
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_thread_storage.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T &operator*() const
|
||||||
|
{
|
||||||
|
return *(this->operator->());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable boost::thread_specific_ptr<T> m_thread_storage;
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Thread_Storage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline T *operator->() const
|
||||||
|
{
|
||||||
|
return &obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T &operator*() const
|
||||||
|
{
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable T obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user