Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58834 - in sandbox/stm/branches/vbe/boost/stm: . detail non_tx/detail tx txw
From: vicente.botet_at_[hidden]
Date: 2010-01-09 08:48:25


Author: viboes
Date: 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
New Revision: 58834
URL: http://svn.boost.org/trac/boost/changeset/58834

Log:
TBoost.STM vbe: Manage with Shallow copy
* rename copy_state by copy_cache
* remove cache_clone and cache_copy
* Added requirement to static make_cache and added make_cache template class able to dispatch to static or dynamic polymorphism.
* parameterize write family functions with static or dynamic polymorphism parameter
* added write_dyn family function managing dynamic polymorphism writes.
* make more robust cache_allocate
* add addres_of free function to convert object<T> to pointer<T>
Text files modified:
   sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp | 41 +++++++++-
   sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp | 4
   sandbox/stm/branches/vbe/boost/stm/detail/config.hpp | 2
   sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 6
   sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp | 32 +++++--
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 158 +++++++++++----------------------------
   sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp | 6
   sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp | 26 +++++-
   sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp | 3
   sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp | 15 +++
   sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp | 81 ++++----------------
   sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp | 21 +++-
   sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp | 96 ++++--------------------
   13 files changed, 197 insertions(+), 294 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -38,6 +38,36 @@
 //-----------------------------------------------------------------------------
 class transaction;
 
+//~ template <typename T>
+//~ T* make_cache(T const& rhs, transaction& t) {
+ //~ return new T(rhs);
+//~ };
+
+struct static_poly {};
+struct dyn_poly {};
+
+namespace detail {
+ template <typename Poly>
+ struct make_cache_aux;
+
+ template <>
+ struct make_cache_aux<static_poly> {
+ template <typename T>
+ static T* apply(T & rhs, transaction& t) {
+ //return T::make_cache(rhs, &t);
+ return static_cast<T*>(rhs.make_cache(t));
+ }
+ };
+
+ template <>
+ struct make_cache_aux<dyn_poly> {
+ template <typename T>
+ static T* apply(T & rhs, transaction& t) {
+ return static_cast<T*>(rhs.make_cache(t));
+ };
+ };
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // this is the base class of all the transactional objects.
@@ -46,10 +76,10 @@
 // version: the version when performing validation
 // newMemory_: states whether this object is a new object
 // transactional objets must specialize the pure virtual functions
-// copy_state(base_transaction_object const * const rhs)
+// copy_cache(base_transaction_object const & rhs)
 // move_state(base_transaction_object * rhs) if BUILD_MOVE_SEMANTICS
 // delete_cache()
-// copy_state is used to copy the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
+// copy_cache is used to copy the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
 // move_state is used to move the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
 // delete_cache is used to release the backup/working copy when the transaction ends if direct/defered policy is used
 // when USE_STM_MEMORY_MANAGER is defined this class provides two functions (retrieve_mem and return_mem) and to manage a pool of memory
@@ -83,8 +113,8 @@
     {}
 #endif
 
- virtual base_transaction_object* make_cache(transaction* t) const = 0;
- virtual void copy_state(base_transaction_object const * const rhs) = 0;
+ virtual base_transaction_object* make_cache(transaction& t) const = 0;
+ virtual void copy_cache(base_transaction_object const & rhs) = 0;
 #if BUILD_MOVE_SEMANTICS
     virtual void move_state(base_transaction_object * rhs) = 0;
 #else
@@ -107,7 +137,7 @@
     std::list<base_transaction_object*>& binds() {return embeddeds_;}
     void bind(base_transaction_object* bto) {embeddeds_.push_back(bto);}
 #endif
-
+
 private:
 
     //--------------------------------------------------------------------------
@@ -131,6 +161,7 @@
 #endif
 };
 
+
 } // namespace core
 }
 #endif // BOOST_STM_BASE_TRANSACTION_OBJECT__HPP

Modified: sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -38,12 +38,10 @@
 class base_transaction_object;
 class transaction;
 
-template <class T> T* cache_clone(const T& val);
-template <class T> void cache_copy(const T* const ori, T* target);
 void cache_release(base_transaction_object* ptr);
 
 
-template <class T> T* cache_allocate(transaction*);
+template <class T> T* cache_allocate(transaction&);
 template <class T> void cache_deallocate(T*);
 
 

