MeshLib Documentation
Loading...
Searching...
No Matches
MRUniqueThreadSafeOwner.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include <functional>
5#include <mutex>
6#include <memory>
7
8namespace MR
9{
10
11struct TaskGroup;
12
15
18template<typename T>
20{
21public:
28
32 T * get() { return obj_.get(); }
34 MRMESH_API T & getOrCreate( const std::function<T()> & creator );
36 MRMESH_API void update( const std::function<void(T&)> & updater );
38 [[nodiscard]] MRMESH_API size_t heapBytes() const;
39
40private:
41 mutable std::mutex mutex_;
42 std::unique_ptr<T> obj_;
44 std::shared_ptr<TaskGroup> construction_;
45};
46
48
49} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRUniqueThreadSafeOwner.h:20
MRMESH_API void update(const std::function< void(T &)> &updater)
calls given updater for the owned object (if any)
MRMESH_API ~UniqueThreadSafeOwner()
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
T * get()
returns existing owned object and does not create new one
Definition MRUniqueThreadSafeOwner.h:32
MRMESH_API void reset()
deletes owned object
MRMESH_API UniqueThreadSafeOwner(const UniqueThreadSafeOwner &)
MRMESH_API UniqueThreadSafeOwner(UniqueThreadSafeOwner &&b) noexcept
MRMESH_API T & getOrCreate(const std::function< T()> &creator)
returns existing owned object or creates new one using creator function
MRMESH_API UniqueThreadSafeOwner()
MRMESH_API UniqueThreadSafeOwner & operator=(const UniqueThreadSafeOwner &)
Definition MRCameraOrientationPlugin.h:8