use a mutex in const function root_node to protect the non const call to

build()

The class AABB_tree is now read-only thread-safe
This commit is contained in:
Sébastien Loriot 2011-09-08 08:56:16 +00:00
parent eed2074f7f
commit 795ab80486
2 changed files with 15 additions and 3 deletions

View File

@ -27,6 +27,10 @@
#include <CGAL/internal/AABB_tree/AABB_search_tree.h> #include <CGAL/internal/AABB_tree/AABB_search_tree.h>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#ifdef CGAL_HAS_THREADS
#include <boost/thread/mutex.hpp>
#endif
namespace CGAL { namespace CGAL {
/** /**
@ -212,10 +216,17 @@ namespace CGAL {
Primitives m_primitives; Primitives m_primitives;
// single root node // single root node
Node* m_p_root_node; Node* m_p_root_node;
#ifdef CGAL_HAS_THREADS
mutable boost::mutex internal_tree_mutex;//mutex used to protect const calls inducing build()
#endif
const Node* root_node() const { const Node* root_node() const {
#ifdef CGAL_HAS_THREADS
//this ensure that build() will be called once
boost::mutex::scoped_lock scoped_lock(internal_tree_mutex);
#endif
if(m_need_build) if(m_need_build)
const_cast< AABB_tree<AABBTraits>* >(this)->build(); //THIS IS NOT THREADSAFE const_cast< AABB_tree<AABBTraits>* >(this)->build();
return m_p_root_node; return m_p_root_node;
} }

View File

@ -107,7 +107,8 @@ CGAL 3.10 offers the following improvements and new functionality : </p>
<h3>AABB tree</h3> <h3>AABB tree</h3>
<ul> <ul>
<li>Fix constness issues in the AABB_tree class.</li> <li>Document constness of member functions of the AABB_tree class.</li>
<li>The class AABB_tree is now guarantee to be read-only thread-safe.</li>
</ul> </ul>
<h2 id="release3.9">Release 3.9 </h2> <h2 id="release3.9">Release 3.9 </h2>