Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58874 - in sandbox/stm/branches/vbe/boost/stm: . detail tx
From: vicente.botet_at_[hidden]
Date: 2010-01-10 11:43:42


Author: viboes
Date: 2010-01-10 11:43:40 EST (Sun, 10 Jan 2010)
New Revision: 58874
URL: http://svn.boost.org/trac/boost/changeset/58874

Log:
TBoost.STM vbe:
* add BOOST_STM_TX_RETURN_NOTHING
* make mixin pass the final instance instead of this when write or read is called
* let BOOST_STM_TX_DELETE_PTR use stm::delete_ptr so we can overload this function and call for example with a smart pointer instead of a pointer.
* improve usability of smart pointers

Text files modified:
   sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp | 5 +-
   sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 6 ++-
   sandbox/stm/branches/vbe/boost/stm/language_like.hpp | 5 ++
   sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp | 4 +-
   sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp | 71 +++++++++++++++++++++++++++++++--------
   5 files changed, 69 insertions(+), 22 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-10 11:43:40 EST (Sun, 10 Jan 2010)
@@ -54,8 +54,9 @@
     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));
+ //return T::make_cache(static_cast<T const&>(rhs), t);
+ return T::make_cache(rhs, t);
+ //return static_cast<T*>(rhs.make_cache(t));
         }
     };
 

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-10 11:43:40 EST (Sun, 10 Jan 2010)
@@ -48,9 +48,11 @@
       i != transactionsInFlight_.end(); ++i)
    {
       // if this is our threadId, skip it
- if (((transaction*)*i)->threadId_ == this->threadId_) continue;
+ //if (((transaction*)*i)->threadId_ == this->threadId_) continue;
+ if ((*i)->threadId_ == this->threadId_) continue;
 
- if (((transaction*)*i)->isolated()) return true;
+ //if (((transaction*)*i)->isolated()) return true;
+ if ((*i)->isolated()) return true;
    }
 
    return false;

Modified: sandbox/stm/branches/vbe/boost/stm/language_like.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/language_like.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/language_like.hpp 2010-01-10 11:43:40 EST (Sun, 10 Jan 2010)
@@ -179,6 +179,9 @@
 #define BOOST_STM_TX_RETURN(TX, EXPRESSION) \
     return boost::stm::detail::commit_and_return(TX, EXPRESSION)
 
+#define BOOST_STM_TX_RETURN_NOTHING(TX) \
+ if (!TX.commit());else return
+
 //---------------------------------------------------------------------------
 // return the expression EXPRESSION from inside a transaction TX
 //---------------------------------------------------------------------------
@@ -311,7 +314,7 @@
 //---------------------------------------------------------------------------
 
 #define BOOST_STM_TX_DELETE_PTR(TX, PTR) \
- (TX).delete_ptr(PTR)
+ boost::stm::delete_ptr(TX, PTR)
 
 //---------------------------------------------------------------------------
 // deletes the allocated object on transaction TX

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-10 11:43:40 EST (Sun, 10 Jan 2010)
@@ -72,7 +72,7 @@
                 throw aborted_transaction_exception("aborting transaction");
             }
 
- return tx->write(*this).val_;
+ return tx->write(*static_cast<Final*>(this)).val_;
         }
         return val_;
     }
@@ -88,7 +88,7 @@
                 tx->lock_and_abort();
                 throw aborted_transaction_exception("aborting transaction");
             }
- return tx->read(*this).val_;
+ return tx->read(*static_cast<Final const*>(this)).val_;
         }
         return val_;
     }

Modified: sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp 2010-01-10 11:43:40 EST (Sun, 10 Jan 2010)
@@ -28,13 +28,29 @@
 template <typename T>
 class read_ptr
 {
+ typedef read_ptr<T> this_type;
 public:
 
    inline read_ptr(transaction &t, T const &tx_obj) :
       t_(t), tx_ptr_(&const_cast<T&>(t_.read(tx_obj))), written_(false)
    {}
 
- const T* get() const
+ inline read_ptr(transaction &t, T const *tx_ptr) :
+ t_(t), tx_ptr_(const_cast<T*>(t_.read_ptr(tx_ptr))), written_(false)
+ {}
+
+ inline read_ptr<T> & operator=(read_ptr<T> const& rhs) { // never throws
+ if (this!=&rhs) {
+ tx_ptr_=rhs.tx_ptr_;
+ }
+ return *this;
+ }
+ inline read_ptr<T> & operator=(T const * ptr) { // never throws
+ tx_ptr_=const_cast<T*>(ptr);
+ return *this;
+ }
+
+ T* get() const
    {
       if (t_.forced_to_abort())
       {
@@ -90,6 +106,12 @@
       return tx_ptr_;
    }
 
+ typedef T* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return tx_ptr_ == 0? 0: &this_type::tx_ptr_;
+ }
+
 private:
 
    mutable transaction &t_;
@@ -110,13 +132,17 @@
    {}
 
    inline write_ptr(transaction &t, T* ptr) :
- t_(t), tx_obj_(t_.write_ptr(ptr))
+ t_(t), tx_obj_(*t_.write_ptr(ptr))
    {}
 
    inline write_ptr(transaction &t, read_ptr<T> & tx_obj) :
       t_(t), tx_obj_(*t_.write_ptr(tx_obj.tx_ptr_))
    {}
 
+ inline write_ptr(read_ptr<T> & ptr) :
+ t_(ptr.trans()), tx_obj_(*ptr.write_ptr())
+ {}
+
     write_ptr& operator=(T const* ptr) {
         tx_obj_=*t_.write_ptr(ptr);
         return *this;
@@ -125,31 +151,46 @@
         tx_obj_=*t_.write_ptr(tx_obj.tx_ptr_);
         return *this;
     }
- inline T& operator*()
- {
- if (t_.forced_to_abort())
- {
- t_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- return tx_obj_;
- }
-
- inline T* operator->()
- {
+ T* get() const
+ {
       if (t_.forced_to_abort())
       {
          t_.lock_and_abort();
          throw aborted_transaction_exception("aborting transaction");
       }
       return &tx_obj_;
- }
+ }
+ T& operator*() { return *get(); }
+ T* operator->() { return get(); }
 
 private:
    mutable transaction &t_;
    mutable T &tx_obj_;
 };
 
+template <typename T>
+inline write_ptr<T> make_write_ptr(transaction& tx, T const* ptr) {
+ return write_ptr<T>(tx, ptr);
+}
+
+template <typename T>
+inline write_ptr<T> make_write_ptr(transaction& tx, T* ptr) {
+ return write_ptr<T>(tx, ptr);
+}
+
+template <typename T>
+inline write_ptr<T> make_write_ptr(read_ptr<T>& ptr) {
+ return write_ptr<T>(ptr);
+}
+
+template <typename T>
+void delete_ptr(transaction& tx, read_ptr<T>& ptr) {
+ delete_ptr(tx, ptr.get());
+}
+template <typename T>
+void delete_ptr(transaction& tx, write_ptr<T>& ptr) {
+ delete_ptr(tx, ptr.get());
+}
 }}
 #endif
 


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