17 #ifndef COM_BORA_SOFTWARE__BALAU_CONCURRENT__THREAD_LOCAL_INSTANCE 18 #define COM_BORA_SOFTWARE__BALAU_CONCURRENT__THREAD_LOCAL_INSTANCE 20 #include <boost/thread/tss.hpp> 35 public: T & operator () () {
36 if (!instance.get()) {
37 instance.reset(
new T);
40 return *instance.get();
46 public: T & operator () (std::function<T * ()> instantiate) {
47 if (!instance.get()) {
48 instance.reset(instantiate());
51 return *instance.get();
56 private: boost::thread_specific_ptr<T> instance;
62 class ThreadLocalInstance<T,
std::negation<typename std::enable_if<std::is_default_constructible<T>::value>::type>> {
66 public: T & operator () (std::function<T * ()> instantiate) {
68 instance.reset(instantiate());
71 return *instance.get();
76 private: boost::thread_specific_ptr<T> instance;
82 #endif // COM_BORA_SOFTWARE__BALAU_CONCURRENT__THREAD_LOCAL_INSTANCE
Concurrency control classes.
Definition: CyclicBarrier.hpp:26
A thread local instance that can be used as a class member instance variable.
Definition: ThreadLocalInstance.hpp:27