diff options
author | Ghostkeeper <rubend@tutanota.com> | 2022-04-20 14:37:46 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2022-04-20 14:37:46 +0300 |
commit | 185e67ee0f0e9178eb69522c8ee0897ba1388566 (patch) | |
tree | 8cce2f743afd24bc86acdca8071ff341d3015503 | |
parent | efc5f9d9b6a46499606aabf9d21b231c7970b13a (diff) | |
parent | 715f13cb69aab736aaffc4cbaff19a652c64131d (diff) |
Merge branch '5.0'
-rw-r--r-- | src/TreeModelVolumes.cpp | 7 | ||||
-rw-r--r-- | src/TreeModelVolumes.h | 8 | ||||
-rw-r--r-- | src/TreeSupport.cpp | 5 |
3 files changed, 15 insertions, 5 deletions
diff --git a/src/TreeModelVolumes.cpp b/src/TreeModelVolumes.cpp index 7479d5a82..1c6889ee8 100644 --- a/src/TreeModelVolumes.cpp +++ b/src/TreeModelVolumes.cpp @@ -104,6 +104,8 @@ const Polygons& TreeModelVolumes::calculateCollision(const RadiusLayerPair& key) collision_areas = collision_areas.unionPolygons(collision_model.offset(radius)); } } + + const std::lock_guard<std::mutex> lock(object_mutex_); const auto ret = collision_cache_.insert({key, std::move(collision_areas)}); assert(ret.second); return ret.first->second; @@ -135,6 +137,8 @@ const Polygons& TreeModelVolumes::calculateAvoidance(const RadiusLayerPair& key) } auto avoidance_areas = getAvoidance(radius, layer_idx - 1).offset(-max_move_).smooth(5); avoidance_areas = avoidance_areas.unionPolygons(getCollision(radius, layer_idx)); + + const std::lock_guard<std::mutex> lock(object_mutex_); const auto ret = avoidance_cache_.insert({key, std::move(avoidance_areas)}); assert(ret.second); return ret.first->second; @@ -144,8 +148,9 @@ const Polygons& TreeModelVolumes::calculateInternalModel(const RadiusLayerPair& { const auto& radius = key.first; const auto& layer_idx = key.second; - const auto& internal_areas = getAvoidance(radius, layer_idx).difference(getCollision(radius, layer_idx)); + + const std::lock_guard<std::mutex> lock(object_mutex_); const auto ret = internal_model_cache_.insert({key, internal_areas}); assert(ret.second); return ret.first->second; diff --git a/src/TreeModelVolumes.h b/src/TreeModelVolumes.h index 74f2b4cc3..29d23b0d6 100644 --- a/src/TreeModelVolumes.h +++ b/src/TreeModelVolumes.h @@ -4,6 +4,7 @@ #ifndef TREEMODELVOLUMES_H #define TREEMODELVOLUMES_H +#include <mutex> #include <unordered_map> #include "settings/EnumSettings.h" //To store whether X/Y or Z distance gets priority. @@ -20,7 +21,7 @@ class Settings; /*! * \brief Lazily generates tree guidance volumes. * - * \warning This class is not currently thread-safe and should not be accessed in OpenMP blocks + * \warning This class blocks on thread access. Use calls to this in threaded blocks sparingly. */ class TreeModelVolumes { @@ -195,6 +196,11 @@ private: mutable std::unordered_map<RadiusLayerPair, Polygons> collision_cache_; mutable std::unordered_map<RadiusLayerPair, Polygons> avoidance_cache_; mutable std::unordered_map<RadiusLayerPair, Polygons> internal_model_cache_; + + /*! + * \brief Used to make the class thread-safe. + */ + mutable std::mutex object_mutex_; }; } diff --git a/src/TreeSupport.cpp b/src/TreeSupport.cpp index 6edfa7f29..278cd3e16 100644 --- a/src/TreeSupport.cpp +++ b/src/TreeSupport.cpp @@ -31,10 +31,9 @@ namespace cura { -TreeSupport::TreeSupport(const SliceDataStorage& storage) +TreeSupport::TreeSupport(const SliceDataStorage& storage) : + volumes_(storage, Application::getInstance().current_slice->scene.current_mesh_group->settings) { - const Settings& mesh_group_settings = Application::getInstance().current_slice->scene.current_mesh_group->settings; - volumes_ = TreeModelVolumes(storage, mesh_group_settings); } void TreeSupport::generateSupportAreas(SliceDataStorage& storage) |