Modified: sandbox/stm/branches/vbe/boost/stm/detail/config.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/config.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/config.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -104,7 +104,7 @@
 //// BOOST_STM_CACHE_USE_CLASS_MEMORY_MANAGER: uses the class specific memory manager
 //// BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER: uses the monotonic storage memory manager
 
-//#define BOOST_STM_CACHE_USE_MALLOC 1
+#define BOOST_STM_CACHE_USE_MALLOC 1
 #if defined(BOOST_STM_USE_GLOBAL_MEMORY_MANAGER)
 //#define BOOST_STM_CACHE_USE_MEMORY_MANAGER 1
 #endif

Modified: sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -1787,7 +1787,7 @@
       // i->second == 0 will happen when a transaction has added a piece of
       // memory to its writeList_ that it is deleting (not writing to).
       // Thus, when seeing 0 as the second value, it signifies that this
- // memory is being destroyed, not updated. Do not perform copy_state()
+ // memory is being destroyed, not updated. Do not perform copy_cache()
       // on it.
       //
       // However, deleted memory MUST reset its invalid_thread_id()
@@ -1797,7 +1797,7 @@
       if (0 == i->second) continue;
 
       if (using_move_semantics()) i->first->move_state(i->second);
- else i->first->copy_state(i->second);
+ else i->first->copy_cache(*i->second);
       i->first->transaction_thread(invalid_thread_id());
 
       cache_release(i->second);
@@ -1978,7 +1978,7 @@
       }
 
       if (using_move_semantics()) i->first->move_state(i->second);
