File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323
2424#include < geode/model/helpers/ray_tracing.hpp>
2525
26- #include < mutex >
26+ #include < shared_mutex >
2727
2828#include < geode/basic/pimpl_impl.hpp>
2929
@@ -300,14 +300,20 @@ namespace geode
300300 private:
301301 const AABBTree3D& surface_aabb ( const Surface3D& surface )
302302 {
303- std::lock_guard lock{ mutex_ };
304303 {
304+ std::shared_lock read_lock{ mutex_ };
305305 const auto it = aabb_trees_.find ( surface.id () );
306306 if ( it != aabb_trees_.end () )
307307 {
308308 return *it->second ;
309309 }
310310 }
311+ std::lock_guard write_lock{ mutex_ };
312+ const auto it = aabb_trees_.find ( surface.id () );
313+ if ( it != aabb_trees_.end () )
314+ {
315+ return *it->second ;
316+ }
311317 const auto [it, inserted] = aabb_trees_.emplace (
312318 surface.id (), std::make_unique< AABBTree3D >(
313319 create_aabb_tree ( surface.mesh () ) ) );
@@ -317,7 +323,7 @@ namespace geode
317323 private:
318324 const BRep& brep_;
319325 absl::flat_hash_map< uuid, std::unique_ptr< AABBTree3D > > aabb_trees_;
320- std::mutex mutex_;
326+ std::shared_mutex mutex_;
321327 };
322328
323329 BRepRayTracing::BRepRayTracing ( const BRep& brep ) : impl_{ brep } {}
You can’t perform that action at this time.
0 commit comments