MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::SharedThreadSafeOwner< T > Class Template Reference

#include <MRMesh/MRSharedThreadSafeOwner.h>

Public Member Functions

 SharedThreadSafeOwner ()
 SharedThreadSafeOwner (const SharedThreadSafeOwner &)
SharedThreadSafeOwneroperator= (const SharedThreadSafeOwner &)
 SharedThreadSafeOwner (SharedThreadSafeOwner &&b) noexcept
SharedThreadSafeOwneroperator= (SharedThreadSafeOwner &&b) noexcept
 ~SharedThreadSafeOwner ()
void reset ()
 stops owning T-instance
const T * get ()
 returns the currently owned instance, the pointer becomes invalid after reset() or update()
std::shared_ptr< const T > getPtr ()
 returns the currently owned instance
const T & getOrCreate (const std::function< T()> &creator)
void update (const std::function< void(T &)> &updater)
size_t heapBytes () const
 returns the amount of memory this object occupies on heap

Detailed Description

template<typename T>
class MR::SharedThreadSafeOwner< T >

A group of these objects owns collectively one T-instance, allowing access to stored instance from parallel threads; if one object updates its T-instance, then it makes a copy of T-instance first and become the only object in new group

Constructor & Destructor Documentation

◆ SharedThreadSafeOwner() [1/3]

template<typename T>
MR::SharedThreadSafeOwner< T >::SharedThreadSafeOwner ( )

◆ SharedThreadSafeOwner() [2/3]

template<typename T>
MR::SharedThreadSafeOwner< T >::SharedThreadSafeOwner ( const SharedThreadSafeOwner< T > & )

◆ SharedThreadSafeOwner() [3/3]

template<typename T>
MR::SharedThreadSafeOwner< T >::SharedThreadSafeOwner ( SharedThreadSafeOwner< T > && b)
noexcept

◆ ~SharedThreadSafeOwner()

template<typename T>
MR::SharedThreadSafeOwner< T >::~SharedThreadSafeOwner ( )

Member Function Documentation

◆ get()

template<typename T>
const T * MR::SharedThreadSafeOwner< T >::get ( )
inlinenodiscard

returns the currently owned instance, the pointer becomes invalid after reset() or update()

◆ getOrCreate()

template<typename T>
const T & MR::SharedThreadSafeOwner< T >::getOrCreate ( const std::function< T()> & creator)

returns the currently owned instance (if any), otherwise calls (creator) to create new owned instance, which is returned; if many threads call this simultaneously, then they can collectively participate in the construction

◆ getPtr()

template<typename T>
std::shared_ptr< const T > MR::SharedThreadSafeOwner< T >::getPtr ( )
inlinenodiscard

returns the currently owned instance

◆ heapBytes()

template<typename T>
size_t MR::SharedThreadSafeOwner< T >::heapBytes ( ) const
nodiscard

returns the amount of memory this object occupies on heap

◆ operator=() [1/2]

template<typename T>
SharedThreadSafeOwner & MR::SharedThreadSafeOwner< T >::operator= ( const SharedThreadSafeOwner< T > & )

◆ operator=() [2/2]

template<typename T>
SharedThreadSafeOwner & MR::SharedThreadSafeOwner< T >::operator= ( SharedThreadSafeOwner< T > && b)
noexcept

◆ reset()

template<typename T>
void MR::SharedThreadSafeOwner< T >::reset ( )

stops owning T-instance

◆ update()

template<typename T>
void MR::SharedThreadSafeOwner< T >::update ( const std::function< void(T &)> & updater)

if the object owns some T-instance, then updater function is applied to it; get() and getPtr() return nullptr for other threads during update()


The documentation for this class was generated from the following files: