MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSharedThreadSafeOwner.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRBindingMacros.h"
5#include <functional>
6#include <memory>
7
8namespace MR
9{
10
13
17template<typename T>
18class MR_BIND_IGNORE SharedThreadSafeOwner
19{
20public:
23
25 [[nodiscard]] const T* get() { return obj_.get(); }
26
28 [[nodiscard]] std::shared_ptr<const T> getPtr() { return obj_; }
29
33 MRMESH_API const T & getOrCreate( const std::function<T()> & creator );
34
37 MRMESH_API void update( const std::function<void(T&)> & updater );
38
40 [[nodiscard]] MRMESH_API size_t heapBytes() const;
41
42private:
44 std::shared_ptr<T> obj_;
45
47 std::shared_ptr<TbbTaskArenaAndGroup> construction_;
48};
49
51
52} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
Definition MRSharedThreadSafeOwner.h:19
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
const T * get()
returns the currently owned instance, the pointer becomes invalid after reset() or update()
Definition MRSharedThreadSafeOwner.h:25
MRMESH_API void reset()
stops owning T-instance
MRMESH_API const T & getOrCreate(const std::function< T()> &creator)
std::shared_ptr< const T > getPtr()
returns the currently owned instance
Definition MRSharedThreadSafeOwner.h:28