MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / update

Method update

source/MRMesh/MRSharedThreadSafeOwner.cpp:57–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55
56template<typename T>
57void 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
72template<typename T>
73const T & SharedThreadSafeOwner<T>::getOrCreate( const std::function<T()> & creator )

Callers 3

packMethod · 0.45
packOptimallyMethod · 0.45
updateCachesMethod · 0.45

Calls 1

resetMethod · 0.45

Tested by

no test coverage detected