From: Braden M. <br...@us...> - 2005-11-02 15:41:17
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30333/src/libopenvrml/openvrml Modified Files: field_value.cpp field_value.h Log Message: field_value's reference-counted value object needs to be protected by a mutex. Index: field_value.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/field_value.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** field_value.cpp 30 Oct 2005 03:20:17 -0000 1.14 --- field_value.cpp 2 Nov 2005 15:41:04 -0000 1.15 *************** *** 104,107 **** --- 104,113 ---- /** + * @var boost::mutex openvrml::field_value::counted_impl::mutex_ + * + * @brief Mutex protecting @a value_. + */ + + /** * @var boost::shared_ptr<ValueType> openvrml::field_value::counted_impl::value_ * *************** *** 122,125 **** --- 128,151 ---- /** + * @fn openvrml::field_value::counted_impl::counted_impl(const counted_impl<ValueType> & ci) throw () + * + * @brief Construct a copy. + * + * @param ci the instance to copy. + */ + + /** + * @fn openvrml::field_value::counted_impl::~counted_impl() throw () + * + * @brief Destroy. + */ + + /** + * @fn openvrml::field_value::counted_impl<ValueType> & openvrml::field_value::counted_impl::operator=(const counted_impl<ValueType> &) + * + * @brief Not implemented. + */ + + /** * @fn const ValueType & openvrml::field_value::counted_impl::value() const throw () * Index: field_value.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/field_value.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** field_value.h 30 Oct 2005 03:20:17 -0000 1.12 --- field_value.h 2 Nov 2005 15:41:04 -0000 1.13 *************** *** 32,35 **** --- 32,36 ---- # include <boost/shared_ptr.hpp> # include <boost/utility.hpp> + # include <boost/thread/mutex.hpp> # include <openvrml/basetypes.h> *************** *** 59,62 **** --- 60,64 ---- template <typename ValueType> class counted_impl : public counted_impl_base { + mutable boost::mutex mutex_; boost::shared_ptr<ValueType> value_; *************** *** 64,71 **** --- 66,79 ---- explicit counted_impl(const ValueType & value) throw (std::bad_alloc); + counted_impl(const counted_impl<ValueType> & ci) throw (); + virtual ~counted_impl() throw (); + const ValueType & value() const throw (); void value(const ValueType & val) throw (std::bad_alloc); private: + counted_impl<ValueType> & + operator=(const counted_impl<ValueType> &); + virtual std::auto_ptr<counted_impl_base> do_clone() const throw (std::bad_alloc); *************** *** 159,165 **** --- 167,187 ---- template <typename ValueType> + field_value::counted_impl<ValueType>:: + counted_impl(const counted_impl<ValueType> & ci) throw (): + counted_impl_base() + { + boost::mutex::scoped_lock lock(ci.mutex_); + value_ = ci.value_; + } + + template <typename ValueType> + field_value::counted_impl<ValueType>::~counted_impl() throw () + {} + + template <typename ValueType> const ValueType & field_value::counted_impl<ValueType>::value() const throw () { + boost::mutex::scoped_lock lock(this->mutex_); assert(this->value_); return *this->value_; *************** *** 170,173 **** --- 192,196 ---- throw (std::bad_alloc) { + boost::mutex::scoped_lock lock(this->mutex_); assert(this->value_); if (!this->value_.unique()) { *************** *** 218,222 **** { assert(this->counted_impl_.get()); ! return boost::polymorphic_downcast< counted_impl<typename FieldValue::value_type> *>( this->counted_impl_.get())->value(val); --- 241,245 ---- { assert(this->counted_impl_.get()); ! boost::polymorphic_downcast< counted_impl<typename FieldValue::value_type> *>( this->counted_impl_.get())->value(val); |