10 #ifndef INCLUDED_utility_thread_threadsafe_creation_HH
11 #define INCLUDED_utility_thread_threadsafe_creation_HH
17 #include <boost/function.hpp>
52 boost::function<
T * () > creation_func,
53 #
if defined MULTI_THREADED && defined CXX11
54 std::atomic< T * > & instance
64 T * local_instance = instance.load( std::memory_order_relaxed );
65 std::atomic_thread_fence( std::memory_order_acquire );
66 if ( ! local_instance ) {
67 std::lock_guard< std::mutex > lock( T::singleton_mutex() );
68 local_instance = instance.load( std::memory_order_relaxed );
70 local_instance = creation_func();
71 instance.store( local_instance, std::memory_order_relaxed );
72 std::atomic_thread_fence( std::memory_order_release );
80 instance = creation_func();
86 instance = creation_func();
112 typename std::map< std::string, utility::pointer::shared_ptr< T > >
::const_iterator
114 typename boost::function< utility::pointer::shared_ptr< T > () > builder,
115 utility::thread::ReadWriteMutex & wrm,
116 std::string
const & tname,
117 typename std::map< std::string, utility::pointer::shared_ptr< T > > & tmap
120 utility::thread::WriteLockGuard lock( wrm );
121 typename std::map< std::string, utility::pointer::shared_ptr< T > >
::const_iterator iter;
123 iter = tmap.find( tname );
124 if ( iter == tmap.end() ) {
125 utility::pointer::shared_ptr< T > newT = builder();
126 iter = tmap.insert( std::make_pair( tname, newT )).first;
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
Non-owning access smart pointer – dispatch class.
Classes to manage data that can be read by multiple threads and written to by only one thread...
void safely_create_singleton(T *&instance)