| 55 | |
| 56 | template<typename T> |
| 57 | void SharedThreadSafeOwner<T>::update( const std::function<void(T&)> & updater ) |
| 58 | { |
| 59 | assert( !construction_ ); // one thread constructs the object, and this thread updates it |
| 60 | auto myPtr = atomic_exchange( &obj_, {} ); |
| 61 | if ( !myPtr ) |
| 62 | return; |
| 63 | assert( myPtr.use_count() >= 1 ); |
| 64 | if ( myPtr.use_count() > 1 ) // create the copy if we was not the unique owner |
| 65 | myPtr.reset( new T( *myPtr ) ); |
| 66 | assert( myPtr.use_count() == 1 ); |
| 67 | updater( *myPtr ); |
| 68 | assert( !construction_ ); // one thread constructs the object, and this thread updates it |
| 69 | atomic_store( &obj_, std::move( myPtr ) ); |
| 70 | } |
| 71 | |
| 72 | template<typename T> |
| 73 | const T & SharedThreadSafeOwner<T>::getOrCreate( const std::function<T()> & creator ) |
no test coverage detected