Skip to content

Commit d05b9a4

Browse files
committed
fix(BRepRayTracing): use shared_mutex
1 parent f78bab3 commit d05b9a4

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/geode/model/helpers/ray_tracing.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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 } {}

0 commit comments

Comments
 (0)