$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r56308 - in sandbox/stm/branches/vbe: boost boost/stm boost/stm/detail libs/stm/src libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-09-19 08:26:49
Author: viboes
Date: 2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
New Revision: 56308
URL: http://svn.boost.org/trac/boost/changeset/56308
Log:
TBoost.Stm vbe
* Adding transactional_object.hpp, tx_smart_ptr.hpp and non_tx_smart_ptr.hpp
* renaming of cache_restore by cache_copy
* renaming of cache_new_copy by cache_clone
Added:
   sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp   (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp   (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx_smart_ptr.hpp   (contents, props changed)
Text files modified: 
   sandbox/stm/branches/vbe/boost/stm.hpp                  |     2                                         
   sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp |   207 ------------                            
   sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp    |   617 ----------------------------------------
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp      |    88 +----                                   
   sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp   |     5                                         
   sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2       |     3                                         
   6 files changed, 48 insertions(+), 874 deletions(-)
Modified: sandbox/stm/branches/vbe/boost/stm.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm.hpp	(original)
+++ sandbox/stm/branches/vbe/boost/stm.hpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -38,6 +38,8 @@
 #include <boost/stm/transaction.hpp>
 #include <boost/stm/contention_manager.hpp>
 #include <boost/stm/detail/tx_ptr.hpp>
+#include <boost/stm/tx_smart_ptr.hpp>
+#include <boost/stm/non_tx_smart_ptr.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 #endif // TRANSACTION_H
Modified: sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp	(original)
+++ sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -55,9 +55,17 @@
 // forward declarations
 //-----------------------------------------------------------------------------
 
+class base_transaction_object;
+    
+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> inline T* cache_clone_constructor(const T&);
+    
+template <class T> T* cache_allocate();
 template <class T> void cache_deallocate(T*);
-template <class T> void cache_restore(const T* const ori, T* target);
-template <class T> inline T* cache_new_copy_constructor(const T&);
+
 class transaction;
 
 #ifndef BOOST_STM_USE_BOOST_MUTEX
@@ -301,9 +309,9 @@
 //-----------------------------------------------------------------------------
 // transaction object mixin
 // Provides the definition of the virtual functions
-//      copy_state: relaying on the cache_restore<T> generic function
+//      copy_state: relaying on the cache_copy<T> generic function
 //      move_state and
-//      cache_deallocate: relaying on the cache_restore<T> generic function
+//      cache_deallocate: relaying on the cache_copy<T> generic function
 // Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
 
 // The parameter Base=base_transaction_object allows to mic transaction_object and polymorphism
@@ -318,13 +326,13 @@
 
     //--------------------------------------------------------------------------
     virtual base_transaction_object* clone() const {
-        return cache_new_copy(*this);
+        return cache_clone(*this);
     }
 
    //--------------------------------------------------------------------------
    virtual void copy_state(base_transaction_object const * const rhs)
    {
-        boost::stm::cache_restore(static_cast<Derived const * const>(rhs), static_cast<Derived *>(this));
+        boost::stm::cache_copy(static_cast<Derived const * const>(rhs), static_cast<Derived *>(this));
    }
 
 #if BUILD_MOVE_SEMANTICS
@@ -410,193 +418,6 @@
    T value_;
 };
 
-
-//-----------------------------------------------------------------------------
-// transactional object wrapper
-// 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_restore<T> generic function
-//      move_state and
-//      cache_deallocate: relaying on the cache_restore<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
-// we can static/dynamic cast them robustly.
-// Evidently the std::static_cast/std::dynamic_cast do not works. We need to define the specific cast
-//
-// transactional_object<D>* d=...;
-// transactional_object<B>* b=tx_static_cast<B>(d);
-//
-// transactional_object<B>* b=...;
-// transactional_object<D>* d=tx_dynamic_cast<B>(b);
-//
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class transactional_object : public base_transaction_object {
-public:
-    T value;
-
-    transactional_object() {}
-    transactional_object(const T*ptr)
-        : base_transaction_object()
-        , value(*ptr) {}
-
-    transactional_object(transactional_object<T> const & r)
-        : base_transaction_object(r)
-        , value(r.value) {}
-
-    template <typename T1>
-    transactional_object(T1 const &p1)
-        : base_transaction_object()
-        , value(p1) {}
-
-    template <typename T1, typename T2>
-    transactional_object(T1 const &p1, T2 const &p2)
-        : base_transaction_object()
-        , value(p1,p2) {}
-
-    transactional_object & operator=(transactional_object const & r)  // =default never throws
-    {
-        value = r.value;
-        return *this;
-    }
-
-    virtual base_transaction_object* clone() const {
-        return cache_new_copy(*this);
-    }
-
-    virtual void copy_state(base_transaction_object const * const rhs) {
-        cache_restore(static_cast<transactional_object<T> const * const>(rhs),
-                      //static_cast<transactional_object<T> *>(this));
-                      this);
-    }
-
-#ifdef BOOST_STM_USE_MEMCOPY
-    virtual void cache_deallocate() {
-        boost::stm::cache_deallocate(this);
-    }
-#endif
-
-#if USE_STM_MEMORY_MANAGER
-   void* operator new(size_t size) throw ()
-   {
-      return retrieve_mem(size);
-   }
-
-   void operator delete(void* mem)
-   {
-      return_mem(mem, sizeof(transactional_object<T>));
-   }
-#endif
-
-};
-
-//-----------------------------------------------------------------------------
-// gets the transactional_object<T> pointer wrapping the T pointer
-//-----------------------------------------------------------------------------
-template <typename T>
-static transactional_object<T>* tx_up_cast(T* ptr) {
-    return reinterpret_cast<transactional_object<T>*>(reinterpret_cast<char*>(ptr)-offsetof(transactional_object<T>, value));
-}
-
-//-----------------------------------------------------------------------------
-// static_cast two transactional_object's
-//-----------------------------------------------------------------------------
-template <typename T, typename U>
-static transactional_object<T>* tx_static_cast(transactional_object<U>* ptr) {
-    return tx_up_cast(static_cast<T*>(&ptr->value));
-}
-
-//-----------------------------------------------------------------------------
-// dynamic_cast two transactional_object's
-//-----------------------------------------------------------------------------
-template <typename T, typename U>
-static transactional_object<T>* tx_dynamic_cast(transactional_object<U>* ptr) {
-    T* p = dynamic_cast<T*>(&ptr->value);
-    if (p==0) return 0;
-    return tx_up_cast(p);
-}
-
-//-----------------------------------------------------------------------------
-// This class defines the transactional cache of a non transactional variable.
-// There is a map from the address of the variable of type T to an instance of this class
-//
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class transactional_reference_cache : public base_transaction_object {
-public:
-    T* const value_;
-    mutable T* ptr_;
-
-    transactional_reference_cache(T& ref)
-        : base_transaction_object()
-        , value_(&ref), ptr_(0) {}
-
-    transactional_reference_cache(T* ptr)
-        : base_transaction_object()
-        , value_(ptr), ptr_(0) {}
-
-    ~transactional_reference_cache() {
-        delete ptr_;
-    }
-    T* get() const {
-        if(ptr_!=0) return ptr_;
-        else return value_;
-    }
-
-    virtual base_transaction_object* clone() const {
-        transactional_reference_cache tmp = cache_new_copy(*this);
-        if (tmp.value!=0) {
-            tmp.ptr_ = new T(*value_);
-        }
-        return tmp;
-    }
-
-    virtual void copy_state(base_transaction_object const * const rhs) {
-        if (value_==0) return;
-        *value_= *(static_cast<transactional_reference_cache<T> const * const>(rhs)->ptr_);
-        delete ptr_;
-        ptr_=0;
-    }
-
-#ifdef BOOST_STM_USE_MEMCOPY
-    virtual void cache_deallocate() {
-        delete ptr_;
-        ptr_=0;
-        boost::stm::cache_deallocate(this);
-    }
-#endif
-
-#if USE_STM_MEMORY_MANAGER
-   void* operator new(size_t size) throw ()
-   {
-      return retrieve_mem(size);
-   }
-
-   void operator delete(void* mem)
-   {
-      return_mem(mem, sizeof(transactional_object<T>));
-   }
-#endif
-
-private:
-    transactional_reference_cache(transactional_reference_cache<T> const & r)
-        : base_transaction_object(r)
-        , value_(r.value_), ptr_(r.ptr_) {}
-
-
-    transactional_reference_cache & operator=(transactional_reference_cache const & r)
-    {
-        value_ = r.value_;
-        ptr_ = r.ptr_;
-        return *this;
-    }
-
-};
-
 //-----------------------------------------------------------------------------
 class base_contention_manager
 {
Modified: sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp	(original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -16,8 +16,6 @@
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-#include <assert.h>
-#include <map>
 #include <boost/stm/transaction.hpp>
 
 //-----------------------------------------------------------------------------
@@ -25,548 +23,6 @@
 namespace boost { namespace stm {
 
 template <typename T>
-class rd_ptr;
-template <typename T>
-class wr_ptr;
-template <typename T>
-class upgrd_ptr;
-
-//-----------------------------------------------------------------------------
-// class tx_obj wraps a transactional_object providing builting operators
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class tx_obj {
-public:
-    transactional_object<T> obj_;
-
-    //-----------------------------------------------------------------------------
-    // default constructor valid ony if T has a default constructor
-
-    tx_obj() : obj_() {}
-
-    //
-    template<class Y>
-    tx_obj(tx_obj<Y> const& r) : obj_(r.ref()) {} // throws only if obj_ contructor throws
-
-    template <typename T1>
-    tx_obj(T1 p1) : obj_(p1) {}
-
-    #if 0
-    bool operator==(const tx_obj<T>& rhs) const {
-        return this->ref()==rhs.ref();
-    }
-
-    bool operator==(const T& rhs) const {
-        return this->ref()==rhs;
-    }
-    #endif
-
-    //operator T() const { return *this->get(); }
-
-    T* operator->() {
-        return this->get();
-    }
-    const T* operator->() const {
-        return this->get();
-    }
-    T& operator*() {
-        return this->ref();
-    }
-    const T& operator*() const {
-        return this->ref();
-    }
-    T* get() {
-        return &this->ref();
-    }
-    const T* get() const {
-        return &this->ref();
-    }
-    T& ref() {
-        transaction* tx=transaction::current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-            return tx->write(obj_).value;
-        }
-        return obj_.value;
-    }
-
-    const T& ref() const {
-        transaction* tx=transaction::current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-            return tx->read(obj_).value;
-        }
-        return obj_.value;
-    }
-
-
-    tx_obj& operator--() { --ref(); return *this; }
-    T operator--(int) { T n = obj_.value_; --ref(); return n; }
-
-    tx_obj& operator++() { ++ref(); return *this; }
-    T operator++(int) { T n = obj_.value_; ++ref(); return n; }
-
-    tx_obj& operator+=(T const &rhs) {
-        ref() += rhs;
-        return *this;
-    }
-
-    T operator+(T const &rhs) const {
-        return ref()+rhs;
-    }
-
-    void swap(tx_obj & other) { // never throws
-        std::swap(obj_, other.obj_);
-    }
-
-};
-
-// two transactional pointers are equal if they point to the same cache on the current transaction.
-template <typename T, typename U>
-bool operator==(const tx_obj<T>& lhs, const tx_obj<U>& rhs) {
-    return lhs.ref()==rhs.ref();
-}
-
-template <typename T, typename U>
-bool operator==(const T& lhs, const tx_obj<U>& rhs) {
-    return lhs==rhs.ref();
-}
-
-template <typename T, typename U>
-bool operator==(const tx_obj<T>& lhs, const U& rhs) {
-    return lhs.ref()==rhs;
-}
-
-template <typename T, typename U>
-bool operator!=(const tx_obj<T>& lhs, const tx_obj<U>& rhs) {
-    return lhs.ref()!=rhs.ref();
-}
-
-template<class T> inline void swap(tx_obj<T> & a, tx_obj<T> & b) {
-    a.swap(b);
-}
-
-//-----------------------------------------------------------------------------
-// a tx_ptr<T> is an smart pointer to a transactional_object<T> (which contains an instance of T).
-// Reference fields in linked structures should always be tx_ptrs.
-// The result of derreferencing it will be the pointer to the T instance
-// When this pointer is derreference on a transaction the transactional_object<T> is set a written and
-// the transaction specific storage will be used
-// Otherwise the shared storage is used.
-// Used to initialize a rd_ptr<T>, wr_ptr<T>, or upgrd_ptr<T>.
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class tx_ptr {
-public:
-    typedef tx_ptr<T> this_type;
-    transactional_object<T> * ptr_;
-
-    tx_ptr() : ptr_(0) {}
-    template<class Y>
-    explicit tx_ptr(Y * ptr) : ptr_(new transactional_object<Y>(ptr)) {}
-
-    template<class Y>
-    explicit tx_ptr(transactional_object<Y>* ptr) : ptr_(ptr) {}
-
-    tx_ptr(tx_obj<T>& r) : ptr_(r->obj_) {}
-
-    template<class Y>
-    tx_ptr(tx_ptr<Y> const& r) : ptr_(r.ptr_) {}// never throws
-
-    template<class Y>
-    tx_ptr(rd_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
-
-    template<class Y>
-    tx_ptr(wr_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
-
-    template<class Y>
-    tx_ptr(upgrd_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
-
-    template<class Y>
-    tx_ptr & operator=(tx_ptr<Y> const & r) { // never throws
-        //this_type(r).swap(*this);
-        ptr_=r.ptr_;
-        return *this;
-    }
-    template<class Y>
-    tx_ptr& operator=(transactional_object<Y>* ptr)  { // never throws
-        ptr_=ptr;
-        return *this;
-    }
-
-    //bool operator==(const tx_ptr<T>& rhs) const {
-    //    return ptr_==rhs.ptr_ || this->get()==rhs.ptr_ || ptr_==rhs.get();
-    //}
-
-    T* operator->() const {
-        return this->get();
-    }
-    T& operator*() const {
-        return *this->get();
-    }
-    T* get() const {
-        if (0==ptr_) return 0;
-        transaction* tx=transaction::current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                    tx->lock_and_abort();
-                    throw aborted_transaction_exception("aborting transaction");
-            }
-            return &(tx->write_ptr(ptr_)->value);
-        }
-        return &ptr_->value;
-    }
-
-    typedef transactional_object<T>* this_type::*unspecified_bool_type;
-
-    operator unspecified_bool_type() const {
-        return ptr_ == 0? 0: &this_type::ptr_;
-    }
-    void swap(tx_ptr & other) { // never throws
-        std::swap(ptr_, other.ptr_);
-    }
-};
-
-// two transactional pointers are equal if they point to the same cache on the current transaction.
-template <typename T, typename U>
-bool operator==(const tx_ptr<T>& lhs, const tx_ptr<U>& rhs) {
-        return lhs.ptr_==rhs.ptr_ || lhs.get()==rhs.ptr_ || lhs.ptr_==rhs.get();
-}
-
-template <typename T, typename U>
-bool operator!=(const tx_ptr<T>& lhs, const tx_ptr<U>& rhs) {
-    return lhs.ptr_!=rhs.ptr_ && lhs.get()!=rhs.ptr_ && lhs.ptr_!=rhs.get();
-}
-
-template<class T> inline void swap(tx_ptr<T> & a, tx_ptr<T> & b) {
-    a.swap(b);
-}
-
-template <typename T>
-tx_ptr<T> make_tx_ptr() {
-    return tx_ptr<T>(new transactional_object<T>());
-}
-
-template <typename T, typename A1>
-tx_ptr<T> make_tx_ptr(A1 const &a1) {
-    return tx_ptr<T>(new transactional_object<T>(a1));
-}
-
-
-template <typename T>
-void delete_ptr(tx_ptr<T> ptr) {
-    if (ptr.ptr_==0) return;
-    transaction* tx=transaction::current_transaction();
-    if (tx==0) delete ptr.ptr_;
-    tx->delete_tx_ptr(ptr.ptr_);
-}
-
-
-template <typename T>
-void delete_ptr(transaction& tx, tx_ptr<T> ptr) {
-    if (ptr.ptr_==0) return;
-    tx.delete_tx_ptr(ptr.ptr_);
-}
-
-template <typename T, typename U>
-static tx_ptr<T> tx_static_cast(tx_ptr<U> ptr) {
-    return tx_ptr<T>(tx_static_cast<T>(ptr->ptr_));
-}
-
-template <typename T, typename U>
-static tx_ptr<T>* tx_dynamic_cast(tx_ptr<U> ptr) {
-    return tx_ptr<T>(tx_dynamic_cast<T>(ptr->ptr_));
-}
-
-
-//-----------------------------------------------------------------------------
-// A rd_ptr<T> ("read pointer") points to an object that the current
-// transaction has opened for read only access.
-// You can only call a const method through a read pointer.
-// A rd_ptr<T> is constructed from an tx_ptr<T> through an explicit constructor.
-// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
-// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
-// It is not safe to derreference a rd_ptr<T> after having assigned the same
-// tx_ptr<T> to a wr_ptr<T>. If this is the case the readen value do not match
-// the writen one. If it is possible to write on the same transaction use
-// upgrd_ptr instead which is safe.
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class rd_ptr {
-    typedef rd_ptr<T> this_type;
-public:
-    mutable transactional_object<T>* ptr_;
-    mutable transaction* tx_;
-
-    inline rd_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(&t),
-        ptr_(&t.insert_and_return_read_memory(*tx_obj.ptr_))
-    {}
-
-    inline rd_ptr(transaction &t, tx_obj<T> const& tx_obj) : tx_(&t),
-        ptr_(&t.insert_and_return_read_memory(tx_obj.obj_))
-    {}
-
-    template<class Y>
-    rd_ptr & operator=(tx_ptr<Y> r) { // never throws
-        //this_type(r).swap(*this);
-        ptr_=r.ptr_;
-        return *this;
-    }
-
-    template<class Y>
-    rd_ptr& operator=(tx_obj<Y> const & r) { // never throws
-        //this_type(r).swap(*this);
-        ptr_=r.get();
-        return *this;
-    }
-
-    const T* get() const {
-        if (tx_->forced_to_abort()) {
-            tx_->lock_and_abort();
-            throw aborted_transaction_exception("aborting transaction");
-        }
-        return &ptr_->value;
-    }
-
-    inline const T & operator*() const { return *get(); }
-    inline const T* operator->() const { return get(); }
-
-
-    typedef transactional_object<T>* this_type::*unspecified_bool_type;
-
-    operator unspecified_bool_type() const
-    {
-        return ptr_ == 0? 0: &this_type::ptr_;
-    }
-
-};
-
-template <typename T>
-rd_ptr<T> make_rd_ptr(transaction& tx, tx_ptr<T> ptr) {
-    return rd_ptr<T>(tx, ptr);
-}
-template <typename T>
-rd_ptr<T> make_rd_ptr(transaction& tx, tx_obj<T> const & ref) {
-    return rd_ptr<T>(tx, ref);
-}
-
-template <typename T>
-rd_ptr<T> make_rd_ptr(tx_ptr<T> ptr) {
-    transaction* tx = transaction::current_transaction();
-    assert(tx==0);
-    return rd_ptr<T>(*tx, ptr);
-}
-
-template <typename T>
-rd_ptr<T> make_rd_ptr(tx_obj<T> const & ref) {
-    transaction* tx = transaction::current_transaction();
-    assert(tx==0);
-    return rd_ptr<T>(*tx, ref);
-}
-
-template <typename T>
-void delete_ptr(rd_ptr<T> ptr) {
-    if (ptr.ptr_==0) return;
-    transaction* tx=transaction::current_transaction();
-    if (tx==0) delete ptr.ptr_;
-    tx->delete_tx_ptr(ptr.ptr_);
-}
-
-template <typename T>
-void delete_ptr(transaction& tx, rd_ptr<T> ptr) {
-    if (ptr.ptr_==0) return;
-    tx.delete_tx_ptr(ptr.ptr_);
-}
-
-//-----------------------------------------------------------------------------
-// A upgrd_ptr<T> ("upgradable pointer") points to an object that the current
-// transaction has opened for read only access.
-// You can only call a const method through a read pointer.
-// A upgrd_ptr<T> is constructed from an tx_ptr<T> through a constructor
-// having also the transaction as parameter.
-// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
-// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
-// It is safe to derreference a rd_ptr<T> after having assigned the same
-// tx_ptr<T> to a wr_ptr<T>.
-// A upgrd_ptr<T> can be upgraded to a wr_ptr<T> through a constructor.
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class upgrd_ptr {
-    typedef tx_ptr<T> this_type;
-public:
-    mutable transaction* tx_;
-    mutable transactional_object<T>* ptr_;
-    mutable bool written_;
-
-    //inline upgrd_ptr() : tx_(0) {}
-    inline upgrd_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(&t),
-        ptr_(const_cast<transactional_object<T>*>(t.read_ptr(tx_obj.ptr_))), written_(false)    {}
-
-    template<class Y>
-    upgrd_ptr & operator=(tx_ptr<Y> const&  r) { // never throws
-        //this_type(r).swap(*this);
-        transaction* tx=transaction::current_transaction();
-        if (tx==0) throw "error";
-        tx_=tx;
-        ptr_=r.ptr_;
-        written_=false;
-        return *this;
-    }
-
-    const T* get() const {
-        if (tx_->forced_to_abort()) {
-            tx_->lock_and_abort();
-            throw aborted_transaction_exception("aborting transaction");
-        }
-
-        // we don't hold the written object and
-        // we have alrerady written an object on this transaction maybe is this one
-        if (!written_ && tx_->written()) {
-            transactional_object<T>* temp = tx_->get_written(*ptr_);
-
-            // if we found something, store this as the tx_ptr_
-            if (0 != temp) {
-                ptr_ = temp;
-                written_ = true;
-            }
-        }
-
-        return &ptr_->value;
-    }
-
-    inline T const & operator*() const { return *get(); }
-    inline T const * operator->() const { return get(); }
-
-    //operator const T*() const { return get(); }
-
-    typedef transactional_object<T>* this_type::*unspecified_bool_type;
-
-    operator unspecified_bool_type() const
-    {
-        return ptr_ == 0? 0: &this_type::ptr_;
-    }
-    void write_ptr(transactional_object<T>* ptr) {
-        ptr_ = ptr;
-        written_ = true;
-    }
-
-    T* write_ptr() {
-        if (tx_->forced_to_abort()) {
-            tx_->lock_and_abort();
-            throw aborted_transaction_exception("aborting transaction");
-        }
-
-        // we are already holding the written object
-        if (written_) return ptr_;
-
-        transactional_object<T>* temp = tx_->get_written(ptr_);
-
-        // if we found something, store this as the tx_ptr_
-        if (0 != temp) {
-            ptr_ = temp;
-            written_ = true;
-        } else {
-            ptr_ = tx_->write_ptr(ptr_);
-            written_ = true;
-        }
-
-        return ptr_;
-    }
-
-};
-
-template <typename T>
-void delete_ptr(upgrd_ptr<T> const& ptr) {
-    if (ptr.ptr_==0) return;
-    if (ptr.tx_==0) delete ptr.ptr_;
-    ptr.tx_->delete_tx_ptr(ptr.ptr_);
-}
-
-template <typename T>
-void delete_ptr(transaction& tx, upgrd_ptr<T> const& ptr) {
-    if (ptr.ptr_==0) return;
-    tx.delete_tx_ptr(ptr.ptr_);
-}
-
-//-----------------------------------------------------------------------------
-// A wr_ptr<T> ("write pointer") points to a shared object that the current transaction has opened for writing.
-// A wr_ptr<T> is initialized explicitly from an tx_ptr<T>.
-// A wr_ptr<T> can also be explicitly constructed from a upgrd_ptr<T> as an upgrade-to-writable operation.
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class wr_ptr {
-    typedef tx_ptr<T> this_type;
-public:
-    mutable transaction& tx_;
-    mutable transactional_object<T>* ptr_;
-
-    inline wr_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(t),
-        ptr_(t.write_ptr(tx_obj.ptr_))
-    {}
-
-    inline wr_ptr(transaction &t, upgrd_ptr<T> tx_obj) : tx_(t),
-        ptr_(t.write_ptr(tx_obj.ptr_))
-    {
-        tx_obj.write_ptr(ptr_);
-    }
-
-    T* get() {
-        if (tx_.forced_to_abort()) {
-            tx_.lock_and_abort();
-            throw aborted_transaction_exception("aborting transaction");
-        }
-        return &ptr_->value;
-    }
-
-    inline T& operator*() { return *get(); }
-    inline T* operator->() { return get(); }
-
-    typedef transactional_object<T>* this_type::*unspecified_bool_type;
-
-    operator unspecified_bool_type() const
-    {
-        return ptr_ == 0? 0: &this_type::ptr_;
-    }
-};
-
-template <typename T>
-wr_ptr<T> make_wr_ptr(transaction& tx, tx_ptr<T>& ptr) {
-    return wr_ptr<T>(tx, ptr);
-}
-
-
-template <typename T>
-wr_ptr<T> make_wr_ptr(tx_ptr<T>& ptr) {
-    transaction* tx = transaction::current_transaction();
-    return wr_ptr<T>(*tx, ptr);
-}
-
-template <typename T>
-void delete_ptr(wr_ptr<T> ptr) {
-    if (ptr.ptr_==0) return;
-    ptr.tx_.delete_tx_ptr(ptr.ptr_);
-}
-
-template <typename T>
-void delete_ptr(transaction& tx, wr_ptr<T> const& ptr) {
-    if (ptr.ptr_==0) return;
-    tx.delete_tx_ptr(ptr.ptr_);
-}
-
-//=========================
-
-template <typename T>
 class read_ptr
 {
 public:
@@ -674,79 +130,6 @@
    mutable T &tx_obj_;
 };
 
-/////////
-//-----------------------------------------------------------------------------
-// A rd_ptr<T> ("read pointer") points to an object that the current
-// transaction has opened for read only access.
-// You can only call a const method through a read pointer.
-// A rd_ptr<T> is constructed from an tx_ptr<T> through an explicit constructor.
-// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
-// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
-// It is not safe to derreference a rd_ptr<T> after having assigned the same
-// tx_ptr<T> to a wr_ptr<T>. If this is the case the readen value do not match
-// the writen one. If it is possible to write on the same transaction use
-// upgrd_ptr instead which is safe.
-//-----------------------------------------------------------------------------
-
-class non_transactional_vars_cache {
-    typedef std::map<void*, base_transaction_object*> map_type;
-    static std::map<void*, base_transaction_object*> map_;
-public:
-    template <typename T>
-    static transactional_reference_cache<T>* get(T* ptr) {
-        map_type::iterator it = map_.find(ptr);
-        transactional_reference_cache<T>* res=0;
-        if (it == map_.end()) {
-            res= new transactional_reference_cache<T>(ptr);
-            map_.insert(std::make_pair(ptr, res));
-        } else {
-            res=static_cast<transactional_reference_cache<T>*>(it->second);
-        }
-        return res;
-    }
-};
-
-template <typename T>
-class non_tx_rd_ptr {
-    typedef non_tx_rd_ptr<T> this_type;
-public:
-    mutable transactional_reference_cache<T>* ptr_;
-    mutable transaction* tx_;
-
-    inline non_tx_rd_ptr(transaction &t, T* ptr) : tx_(&t),
-        ptr_(&t.insert_and_return_read_memory(non_transactional_vars_cache::get(ptr)))
-    {}
-
-    inline non_tx_rd_ptr(transaction &t, T& obj) : tx_(&t),
-        ptr_(&t.insert_and_return_read_memory(non_transactional_vars_cache::get(&obj)))
-    {}
-
-
-
-    const T* get() const {
-        if (tx_->forced_to_abort()) {
-            tx_->lock_and_abort();
-            throw aborted_transaction_exception("aborting transaction");
-        }
-        return ptr_->get();
-    }
-
-    inline const T & operator*() const { return *get(); }
-    inline const T* operator->() const { return get(); }
-
-
-    typedef transactional_reference_cache<T>* this_type::*unspecified_bool_type;
-
-    operator unspecified_bool_type() const
-    {
-        return ptr_ == 0? 0: &this_type::ptr_;
-    }
-
-};
-
-/////////
-
-
 }}
 #endif
 
Added: sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -0,0 +1,396 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_NON_TX_SMART_PTR__HPP
+#define BOOST_STM_NON_TX_SMART_PTR__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <assert.h>
+#include <map>
+#include <boost/stm/transaction.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+namespace non_tx {
+
+template <typename T>
+class rd_ptr;
+template <typename T>
+class wr_ptr;
+template <typename T>
+class upgrd_ptr;
+    
+//-----------------------------------------------------------------------------
+// This class defines the transactional cache of a non transactional variable.
+// There is a map from the address of the variable of type T to an instance of this class
+//
+//-----------------------------------------------------------------------------
+
+namespace detail {
+
+template <typename T>
+class cache : public base_transaction_object {
+public:
+    T* const value_;
+    mutable T* ptr_;
+
+    inline cache(T& ref)
+        : base_transaction_object()
+        , value_(&ref), ptr_(0) {}
+
+    inline cache(T* ptr)
+        : base_transaction_object()
+        , value_(ptr), ptr_(0) {}
+
+    inline ~cache() {
+        delete ptr_;
+    }
+    
+    inline T* get() const {
+        if(ptr_!=0) return ptr_;
+        else return value_;
+    }
+
+    virtual base_transaction_object* clone() const {
+        cache* tmp = cache_clone(*this);
+        if (tmp->value_!=0) {
+            tmp->ptr_ = new T(*value_);
+        }
+        return tmp;
+    }
+
+    virtual void copy_state(base_transaction_object const * const rhs) {
+        if (value_==0) return;
+        *value_= *(static_cast<cache<T> const * const>(rhs)->ptr_);
+        delete ptr_;
+        ptr_=0;
+    }
+
+#ifdef BOOST_STM_USE_MEMCOPY
+    virtual void cache_deallocate() {
+        delete ptr_;
+        ptr_=0;
+        boost::stm::cache_deallocate(this);
+    }
+#endif
+
+#if USE_STM_MEMORY_MANAGER
+   void* operator new(size_t size) throw ()
+   {
+      return retrieve_mem(size);
+   }
+
+   void operator delete(void* mem)
+   {
+      return_mem(mem, sizeof(transactional_object<T>));
+   }
+#endif
+
+private:
+    //cache(cache<T> const & r);
+
+        //: base_transaction_object(r)
+        //, value_(r.value_), ptr_(r.ptr_) {}
+
+
+    //cache & operator=(cache const & r);
+    //{
+    //    value_ = r.value_;
+    //    ptr_ = r.ptr_;
+    //    return *this;
+    //}
+
+};
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class cache_map {
+    typedef std::map<void*, base_transaction_object*> map_type;
+    static std::map<void*, base_transaction_object*> map_;
+public:
+    template <typename T>
+    static cache<T>* get(T* ptr) {
+        map_type::iterator it = map_.find(ptr);
+        cache<T>* res=0;
+        if (it == map_.end()) {
+            res= new cache<T>(ptr);
+            map_.insert(std::make_pair(ptr, res));
+        } else {
+            res=static_cast<cache<T>*>(it->second);
+        }
+        return res;
+    }
+    template <typename T>
+    static cache<T>* get(T const* ptr) {
+        map_type::iterator it = map_.find(const_cast<T*>(ptr));
+        cache<T>* res=0;
+        if (it == map_.end()) {
+            res= new cache<T>(const_cast<T*>(ptr));
+            map_.insert(std::make_pair(const_cast<T*>(ptr), res));
+        } else {
+            res=static_cast<cache<T>*>(it->second);
+        }
+        return res;
+    }
+};
+
+}
+//-----------------------------------------------------------------------------
+// A rd_ptr<T> ("read pointer") points to an object that the current
+// transaction has opened for read only access.
+// You can only call a const method through a read pointer.
+// A rd_ptr<T> is constructed from an tx_ptr<T> through an explicit constructor.
+// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
+// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
+// It is not safe to derreference a rd_ptr<T> after having assigned the same
+// tx_ptr<T> to a wr_ptr<T>. If this is the case the readen value do not match
+// the writen one. If it is possible to write on the same transaction use
+// upgrd_ptr instead which is safe.
+//-----------------------------------------------------------------------------
+
+
+template <typename T>
+class rd_ptr {
+    typedef rd_ptr<T> this_type;
+public:
+    mutable transaction& tx_;
+    mutable detail::cache<T>* ptr_;
+
+    inline rd_ptr(transaction &t, T const * ptr) : tx_(t),
+        ptr_(&t.insert_and_return_read_memory(*detail::cache_map::get(ptr)))
+    {}
+
+    inline rd_ptr(transaction &t, T const & obj) : tx_(t),
+        ptr_(&t.insert_and_return_read_memory(*detail::cache_map::get(&obj)))
+    {}
+
+    template<class Y>
+    inline rd_ptr & operator=(Y const* ptr) { // never throws
+        ptr_=tx_.insert_and_return_read_memory(*detail::cache_map::get(ptr));
+        return *this;
+    }
+        
+    template<class Y>
+    inline rd_ptr & operator=(Y const& ref) { // never throws
+        ptr_=tx_.insert_and_return_read_memory(*detail::cache_map::get(&ref));
+        return *this;
+    }
+
+    const T* get() const {
+        if (tx_.forced_to_abort()) {
+            tx_.lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+        return ptr_->get();
+    }
+
+    inline const T & operator*() const { return *get(); }
+    inline const T* operator->() const { return get(); }
+
+
+    typedef detail::cache<T>* this_type::*unspecified_bool_type;
+
+    inline operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+
+};
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(transaction& tx, T* ptr) {
+    return rd_ptr<T>(tx, ptr);
+}
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(transaction& tx, T& ref) {
+    return rd_ptr<T>(tx, ref);
+}
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(T* ptr) {
+    transaction* tx = transaction::current_transaction();
+    assert(tx==0);
+    return rd_ptr<T>(*tx, ptr);
+}
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(T& ref) {
+    transaction* tx = transaction::current_transaction();
+    assert(tx==0);
+    return rd_ptr<T>(*tx, ref);
+}
+
+template <typename T>
+inline void delete_ptr(rd_ptr<T> ptr) {
+    if (ptr.ptr_==0) return;
+    ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+
+
+//-----------------------------------------------------------------------------
+// A upgrd_ptr<T> ("upgradable pointer") points to an object that the current
+// transaction has opened for read only access.
+// You can only call a const method through a read pointer.
+// A upgrd_ptr<T> is constructed from an tx_ptr<T> through a constructor
+// having also the transaction as parameter.
+// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
+// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
+// It is safe to derreference a rd_ptr<T> after having assigned the same
+// tx_ptr<T> to a wr_ptr<T>.
+// A upgrd_ptr<T> can be upgraded to a wr_ptr<T> through a constructor.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class upgrd_ptr {
+    typedef upgrd_ptr<T> this_type;
+public:
+    mutable transaction* tx_;
+    mutable detail::cache<T>* ptr_;
+    mutable bool written_;
+
+    inline upgrd_ptr(transaction &t, T* ptr) : tx_(&t),
+        ptr_(const_cast<detail::cache<T>*>(t.read_ptr(detail::cache_map::get(ptr)))), written_(false)    {}
+
+    inline upgrd_ptr(transaction &t, T& ref) : tx_(&t),
+        ptr_(const_cast<detail::cache<T>*>(t.read_ptr(detail::cache_map::get(&ref)))), written_(false)    {}
+
+    template<class Y>
+    inline upgrd_ptr & operator=(Y* ptr) { 
+        ptr_=const_cast<detail::cache<T>*>(tx_->read_ptr(detail::cache_map::get(ptr)));
+        return *this;
+    }
+
+    template<class Y>
+    inline upgrd_ptr & operator=(Y& ref) { 
+        ptr_=const_cast<detail::cache<T>*>(tx_->read_ptr(detail::cache_map::get(&ref)));
+        return *this;
+    }
+
+    const T* get() const {
+        if (tx_->forced_to_abort()) {
+            tx_->lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+
+        // we don't hold the written object and
+        // we have alrerady written an object on this transaction maybe is this one
+        if (!written_ && tx_->written()) {
+            detail::cache<T>* temp = tx_->get_written(*ptr_);
+
+            // if we found something, store this as the tx_ptr_
+            if (0 != temp) {
+                ptr_ = temp;
+                written_ = true;
+            }
+        }
+
+        return &ptr_->value;
+    }
+
+    inline T const & operator*() const { return *get(); }
+    inline T const * operator->() const { return get(); }
+
+    //operator const T*() const { return get(); }
+
+    typedef detail::cache<T>* this_type::*unspecified_bool_type;
+
+    inline operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+    inline void write_ptr(detail::cache<T>* ptr) {
+        ptr_ = ptr;
+        written_ = true;
+    }
+
+    T* write_ptr() {
+        if (tx_->forced_to_abort()) {
+            tx_->lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+
+        // we are already holding the written object
+        if (written_) return ptr_;
+
+        detail::cache<T>* temp = tx_->get_written(ptr_);
+
+        // if we found something, store this as the tx_ptr_
+        if (0 != temp) {
+            ptr_ = temp;
+            written_ = true;
+        } else {
+            ptr_ = tx_->write_ptr(ptr_);
+            written_ = true;
+        }
+
+        return ptr_;
+    }
+
+};
+
+template <typename T>
+inline void delete_ptr(upgrd_ptr<T> const& ptr) {
+    if (ptr.ptr_==0) return;
+    if (ptr.tx_==0) delete ptr.ptr_;
+    ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+inline void delete_ptr(transaction& tx, upgrd_ptr<T> const& ptr) {
+    if (ptr.ptr_==0) return;
+    tx.delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+class wr_ptr {
+    typedef wr_ptr<T> this_type;
+public:
+    mutable transaction& tx_;
+    mutable detail::cache<T>* ptr_;
+
+    inline wr_ptr(transaction &t, T* ptr) : tx_(t),
+        ptr_(t.write_ptr(detail::cache_map::get(ptr)))
+    {}
+
+    inline wr_ptr(transaction &t, T& obj) : tx_(t),
+        ptr_(t.write_ptr(detail::cache_map::get(&obj)))
+    {}
+
+
+    T* get() {
+        if (tx_.forced_to_abort()) {
+            tx_.lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+        return ptr_->get();
+    }
+
+    inline T& operator*() { return *get(); }
+    inline T* operator->() { return get(); }
+
+    typedef detail::cache<T>* this_type::*unspecified_bool_type;
+
+    inline operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+};
+
+
+}
+}}
+#endif
+
+
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	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -2052,12 +2052,6 @@
         }
     }
 };
-template <class T>
-struct cache_deallocate<transactional_object<std::vector<T> > > {
-    static void apply(transactional_object<std::vector<T> >* ptr) {
-        delete ptr;
-    }
-};
 
 }
 
@@ -2068,11 +2062,6 @@
 #else //!BOOST_STM_NO_PARTIAL_SPECIALIZATION
 
 template <class T>
-inline void cache_deallocate(transactional_object<std::vector<T> >* ptr) {
-    delete ptr;
-}
-
-template <class T>
 inline void cache_deallocate(T* ptr) {
     if (ptr) {
     #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER)
@@ -2086,119 +2075,92 @@
     }
 }
 #endif //BOOST_STM_NO_PARTIAL_SPECIALIZATION
+#endif // BOOST_STM_USE_MEMCOPY
 
-// this function must be specialized for objects that are non transactional,
-// by calling to new of the copy constructor
+inline void cache_release(base_transaction_object* ptr) {
+#ifdef BOOST_STM_USE_MEMCOPY
+    ptr->cache_deallocate();
+#else
+    delete ptr;
+#endif
+}
 
+#ifdef BOOST_STM_USE_MEMCOPY
 #ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
 namespace partial_specialization_workaround {
 template <class T>
-struct cache_new_copy_constructor;
+struct cache_clone;
 
 template <class T>
-struct cache_new_copy_constructor {
+struct cache_clone {
     static inline T* apply(const T& val) {
         T* p = cache_allocate<T>();
         if (p==0) {
             throw std::bad_alloc();
         }
-        boost::stm::cache_restore(&val, p);
+        boost::stm::cache_copy(&val, p);
         return p;
     }
 };
 
-template <class T, class A>
-struct cache_new_copy_constructor<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
 
 template <class T>
-inline T* cache_new_copy_constructor(const T& val) {
-    return partial_specialization_workaround::cache_new_copy_constructor<T>::apply(val);
+inline T* cache_clone(const T& val) {
+    return partial_specialization_workaround::cache_clone<T>::apply(val);
 }
 #else //BOOST_STM_NO_PARTIAL_SPECIALIZATION
 
 template <class T>
-inline transactional_object<std::vector<T> >* cache_new_copy_constructor(const transactional_object<std::vector<T> >& val) {
-    return new transactional_object<std::vector<T> >(val);
-}
-
-template <class T>
-inline T* cache_new_copy_constructor(const T& val) {
+inline T* cache_clone(const T& val) {
     T* p = cache_allocate<T>();
     if (p==0) {
         //std::cout << __LINE__ << " malloc ERROR" << std::endl;
         throw std::bad_alloc();
     }
-    cache_restore(&val, p);
+    cache_copy(&val, p);
     return p;
 }
 #endif // BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#endif // BOOST_STM_USE_MEMCOPY
-
-inline void cache_release(base_transaction_object* ptr) {
-#ifdef BOOST_STM_USE_MEMCOPY
-    ptr->cache_deallocate();
 #else
-    delete ptr;
-#endif
-}
-
 template <class T>
-inline T* cache_new_copy(const T& val) {
-#ifdef BOOST_STM_USE_MEMCOPY
-    return cache_new_copy_constructor(val);
-#else
+inline T* cache_clone(const T& val) {
     return new T(val);
-#endif
 }
+#endif
+
 
-template <class T> void cache_restore(const T* const ori, T* target);
+template <class T> void cache_copy(const T* const ori, T* target);
 // When BOOST_STM_USE_MEMCOPY is defined
 // this function must be specialized for objects that are non transactional by deleting the object, e.g.
 
 #ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
 #ifdef BOOST_STM_USE_MEMCOPY
 namespace partial_specialization_workaround {
-template <class T> struct cache_restore;
+template <class T> struct cache_copy;
 
 
 template <class T>
-struct cache_restore {
+struct cache_copy {
     static inline void apply(const T* const ori, T* target) {
         memcpy(target, ori, sizeof(T));
     }
 };
 
-template <class T>
-struct cache_restore<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
 #endif
 
-template <class T> void cache_restore(const T* const ori, T* target) {
+template <class T> void cache_copy(const T* const ori, T* target) {
 #ifdef BOOST_STM_USE_MEMCOPY
-    partial_specialization_workaround::cache_restore<T>::apply(ori, target);
+    partial_specialization_workaround::cache_copy<T>::apply(ori, target);
 #else
     *target=*ori;
 #endif
 }
 
 #else
-#ifdef BOOST_STM_USE_MEMCOPY
-template <class T> void cache_restore(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
-    *target=*ori;
-}
-#endif
 
-template <class T> void cache_restore(const T* const ori, T* target) {
+template <class T> void cache_copy(const T* const ori, T* target) {
 #ifdef BOOST_STM_USE_MEMCOPY
     memcpy(target, ori, sizeof(T));
 #else
Added: sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -0,0 +1,204 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_TRANSACTIONAL_OBJECT__HPP
+#define BOOST_STM_TRANSACTIONAL_OBJECT__HPP
+
+#include <boost/stm/base_transaction.hpp>
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// transactional object wrapper
+// 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
+//      move_state and
+//      cache_deallocate: relaying on the cache_copy<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
+// we can static/dynamic cast them robustly.
+// Evidently the std::static_cast/std::dynamic_cast do not works. We need to define the specific cast
+//
+// transactional_object<D>* d=...;
+// transactional_object<B>* b=tx_static_cast<B>(d);
+//
+// transactional_object<B>* b=...;
+// transactional_object<D>* d=tx_dynamic_cast<B>(b);
+//
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class transactional_object : public base_transaction_object {
+public:
+    T value;
+
+    transactional_object() {}
+    transactional_object(const T*ptr)
+        : base_transaction_object()
+        , value(*ptr) {}
+
+    transactional_object(transactional_object<T> const & r)
+        : base_transaction_object(r)
+        , value(r.value) {}
+
+    template <typename T1>
+    transactional_object(T1 const &p1)
+        : base_transaction_object()
+        , value(p1) {}
+
+    template <typename T1, typename T2>
+    transactional_object(T1 const &p1, T2 const &p2)
+        : base_transaction_object()
+        , value(p1,p2) {}
+
+    transactional_object & operator=(transactional_object const & r)  // =default never throws
+    {
+        value = r.value;
+        return *this;
+    }
+
+    virtual base_transaction_object* clone() const {
+        return cache_clone(*this);
+    }
+
+    virtual void copy_state(base_transaction_object const * const rhs) {
+        cache_copy(static_cast<transactional_object<T> const * const>(rhs),
+                      //static_cast<transactional_object<T> *>(this));
+                      this);
+    }
+
+#ifdef BOOST_STM_USE_MEMCOPY
+    virtual void cache_deallocate() {
+        boost::stm::cache_deallocate(this);
+    }
+#endif
+
+#if USE_STM_MEMORY_MANAGER
+   void* operator new(size_t size) throw ()
+   {
+      return retrieve_mem(size);
+   }
+
+   void operator delete(void* mem)
+   {
+      return_mem(mem, sizeof(transactional_object<T>));
+   }
+#endif
+
+};
+
+//-----------------------------------------------------------------------------
+// gets the transactional_object<T> pointer wrapping the T pointer
+//-----------------------------------------------------------------------------
+template <typename T>
+static transactional_object<T>* tx_up_cast(T* ptr) {
+    return reinterpret_cast<transactional_object<T>*>(reinterpret_cast<char*>(ptr)-offsetof(transactional_object<T>, value));
+}
+
+//-----------------------------------------------------------------------------
+// static_cast two transactional_object's
+//-----------------------------------------------------------------------------
+template <typename T, typename U>
+static transactional_object<T>* tx_static_cast(transactional_object<U>* ptr) {
+    return tx_up_cast(static_cast<T*>(&ptr->value));
+}
+
+//-----------------------------------------------------------------------------
+// dynamic_cast two transactional_object's
+//-----------------------------------------------------------------------------
+template <typename T, typename U>
+static transactional_object<T>* tx_dynamic_cast(transactional_object<U>* ptr) {
+    T* p = dynamic_cast<T*>(&ptr->value);
+    if (p==0) return 0;
+    return tx_up_cast(p);
+}
+
+
+
+#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 cache_deallocate(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
+
+
Added: sandbox/stm/branches/vbe/boost/stm/tx_smart_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx_smart_ptr.hpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -0,0 +1,566 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_TX_SMART_PTR__HPP
+#define BOOST_STM_TX_SMART_PTR__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <assert.h>
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/transactional_object.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+template <typename T>
+class rd_ptr;
+template <typename T>
+class wr_ptr;
+template <typename T>
+class upgrd_ptr;
+
+//-----------------------------------------------------------------------------
+// class tx_obj wraps a transactional_object providing builting operators
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class tx_obj {
+public:
+    transactional_object<T> obj_;
+
+    //-----------------------------------------------------------------------------
+    // default constructor valid ony if T has a default constructor
+
+    tx_obj() : obj_() {}
+
+    //
+    template<class Y>
+    tx_obj(tx_obj<Y> const& r) : obj_(r.ref()) {} // throws only if obj_ contructor throws
+
+    template <typename T1>
+    tx_obj(T1 p1) : obj_(p1) {}
+
+    #if 0
+    bool operator==(const tx_obj<T>& rhs) const {
+        return this->ref()==rhs.ref();
+    }
+
+    bool operator==(const T& rhs) const {
+        return this->ref()==rhs;
+    }
+    #endif
+
+    //operator T() const { return *this->get(); }
+
+    T* operator->() {
+        return this->get();
+    }
+    const T* operator->() const {
+        return this->get();
+    }
+    T& operator*() {
+        return this->ref();
+    }
+    const T& operator*() const {
+        return this->ref();
+    }
+    T* get() {
+        return &this->ref();
+    }
+    const T* get() const {
+        return &this->ref();
+    }
+    T& ref() {
+        transaction* tx=transaction::current_transaction();
+        if (tx!=0) {
+            if (tx->forced_to_abort()) {
+                tx->lock_and_abort();
+                throw aborted_transaction_exception("aborting transaction");
+            }
+            return tx->write(obj_).value;
+        }
+        return obj_.value;
+    }
+
+    const T& ref() const {
+        transaction* tx=transaction::current_transaction();
+        if (tx!=0) {
+            if (tx->forced_to_abort()) {
+                tx->lock_and_abort();
+                throw aborted_transaction_exception("aborting transaction");
+            }
+            return tx->read(obj_).value;
+        }
+        return obj_.value;
+    }
+
+
+    tx_obj& operator--() { --ref(); return *this; }
+    T operator--(int) { T n = obj_.value_; --ref(); return n; }
+
+    tx_obj& operator++() { ++ref(); return *this; }
+    T operator++(int) { T n = obj_.value_; ++ref(); return n; }
+
+    tx_obj& operator+=(T const &rhs) {
+        ref() += rhs;
+        return *this;
+    }
+
+    T operator+(T const &rhs) const {
+        return ref()+rhs;
+    }
+
+    void swap(tx_obj & other) { // never throws
+        std::swap(obj_, other.obj_);
+    }
+
+};
+
+// two transactional pointers are equal if they point to the same cache on the current transaction.
+template <typename T, typename U>
+inline bool operator==(const tx_obj<T>& lhs, const tx_obj<U>& rhs) {
+    return lhs.ref()==rhs.ref();
+}
+
+template <typename T, typename U>
+inline bool operator==(const T& lhs, const tx_obj<U>& rhs) {
+    return lhs==rhs.ref();
+}
+
+template <typename T, typename U>
+inline bool operator==(const tx_obj<T>& lhs, const U& rhs) {
+    return lhs.ref()==rhs;
+}
+
+template <typename T, typename U>
+inline bool operator!=(const tx_obj<T>& lhs, const tx_obj<U>& rhs) {
+    return lhs.ref()!=rhs.ref();
+}
+
+template<class T> inline void swap(tx_obj<T> & a, tx_obj<T> & b) {
+    a.swap(b);
+}
+
+//-----------------------------------------------------------------------------
+// a tx_ptr<T> is an smart pointer to a transactional_object<T> (which contains an instance of T).
+// Reference fields in linked structures should always be tx_ptrs.
+// The result of derreferencing it will be the pointer to the T instance
+// When this pointer is derreference on a transaction the transactional_object<T> is set a written and
+// the transaction specific storage will be used
+// Otherwise the shared storage is used.
+// Used to initialize a rd_ptr<T>, wr_ptr<T>, or upgrd_ptr<T>.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class tx_ptr {
+public:
+    typedef tx_ptr<T> this_type;
+    transactional_object<T> * ptr_;
+
+    tx_ptr() : ptr_(0) {}
+    template<class Y>
+    explicit tx_ptr(Y * ptr) : ptr_(new transactional_object<Y>(ptr)) {}
+
+    template<class Y>
+    explicit tx_ptr(transactional_object<Y>* ptr) : ptr_(ptr) {}
+
+    tx_ptr(tx_obj<T>& r) : ptr_(r->obj_) {}
+
+    template<class Y>
+    tx_ptr(tx_ptr<Y> const& r) : ptr_(r.ptr_) {}// never throws
+
+    template<class Y>
+    tx_ptr(rd_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
+
+    template<class Y>
+    tx_ptr(wr_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
+
+    template<class Y>
+    tx_ptr(upgrd_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
+
+    template<class Y>
+    tx_ptr & operator=(tx_ptr<Y> const & r) { // never throws
+        //this_type(r).swap(*this);
+        ptr_=r.ptr_;
+        return *this;
+    }
+    template<class Y>
+    tx_ptr& operator=(transactional_object<Y>* ptr)  { // never throws
+        ptr_=ptr;
+        return *this;
+    }
+
+    //bool operator==(const tx_ptr<T>& rhs) const {
+    //    return ptr_==rhs.ptr_ || this->get()==rhs.ptr_ || ptr_==rhs.get();
+    //}
+
+    T* operator->() const {
+        return this->get();
+    }
+    T& operator*() const {
+        return *this->get();
+    }
+    T* get() const {
+        if (0==ptr_) return 0;
+        transaction* tx=transaction::current_transaction();
+        if (tx!=0) {
+            if (tx->forced_to_abort()) {
+                    tx->lock_and_abort();
+                    throw aborted_transaction_exception("aborting transaction");
+            }
+            return &(tx->write_ptr(ptr_)->value);
+        }
+        return &ptr_->value;
+    }
+
+    typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+    operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+    void swap(tx_ptr & other) { // never throws
+        std::swap(ptr_, other.ptr_);
+    }
+};
+
+// two transactional pointers are equal if they point to the same cache on the current transaction.
+template <typename T, typename U>
+inline bool operator==(const tx_ptr<T>& lhs, const tx_ptr<U>& rhs) {
+        return lhs.ptr_==rhs.ptr_ || lhs.get()==rhs.ptr_ || lhs.ptr_==rhs.get();
+}
+
+template <typename T, typename U>
+inline bool operator!=(const tx_ptr<T>& lhs, const tx_ptr<U>& rhs) {
+    return lhs.ptr_!=rhs.ptr_ && lhs.get()!=rhs.ptr_ && lhs.ptr_!=rhs.get();
+}
+
+template<class T> 
+inline void swap(tx_ptr<T> & a, tx_ptr<T> & b) {
+    a.swap(b);
+}
+
+template <typename T>
+inline tx_ptr<T> make_tx_ptr() {
+    return tx_ptr<T>(new transactional_object<T>());
+}
+
+template <typename T, typename A1>
+inline tx_ptr<T> make_tx_ptr(A1 const &a1) {
+    return tx_ptr<T>(new transactional_object<T>(a1));
+}
+
+
+template <typename T>
+void delete_ptr(tx_ptr<T> ptr) {
+    if (ptr.ptr_==0) return;
+    transaction* tx=transaction::current_transaction();
+    if (tx==0) delete ptr.ptr_;
+    tx->delete_tx_ptr(ptr.ptr_);
+}
+
+
+template <typename T>
+void delete_ptr(transaction& tx, tx_ptr<T> ptr) {
+    if (ptr.ptr_==0) return;
+    tx.delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T, typename U>
+inline tx_ptr<T> tx_static_cast(tx_ptr<U> ptr) {
+    return tx_ptr<T>(tx_static_cast<T>(ptr->ptr_));
+}
+
+template <typename T, typename U>
+inline tx_ptr<T>* tx_dynamic_cast(tx_ptr<U> ptr) {
+    return tx_ptr<T>(tx_dynamic_cast<T>(ptr->ptr_));
+}
+
+
+//-----------------------------------------------------------------------------
+// A rd_ptr<T> ("read pointer") points to an object that the current
+// transaction has opened for read only access.
+// You can only call a const method through a read pointer.
+// A rd_ptr<T> is constructed from an tx_ptr<T> through an explicit constructor.
+// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
+// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
+// It is not safe to derreference a rd_ptr<T> after having assigned the same
+// tx_ptr<T> to a wr_ptr<T>. If this is the case the readen value do not match
+// the writen one. If it is possible to write on the same transaction use
+// upgrd_ptr instead which is safe.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class rd_ptr {
+    typedef rd_ptr<T> this_type;
+public:
+    mutable transaction* tx_;
+    mutable transactional_object<T>* ptr_;
+
+    inline rd_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(&t),
+        ptr_(&t.insert_and_return_read_memory(*tx_obj.ptr_))
+    {}
+
+    inline rd_ptr(transaction &t, tx_obj<T> const& tx_obj) : tx_(&t),
+        ptr_(&t.insert_and_return_read_memory(tx_obj.obj_))
+    {}
+
+    template<class Y>
+    inline rd_ptr & operator=(tx_ptr<Y> r) { // never throws
+        //this_type(r).swap(*this);
+        ptr_=r.ptr_;
+        return *this;
+    }
+
+    template<class Y>
+    inline rd_ptr& operator=(tx_obj<Y> const & r) { // never throws
+        //this_type(r).swap(*this);
+        ptr_=r.get();
+        return *this;
+    }
+
+    const T* get() const {
+        if (tx_->forced_to_abort()) {
+            tx_->lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+        return &ptr_->value;
+    }
+
+    inline const T & operator*() const { return *get(); }
+    inline const T* operator->() const { return get(); }
+
+
+    typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+    inline operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+
+};
+
+template <typename T>
+rd_ptr<T> make_rd_ptr(transaction& tx, tx_ptr<T> ptr) {
+    return rd_ptr<T>(tx, ptr);
+}
+template <typename T>
+rd_ptr<T> make_rd_ptr(transaction& tx, tx_obj<T> const & ref) {
+    return rd_ptr<T>(tx, ref);
+}
+
+template <typename T>
+rd_ptr<T> make_rd_ptr(tx_ptr<T> ptr) {
+    transaction* tx = transaction::current_transaction();
+    assert(tx==0);
+    return rd_ptr<T>(*tx, ptr);
+}
+
+template <typename T>
+rd_ptr<T> make_rd_ptr(tx_obj<T> const & ref) {
+    transaction* tx = transaction::current_transaction();
+    assert(tx==0);
+    return rd_ptr<T>(*tx, ref);
+}
+
+template <typename T>
+void delete_ptr(rd_ptr<T> ptr) {
+    if (ptr.ptr_==0) return;
+    ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+void delete_ptr(transaction& tx, rd_ptr<T> ptr) {
+    if (ptr.ptr_==0) return;
+    tx.delete_tx_ptr(ptr.ptr_);
+}
+
+//-----------------------------------------------------------------------------
+// A upgrd_ptr<T> ("upgradable pointer") points to an object that the current
+// transaction has opened for read only access.
+// You can only call a const method through a read pointer.
+// A upgrd_ptr<T> is constructed from an tx_ptr<T> through a constructor
+// having also the transaction as parameter.
+// Once a rd_ptr<T> has been constructed, an tx_ptr<T> can be opened for
+// reading simply by assignment (operator=()) into the constructed rd_ptr<T>.
+// It is safe to derreference a rd_ptr<T> after having assigned the same
+// tx_ptr<T> to a wr_ptr<T>.
+// A upgrd_ptr<T> can be upgraded to a wr_ptr<T> through a constructor.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class upgrd_ptr {
+    typedef upgrd_ptr<T> this_type;
+public:
+    mutable transaction* tx_;
+    mutable transactional_object<T>* ptr_;
+    mutable bool written_;
+
+    inline upgrd_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(&t),
+        ptr_(const_cast<transactional_object<T>*>(t.read_ptr(tx_obj.ptr_))), written_(false)    {}
+
+    template<class Y>
+    upgrd_ptr & operator=(tx_ptr<Y> const&  r) { // never throws
+        //this_type(r).swap(*this);
+        transaction* tx=transaction::current_transaction();
+        if (tx==0) throw "error";
+        tx_=tx;
+        ptr_=r.ptr_;
+        written_=false;
+        return *this;
+    }
+
+    const T* get() const {
+        if (tx_->forced_to_abort()) {
+            tx_->lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+
+        // we don't hold the written object and
+        // we have alrerady written an object on this transaction maybe is this one
+        if (!written_ && tx_->written()) {
+            transactional_object<T>* temp = tx_->get_written(*ptr_);
+
+            // if we found something, store this as the tx_ptr_
+            if (0 != temp) {
+                ptr_ = temp;
+                written_ = true;
+            }
+        }
+
+        return &ptr_->value;
+    }
+
+    inline T const & operator*() const { return *get(); }
+    inline T const * operator->() const { return get(); }
+
+    //operator const T*() const { return get(); }
+
+    typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+    inline operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+    
+    inline void write_ptr(transactional_object<T>* ptr) {
+        ptr_ = ptr;
+        written_ = true;
+    }
+
+    T* write_ptr() {
+        if (tx_->forced_to_abort()) {
+            tx_->lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+
+        // we are already holding the written object
+        if (written_) return ptr_;
+
+        transactional_object<T>* temp = tx_->get_written(ptr_);
+
+        // if we found something, store this as the tx_ptr_
+        if (0 != temp) {
+            ptr_ = temp;
+            written_ = true;
+        } else {
+            ptr_ = tx_->write_ptr(ptr_);
+            written_ = true;
+        }
+
+        return ptr_;
+    }
+
+};
+
+template <typename T>
+void delete_ptr(upgrd_ptr<T> const& ptr) {
+    if (ptr.ptr_==0) return;
+    if (ptr.tx_==0) delete ptr.ptr_;
+    ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+void delete_ptr(transaction& tx, upgrd_ptr<T> const& ptr) {
+    if (ptr.ptr_==0) return;
+    tx.delete_tx_ptr(ptr.ptr_);
+}
+
+//-----------------------------------------------------------------------------
+// A wr_ptr<T> ("write pointer") points to a shared object that the current transaction has opened for writing.
+// A wr_ptr<T> is initialized explicitly from an tx_ptr<T>.
+// A wr_ptr<T> can also be explicitly constructed from a upgrd_ptr<T> as an upgrade-to-writable operation.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class wr_ptr {
+    typedef wr_ptr<T> this_type;
+public:
+    mutable transaction& tx_;
+    mutable transactional_object<T>* ptr_;
+
+    inline wr_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(t),
+        ptr_(t.write_ptr(tx_obj.ptr_))
+    {}
+
+    inline wr_ptr(transaction &t, upgrd_ptr<T> tx_obj) : tx_(t),
+        ptr_(t.write_ptr(tx_obj.ptr_))
+    {
+        tx_obj.write_ptr(ptr_);
+    }
+
+    T* get() {
+        if (tx_.forced_to_abort()) {
+            tx_.lock_and_abort();
+            throw aborted_transaction_exception("aborting transaction");
+        }
+        return &ptr_->value;
+    }
+
+    inline T& operator*() { return *get(); }
+    inline T* operator->() { return get(); }
+
+    typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+    inline operator unspecified_bool_type() const {
+        return ptr_ == 0? 0: &this_type::ptr_;
+    }
+};
+
+template <typename T>
+inline wr_ptr<T> make_wr_ptr(transaction& tx, tx_ptr<T>& ptr) {
+    return wr_ptr<T>(tx, ptr);
+}
+
+
+template <typename T>
+inline wr_ptr<T> make_wr_ptr(tx_ptr<T>& ptr) {
+    transaction* tx = transaction::current_transaction();
+    return wr_ptr<T>(*tx, ptr);
+}
+
+template <typename T>
+inline void delete_ptr(wr_ptr<T> ptr) {
+    if (ptr.ptr_==0) return;
+    ptr.tx_.delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+inline void delete_ptr(transaction& tx, wr_ptr<T> const& ptr) {
+    if (ptr.ptr_==0) return;
+    tx.delete_tx_ptr(ptr.ptr_);
+}
+
+}}
+#endif
+
+
Modified: sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp	(original)
+++ sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -12,12 +12,17 @@
 //////////////////////////////////////////////////////////////////////////////
 
 #include <boost/stm/transaction.hpp>
+#include <boost/stm/non_tx_smart_ptr.hpp>
 #include <boost/stm/contention_manager.hpp>
 #include <iostream>
 
 using namespace std;
 //using namespace boost::stm;
 namespace boost { namespace stm {
+namespace non_tx {
+    std::map<void*, base_transaction_object*> detail::cache_map::map_;
+    
+}
 
 ///////////////////////////////////////////////////////////////////////////////
 // Static initialization
Modified: sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2	(original)
+++ sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2	2009-09-19 08:26:48 EDT (Sat, 19 Sep 2009)
@@ -44,8 +44,9 @@
 
     test-suite "tests"
         :
-          [ run stm.cpp testatom.cpp pointer_test.cpp  smart.cpp  globalIntArr.cpp testHashMapAndLinkedListsWithLocks.cpp irrevocableInt.cpp testHashMapWithLocks.cpp isolatedComposedIntLockInTx.cpp   testInt.cpp isolatedComposedIntLockInTx2.cpp  testLL_latm.cpp isolatedInt.cpp testLinkedList.cpp isolatedIntLockInTx.cpp testLinkedListWithLocks.cpp litExample.cpp testPerson.cpp lotExample.cpp testRBTree.cpp  transferFun.cpp nestedTxs.cpp txLinearLock.cpp testHT_latm.cpp usingLockTx.cpp testHashMap.cpp ]
+          #[ run stm.cpp testatom.cpp pointer_test.cpp  smart.cpp  globalIntArr.cpp testHashMapAndLinkedListsWithLocks.cpp irrevocableInt.cpp testHashMapWithLocks.cpp isolatedComposedIntLockInTx.cpp   testInt.cpp isolatedComposedIntLockInTx2.cpp  testLL_latm.cpp isolatedInt.cpp testLinkedList.cpp isolatedIntLockInTx.cpp testLinkedListWithLocks.cpp litExample.cpp testPerson.cpp lotExample.cpp testRBTree.cpp  transferFun.cpp nestedTxs.cpp txLinearLock.cpp testHT_latm.cpp usingLockTx.cpp testHashMap.cpp ]
           [ run ../example/bank.cpp ]
           #[ run ../example/list.cpp ]
           [ run ../example/counter.cpp ]
+          [ run ../example/non_tx_counter.cpp ]
     ;