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

#include <MRSharedThreadSafeOwner.h>

Public Member Functions

MRMESH_API 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
 
MRMESH_API const T & getOrCreate (const std::function< T()> &creator)
 
MRMESH_API void update (const std::function< void(T &)> &updater)
 
MRMESH_API 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

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 >
MRMESH_API 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 >
MRMESH_API size_t MR::SharedThreadSafeOwner< T >::heapBytes ( ) const
nodiscard

returns the amount of memory this object occupies on heap

◆ reset()

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

stops owning T-instance

◆ update()

template<typename T >
MRMESH_API 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 foe other threads during update()


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