- else i->first->copy_state(i->second);
+ else i->first->copy_cache(*i->second);
 
       i->first->transaction_thread(invalid_thread_id());
       i->first->new_memory(0);

Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -76,22 +76,34 @@
     }
 
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- virtual base_transaction_object* make_cache(transaction* t) const {
+ static cache<T>* make_cache(cache<T> const& rhs, transaction& t) {
         cache<T>* p = cache_allocate<cache<T> >(t);
- if (p==0) {
- throw std::bad_alloc();
+ ::new (p) cache<T>(*static_cast<cache<T> const*>(&rhs));
+ return p;
+
+ if (p->value_!=0) {
+ p->ptr_ = new T(*(rhs.value_));
         }
+ return p;
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ cache<T>* p = cache_allocate<cache<T> >(t);
         ::new (p) cache<T>(*static_cast<cache<T> const*>(this));
         return p;
+ //~ return make_cache(*this, t);
+
+ }
 #else
- virtual base_transaction_object* make_cache(transaction*) const {
+ static cache<T>* make_cache(cache<T> const& rhs, transaction& ) {
+ cache* p = new cache<T>(rhs);
+ return p;
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ //~ return make_cache(*this, t);
         cache* p = new cache<T>(*this);
-#endif
- if (p->value_!=0) {
- p->ptr_ = new T(*value_);
- }
         return p;
     }
+#endif
 
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
     virtual void delete_cache() {
@@ -108,9 +120,9 @@
     }
 #endif
 
- virtual void copy_state(base_transaction_object const * const rhs) {
+ virtual void copy_cache(base_transaction_object const &rhs) {
         if (value_==0) return;
- *value_= *(static_cast<cache<T> const * const>(rhs)->ptr_);
+ *value_= *(static_cast<cache<T> const * const>(&rhs)->ptr_);
         delete ptr_;
         ptr_=0;
     }

Modified: sandbox/stm/branches/vbe/boost/stm/transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -521,25 +521,41 @@
    template <typename T> T* write_ptr(T* in)
    {
       if (0 == in) return 0;
- return &write(*in);
+ return &write_poly<T,static_poly>(*in);
    }
- template <typename T> T& w(T& in) { return write(in); }
-
- //--------------------------------------------------------------------------
+ template <typename T> T& w(T& in) { return write_poly<T,static_poly>(in); }
    template <typename T>
    inline T& write(T& in)
    {
+ return write_poly<T,static_poly>(in);
+ }
+
+ template <typename T> T* write_ptr_dyn(T* in)
+ {
+ if (0 == in) return 0;
+ return &write_poly<T,dyn_poly>(*in);
+ }
+ template <typename T>
+ inline T& write_dyn(T& in)
+ {
+ return write_poly<T,dyn_poly>(in);
+ }
+
+ //--------------------------------------------------------------------------
+ template <typename T, typename Poly>
+ inline T& write_poly(T& in)
+ {
       if (direct_updating())
       {
 #if PERFORMING_VALIDATION
          throw "direct updating not implemented for validation yet";
 #else
- return direct_write(in);
+ return direct_write<T,Poly>(in);
 #endif
       }
       else
       {
- return deferred_write(in);
+ return deferred_write<T,Poly>(in);
       }
    }
 
@@ -955,7 +971,7 @@
    }
 
    //--------------------------------------------------------------------------
- template <typename T>
+ template <typename T, typename Poly>
    T& direct_write(T& in)
    {
       // if this is our memory (new or mod global) just return
@@ -982,7 +998,7 @@
       }
 
       in.transaction_thread(threadId_);
- writeList().insert(tx_pair((base_transaction_object*)&in, in.make_cache(this)));
+ writeList().insert(tx_pair((base_transaction_object*)&in, detail::make_cache_aux<Poly>::apply(in , *this)));
 #if USE_BLOOM_FILTER
       bloom().insert((std::size_t)&in);
 #endif
@@ -1171,7 +1187,7 @@
    }
 
 private:
- template <typename T>
+ template <typename T, typename Poly>
    T& deferred_write(T& in)
    {
       if (forced_to_abort())
@@ -1203,7 +1219,7 @@
          wbloom().set_bv2(bloom().h2());
          //sm_wbv().set_bit((size_t)&in % sm_wbv().size());
 #endif
- base_transaction_object* returnValue = in.make_cache(this);
+ base_transaction_object* returnValue = detail::make_cache_aux<Poly>::apply(in, *this);
          returnValue->transaction_thread(threadId_);
          writeList().insert(tx_pair((base_transaction_object*)&in, returnValue));
          return *static_cast<T*>(returnValue);
@@ -2131,13 +2147,20 @@
 
 
 #if defined(BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER)
-template <class T> T* cache_allocate(transaction* t) {
+template <class T> T* cache_allocate(transaction& t) {
     #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER)
- return reinterpret_cast<T*>(base_memory_manager::retrieve_mem(sizeof(T)));
+ T* res= reinterpret_cast<T*>(base_memory_manager::retrieve_mem(sizeof(T)));
+ if (res==0) throw std::bad_alloc();
+ return res;
     #elif defined(BOOST_STM_CACHE_USE_MALLOC)
- return reinterpret_cast<T*>(malloc(sizeof(T)));
+ T* res= reinterpret_cast<T*>(malloc(sizeof(T)));
+ if (res==0) throw std::bad_alloc();
+ return res;
+ //return reinterpret_cast<T*>(::new char[sizeof(T)]);
     #elif defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
- return reinterpret_cast<T*>(t->context_.mstorage_.allocate<T>());
+ T* res= reinterpret_cast<T*>(t.context_.mstorage_.allocate<T>());
+ if (res==0) throw std::bad_alloc();
+ return res;
     #else
     return 0;
     #error "BOOST_STM_CACHE_USE_MEMORY_MANAGER, BOOST_STM_CACHE_USE_MALLOC or BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER must be defined"
@@ -2145,53 +2168,22 @@
 }
 #endif
 
-// this function must be specialized for objects that are non transactional
-// by deleting the object
-
 #if defined(BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER)
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-template <class T>
-struct cache_deallocate;
-
-template <class T>
-struct cache_deallocate {
- static void apply(T* ptr) {
- if (ptr) {
- #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER)
- base_memory_manager::return_mem(ptr,sizeof(T));
- #elif defined(BOOST_STM_CACHE_USE_MALLOC)
- free(ptr);
- #elif defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
- #else
- #error "BOOST_STM_CACHE_USE_MEMORY_MANAGER, BOOST_STM_CACHE_USE_MALLOC or BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER must be defined"
- #endif
- }
- }
-};
-
-}
-
-template <class T> void cache_deallocate(T*ptr) {
- partial_specialization_workaround::cache_deallocate<T>::apply(ptr);
-}
-
-#else //!BOOST_STM_NO_PARTIAL_SPECIALIZATION
 
 template <class T>
 inline void cache_deallocate(T* ptr) {
     if (ptr) {
- #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER
+ #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER)
         base_memory_manager::return_mem(ptr,sizeof(T));
     #elif defined(BOOST_STM_CACHE_USE_MALLOC)
         free(ptr);
+ //delete [] ptr;
     #elif defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
     #else
- #error "BOOST_STM_CACHE_USE_MEMORY_MANAGER or BOOST_STM_CACHE_USE_MALLOC must be defined"
+ #error "BOOST_STM_CACHE_USE_MEMORY_MANAGER, BOOST_STM_CACHE_USE_MALLOC or BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER must be defined"
     #endif
- }
+ }
 }
-#endif //BOOST_STM_NO_PARTIAL_SPECIALIZATION
 #endif
 
 inline void cache_release(base_transaction_object* ptr) {
@@ -2199,70 +2191,6 @@
     ptr->delete_cache();
 }
 
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-template <class T>
-struct cache_clone;
-
-template <class T>
-struct cache_clone {
- static inline T* apply(transaction* t, const T& val) {
- T* p = cache_allocate<T>(t);
- if (p==0) {
- throw std::bad_alloc();
- }
- boost::stm::cache_copy(&val, p);
- return p;
- }
-};
-
-} // partial_specialization_workaround
-
-template <class T>
-inline T* cache_clone(transaction* t, const T& val) {
- return partial_specialization_workaround::cache_clone<T>::apply(t, val);
-}
-#else //BOOST_STM_NO_PARTIAL_SPECIALIZATION
-
-template <class T>
-inline T* cache_clone(transaction* t, const T& val) {
- T* p = cache_allocate<T>(t);
- if (p==0) {
- throw std::bad_alloc();
- }
- cache_copy(&val, p);
- return p;
-}
-#endif // BOOST_STM_NO_PARTIAL_SPECIALIZATION
-
-
-template <class T> void cache_copy(const T* const ori, T* target);
-
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-template <class T> struct cache_copy;
-
-
-template <class T>
-struct cache_copy {
- static inline void apply(const T* const ori, T* target) {
- memcpy(target, ori, sizeof(T));
- }
-};
-
-} // partial_specialization_workaround
-
-template <class T> void cache_copy(const T* const ori, T* target) {
- partial_specialization_workaround::cache_copy<T>::apply(ori, target);
-}
-
-#else
-
-template <class T> void cache_copy(const T* const ori, T* target) {
- memcpy(target, ori, sizeof(T));
-}
-#endif
-
 //-----------------------------------------------------------------------------
 // scoped thread initializer calling transaction::initialize_thread() in the
 // constructor and transaction::terminate_thread() in the destructor
