4747#include < boost/preprocessor/repetition/enum_binary_params.hpp>
4848#include < boost/preprocessor/repetition/enum.hpp>
4949
50+ #ifdef CGAL_HAS_THREADS
51+ # define CGAL_LAZY_USE_MUTEX 1
52+ #endif
53+
54+ #ifdef CGAL_LAZY_USE_MUTEX
55+ # include < CGAL/mutex.h>
56+ #endif
57+
5058namespace CGAL {
5159
5260template <typename AT, typename ET, typename EFT, typename E2A> class Lazy ;
@@ -62,16 +70,6 @@ approx(const Lazy<AT,ET, EFT, E2A>& l)
6270 return l.approx ();
6371}
6472
65- // Where is this one (non-const) needed ? Is it ?
66- template <typename AT, typename ET, typename EFT, typename E2A>
67- inline
68- AT&
69- approx (Lazy<AT,ET, EFT, E2A>& l)
70- {
71- return l.approx ();
72- }
73-
74-
7573template <typename AT, typename ET, typename EFT, typename E2A>
7674inline
7775const ET&
@@ -231,6 +229,9 @@ class Lazy_rep : public Rep, public Depth_base
231229
232230 mutable AT at;
233231 mutable ET *et;
232+ #ifdef CGAL_LAZY_USE_MUTEX
233+ mutable CGAL_MUTEX update_exact_mutex;
234+ #endif
234235
235236 Lazy_rep ()
236237 : at(), et(NULL ){}
@@ -243,25 +244,24 @@ class Lazy_rep : public Rep, public Depth_base
243244
244245 const AT& approx () const
245246 {
246- return at;
247- }
248-
249- AT& approx ()
250- {
247+ #ifdef CGAL_LAZY_USE_MUTEX
248+ CGAL_SCOPED_LOCK (update_exact_mutex);
249+ #endif
251250 return at;
252251 }
253252
254253 const ET & exact () const
255254 {
255+ #ifdef CGAL_LAZY_USE_MUTEX
256256 if (et==NULL )
257- update_exact ();
258- return *et;
259- }
260-
261- ET & exact ()
262- {
257+ {
258+ CGAL_SCOPED_LOCK (update_exact_mutex);
259+ if (et==NULL ) update_exact ();
260+ }
261+ #else // not CGAL_LAZY_USE_MUTEX
263262 if (et==NULL )
264263 update_exact ();
264+ #endif // not CGAL_LAZY_USE_MUTEX
265265 return *et;
266266 }
267267
@@ -762,12 +762,6 @@ public :
762762 const ET& exact () const
763763 { return ptr ()->exact (); }
764764
765- AT& approx ()
766- { return ptr ()->approx (); }
767-
768- ET& exact ()
769- { return ptr ()->exact (); }
770-
771765 unsigned depth () const
772766 {
773767 return ptr ()->depth ();
0 commit comments