Commit: e858f2e9fff19d6325533e08ebf1068cbcea48ec
Author: Jacques Lucke
Date:   Thu Jun 27 13:27:52 2019 +0200
Branches: functions
https://developer.blender.org/rBe858f2e9fff19d6325533e08ebf1068cbcea48ec

thread safe block creation and deletion

===================================================================

M       source/blender/simulations/bparticles/particles_container.cpp
M       source/blender/simulations/bparticles/particles_container.hpp

===================================================================

diff --git a/source/blender/simulations/bparticles/particles_container.cpp 
b/source/blender/simulations/bparticles/particles_container.cpp
index ab4d586f4e4..990709c4992 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -23,6 +23,8 @@ ParticlesContainer::~ParticlesContainer()
 
 ParticlesBlock &ParticlesContainer::new_block()
 {
+  std::lock_guard<std::mutex> lock(m_blocks_mutex);
+
   AttributeArraysCore attributes_core = 
AttributeArraysCore::NewWithSeparateAllocations(
       m_attributes_info, m_block_size);
   ParticlesBlock *block = new ParticlesBlock(*this, attributes_core);
@@ -32,6 +34,8 @@ ParticlesBlock &ParticlesContainer::new_block()
 
 void ParticlesContainer::release_block(ParticlesBlock &block)
 {
+  std::lock_guard<std::mutex> lock(m_blocks_mutex);
+
   BLI_assert(block.active_amount() == 0);
   BLI_assert(m_blocks.contains(&block));
   BLI_assert(&block.container() == this);
diff --git a/source/blender/simulations/bparticles/particles_container.hpp 
b/source/blender/simulations/bparticles/particles_container.hpp
index 86cfea31727..817ed18741c 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <mutex>
+
 #include "BLI_array_ref.hpp"
 #include "BLI_small_vector.hpp"
 #include "BLI_small_set_vector.hpp"
@@ -27,6 +29,7 @@ class ParticlesContainer {
   AttributesInfo m_attributes_info;
   SmallSet<ParticlesBlock *> m_blocks;
   uint m_block_size;
+  std::mutex m_blocks_mutex;
 
  public:
   ParticlesContainer(AttributesInfo attributes, uint block_size);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to