@@ -2272,6 +2200,10 @@
     ~thread_initializer() {transaction::terminate_thread();}
 };
 
+template <typename T>
+void delete_ptr(transaction& t, T *in) {
+ t.delete_ptr(in);
+}
 
 //---------------------------------------------------------------------------
 // do not remove if (). It is necessary a necessary fix for compilers

Modified: sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -72,7 +72,7 @@
 // transaction object mixin
 // Provides the definition of the virtual functions
 // make_cache: use copy constructor
-// copy_state: use assignement
+// copy_cache: use assignement
 // move_state and
 // delete_cache: use delete
 // Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
@@ -128,9 +128,9 @@
 #endif
 
    //--------------------------------------------------------------------------
- virtual void copy_state(base_transaction_object const * const rhs)
+ virtual void copy_cache(base_transaction_object const & rhs)
    {
- *static_cast<Final *>(this) = *static_cast<Final const * const>(rhs);
+ *static_cast<Final *>(this) = *static_cast<Final const *>(&rhs);
    }
 
 #if BUILD_MOVE_SEMANTICS

Modified: sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -43,7 +43,7 @@
 // transaction object mixin
 // Provides the definition of the virtual functions
 // make_cache: use copy constructor
-// copy_state: use assignement
+// copy_cache: use assignement
 // move_state and
 // delete_cache: use delete
 // Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
