MeshLib C++ Docs
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
13
16template<typename T>
18{
19public:
26
30 T * get() { return obj_.get(); }
32 MRMESH_API T & getOrCreate( const std::function<T()> & creator );
34 MRMESH_API void update( const std::function<void(T&)> & updater );
36 [[nodiscard]] MRMESH_API size_t heapBytes() const;
37
38private:
39 mutable std::mutex mutex_;
40 std::unique_ptr<T> obj_;
42 std::shared_ptr<TbbTaskArenaAndGroup> construction_;
43};
44
46
47} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
Definition MRUniqueThreadSafeOwner.h:18
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:30
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 &)