#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SHAREDNAVMESH_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_SHAREDNAVMESH_H #include #include class dtNavMesh; namespace DetourNavigator { using NavMeshPtr = std::shared_ptr; class LockedSharedNavMesh { public: LockedSharedNavMesh(std::mutex& mutex, const NavMeshPtr& value) : mLock(new std::lock_guard(mutex)), mValue(value) {} dtNavMesh* operator ->() const { return mValue.get(); } dtNavMesh& operator *() const { return *mValue; } private: std::unique_ptr> mLock; NavMeshPtr mValue; }; class SharedNavMesh { public: SharedNavMesh(const NavMeshPtr& value) : mMutex(std::make_shared()), mValue(value) {} LockedSharedNavMesh lock() const { return LockedSharedNavMesh(*mMutex, mValue); } NavMeshPtr raw() const { return mValue; } private: std::shared_ptr mMutex; NavMeshPtr mValue; }; } #endif