@@ -70,13 +70,27 @@
 
     //--------------------------------------------------------------------------
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- virtual base_transaction_object* make_cache(transaction* t) const {
+ static Final* make_cache(Final const& rhs, transaction& t) {
         Final* p = cache_allocate<Final>(t);
- ::new (p) Final(*static_cast<Final const*>(this));
+ ::new (p) Final(*static_cast<Final const*>(&rhs));
         return p;
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ Final const& f=*static_cast<Final const*>(this);
+ return make_cache(f, t);
+ //~ return make_cache(*static_cast<Final const*>(this), t);
+ //~ Final* p = cache_allocate<Final>(t);
+ //~ ::new (p) Final(*static_cast<Final const*>(this));
+ //~ return p;
     }
 #else
- virtual base_transaction_object* make_cache(transaction*) const {
+ static Final* make_cache(Final const& rhs, transaction& ) {
+ Final* tmp = new Final(*static_cast<Final const*>(&rhs));
+ return tmp;
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ //~ Final const& f=*static_cast<Final const*>(this);
+ //~ return make_cache(f, t);
         Final* tmp = new Final(*static_cast<Final const*>(this));
         return tmp;
     }
@@ -95,9 +109,9 @@
 #endif
 
    //--------------------------------------------------------------------------
- virtual void copy_state(base_transaction_object const * const rhs)
+ virtual void copy_cache(base_transaction_object const & rhs)
    {
- *static_cast<Final *>(this) = *static_cast<Final const * const>(rhs);
+ *static_cast<Final *>(this) = *static_cast<Final const *>(&rhs);
    }
 
 #if BUILD_MOVE_SEMANTICS

Modified: sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -77,6 +77,9 @@
         return val_;
     }
 
+ T* address_of() {
+ return &val_;
+ }
     //-----------------------------------------------------------------------------
     T value() const {
         transaction* tx=current_transaction();

Modified: sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -46,6 +46,11 @@
             //std::cerr << __LINE__ << " pointer" << std::endl;
     }
     
+ template<class U, class V, class B>
+ pointer(mixin<U, V*, B> const& rhs) : base_type(rhs.value()) {
+ //std::cerr << __LINE__ << " pointer" << std::endl;
+ }
+
     pointer(T* v) : base_type(v) {
             //std::cerr << __LINE__ << " pointer" << std::endl;
     }
@@ -54,6 +59,11 @@
             //std::cerr << __LINE__ << " pointer" << std::endl;
     }
 
+ template<class U, class V, class B>
+ pointer& operator=(mixin<U, V*, B> const& rhs) {
+ this->val_=rhs.value();
+ };
+
     T* operator->() const {
         return this->value();
     }
@@ -70,6 +80,11 @@
 
 };
 
+template <typename T>
+pointer<T> address_of(object<T>& obj) {
+ return pointer<T>(obj.address_of());
+}
+
 template <typename C, typename R>
 class pointer_to_member : public mixin< pointer_to_member<C,R>, R C::*>
 {

Modified: sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -26,6 +26,7 @@
 #include <boost/stm/cache_fct.hpp>
 #include <boost/stm/datatypes.hpp>
 #include <boost/stm/memory_managers/memory_manager.hpp>
+#include <boost/mpl/bool.hpp>
 //-----------------------------------------------------------------------------
 
 //-----------------------------------------------------------------------------
@@ -38,10 +39,6 @@
  struct has_shallow_copy_semantics : boost::mpl::false_
  {};
      
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class transaction;
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -49,7 +46,7 @@
 // transaction object mixin making shallow copy
 // Provides the definition of the virtual functions
 // make_cache: use shallow copy constructor on cache_allocated area
-// copy_state: use shallow assignement
+// copy_cache: use shallow assignement
 // move_state and
 // delete_cache: use cache_deallocate
 // Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
@@ -73,12 +70,21 @@
 #else
     typedef Base base_type;
 #endif
+ Final& final() { return *static_cast<Final*>(this); }
+ const Final& final() const { return *static_cast<Final const*>(this); }
 public:
 
- //--------------------------------------------------------------------------
- virtual base_transaction_object* make_cache(transaction* t) const {
+ static Final* make_cache(Final const& rhs, transaction& t) {
         Final* p = cache_allocate<Final>(t);
- return new(p) Final(this, shallow);
+ return ::new(p) Final(rhs, shallow);
+ };
+
+
+ //--------------------------------------------------------------------------
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ return make_cache(final(), t);
+ //~ Final* p = cache_allocate<Final>(t);
+ //~ return ::new(p) Final(final(), shallow);
     }
 
    //--------------------------------------------------------------------------
@@ -87,73 +93,20 @@
     }
 
    //--------------------------------------------------------------------------
- virtual void copy_state(base_transaction_object const * const rhs)
+ virtual void copy_cache(base_transaction_object const &rhs)
    {
- boost::stm::cache_copy(static_cast<Final const * const>(rhs), static_cast<Final *>(this));
+ final().shallow_assign(*static_cast<Final const *>(&rhs));
    }
 
 #if BUILD_MOVE_SEMANTICS
    virtual void move_state(base_transaction_object * rhs)
    {
- static_cast<Final &>(*this) = draco_move
- (*(static_cast<Final*>(rhs)));
+ final() = draco_move(*(static_cast<Final*>(rhs)));
    }
 #endif
 
 };
 
-template <typename T> class shallow_native_trans :
-public shallow_transaction_object< shallow_native_trans<T> >
-{
-public:
-
- shallow_native_trans() : value_(T()) {}
- shallow_native_trans(T const &rhs) : value_(rhs) {}
- shallow_native_trans(shallow_native_trans const &rhs) : value_(rhs.value_) {}
- ~shallow_native_trans() {}
-
- shallow_native_trans& operator=(T const &rhs) { value_ = rhs; return *this; }
-
- shallow_native_trans& operator--() { --value_; return *this; }
- shallow_native_trans operator--(int) { shallow_native_trans n = *this; --value_; return n; }
-
- shallow_native_trans& operator++() { ++value_; return *this; }
- shallow_native_trans operator++(int) { shallow_native_trans n = *this; ++value_; return n; }
-
- shallow_native_trans& operator+=(T const &rhs)
- {
- value_ += rhs;
- return *this;
- }
-
- shallow_native_trans operator+(shallow_native_trans const &rhs)
- {
- shallow_native_trans ret = *this;
- ret.value_ += rhs.value_;
- return ret;
- }
-
- //template <>
- operator T() const
- {
- return this->value_;
- }
-
-#if BUILD_MOVE_SEMANTICS
- //--------------------------------------------------
- // move semantics
- //--------------------------------------------------
- shallow_native_trans(shallow_native_trans &&rhs) { value_ = rhs.value_;}
- shallow_native_trans& operator=(shallow_native_trans &&rhs)
- { value_ = rhs.value_; return *this; }
-#endif
-
- T& value() { return value_; }
- T const & value() const { return value_; }
-
-private:
- T value_;
-};
 
 }}
 #endif // BOOST_STM_SHALLOW_TRANSACTION_OBJECT__HPP

Modified: sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -54,7 +54,7 @@
 // transaction object mixin making a trivial memcpy copy
 // Provides the definition of the virtual functions
 // make_cache: use memcpy on cache_allocated
-// copy_state: use memcpy
+// copy_cache: use memcpy
 // move_state and
 // delete_cache: use cache_allocated
 // Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
@@ -78,12 +78,20 @@
 #else
     typedef Base base_type;
 #endif
+ Final* final() { return static_cast<Final*>(this); }
+ const Final* final() const { return static_cast<Final const*>(this); }
 public:
+ static Final* make_cache(Final const& rhs, transaction& t) {
+ Final* p = cache_allocate<Final>(t);
+ std::memcpy(p, static_cast<Final const*>(&rhs), sizeof(Final));
+ return p;
+ };
 
     //--------------------------------------------------------------------------
- virtual base_transaction_object* make_cache(transaction* t) const {
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ //~ return make_cache(*final(), t);
         Final* p = cache_allocate<Final>(t);
- boost::stm::cache_copy(static_cast<Final const*>(this), p);
+ std::memcpy(p, final(), sizeof(Final));
         return p;
     }
 
@@ -93,16 +101,15 @@
     }
 
    //--------------------------------------------------------------------------
- virtual void copy_state(base_transaction_object const * const rhs)
+ virtual void copy_cache(base_transaction_object const &rhs)
    {
- boost::stm::cache_copy(static_cast<Final const * const>(rhs), static_cast<Final *>(this));
+ std::memcpy(final(), static_cast<Final const *>(&rhs), sizeof(Final));
    }
 
 #if BUILD_MOVE_SEMANTICS
    virtual void move_state(base_transaction_object * rhs)
    {
- static_cast<Final &>(*this) = draco_move
- (*(static_cast<Final*>(rhs)));
+ *final() = draco_move(*(static_cast<Final*>(rhs)));
    }
 #endif
 

Modified: sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp 2010-01-09 08:48:24 EST (Sat, 09 Jan 2010)
@@ -27,9 +27,9 @@
 // A transactional_object<T> is a base_transaction_object wrapping an instance of type T
 // Provides the definition of the virtual functions
 // forward constructors to the wrapped type
-// copy_state: relaying on the cache_copy<T> generic function
+// copy_cache: relaying on the assignement operator generic function
 // move_state and
-// delete_cache: relaying on the cache_copy<T> generic function
+// delete_cache: relaying on the cache_deallocate<T> generic function
 // Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
 //
 // If a class D inherits from B we have that transactional_object<D> dont inherits from transactional_object<B>, but
@@ -85,18 +85,26 @@
         value = r.value;
         return *this;
     }
+
 
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- virtual base_transaction_object* make_cache(transaction* t) const {
+ static transactional_object<T>* make_cache(transactional_object<T> const& rhs, transaction& t) {
+ transactional_object<T>* p = cache_allocate<transactional_object<T> >(t);
+ std::memcpy(p, static_cast<transactional_object<T> const*>(&rhs), sizeof(transactional_object<T>));
+ return p;
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
         transactional_object<T>* p = cache_allocate<transactional_object<T> >(t);
- if (p==0) {
- throw std::bad_alloc();
- }
         ::new (p) transactional_object<T>(*static_cast<transactional_object<T> const*>(this));
         return p;
+ //~ return make_cache(*this, t);
     }
 #else
- virtual base_transaction_object* make_cache(transaction*) const {
+ static transactional_object<T>* make_cache(transactional_object<T> const& rhs, transaction&) {
+ return new transactional_object<T>(rhs);
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ //~ return make_cache(*this, t);
         return new transactional_object<T>(*this);
     }
 #endif
@@ -112,9 +120,8 @@
     }
 #endif
 
- virtual void copy_state(base_transaction_object const * const rhs) {
- //cache_copy(static_cast<transactional_object<T> const * const>(rhs), this);
- *this=*static_cast<transactional_object<T> const * const>(rhs);
+ virtual void copy_cache(base_transaction_object const & rhs) {
+ *this=*static_cast<transactional_object<T> const *>(&rhs);
     }
 
 };
@@ -146,75 +153,6 @@
 }
 
 
-
-#ifdef BOOST_STM_USE_MEMCOPY
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-
-template <class T, class A>
-struct cache_clone<transactional_object<std::vector<T,A> > > {
- static inline transactional_object<std::vector<T,A> >* apply(const transactional_object<std::vector<T,A> >& val) {
- return new transactional_object<std::vector<T,A> >(val);
- }
-};
-} // partial_specialization_workaround
-
-#else //BOOST_STM_NO_PARTIAL_SPECIALIZATION
-
-template <class T>
-inline transactional_object<std::vector<T> >* cache_clone(const transactional_object<std::vector<T> >& val) {
- return new transactional_object<std::vector<T> >(val);
-}
-
-#endif // BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#endif
-
-
-
-#ifdef BOOST_STM_USE_MEMCOPY
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-
-template <class T>
-struct cache_copy<transactional_object<std::vector<T> > > {
- static inline void apply(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
- *target=*ori;
- }
-};
-
-} // partial_specialization_workaround
-#else
-template <class T> void cache_copy(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
- *target=*ori;
-}
-#endif
-#endif
-
-
-#ifdef BOOST_STM_USE_MEMCOPY
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-
-template <class T>
-struct cache_deallocate<transactional_object<std::vector<T> > > {
- static void apply(transactional_object<std::vector<T> >* ptr) {
- delete ptr;
- }
-};
-
-}
-
-#else //!BOOST_STM_NO_PARTIAL_SPECIALIZATION
-
-template <class T>
-inline void delete_cache(transactional_object<std::vector<T> >* ptr) {
- delete ptr;
-}
-
-#endif //BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#endif // BOOST_STM_USE_MEMCOPY
-
-
 } // namespace core
 }
 #endif // BASE_TRANSACTION_H


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk