Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57103 - in sandbox/stm/branches/vbe/boost/stm: non_tx tx
From: vicente.botet_at_[hidden]
Date: 2009-10-23 11:16:33


Author: viboes
Date: 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
New Revision: 57103
URL: http://svn.boost.org/trac/boost/changeset/57103

Log:
TBoost.STM vbe: Factoring common behavior between non_tx::numeric.hpp and non_tx/pointer.hpp on a new file non_tx::object.hpp

Added:
   sandbox/stm/branches/vbe/boost/stm/non_tx/object.hpp (contents, props changed)
Text files modified:
   sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp | 118 +------------------------------
   sandbox/stm/branches/vbe/boost/stm/non_tx/pointer.hpp | 147 ++++++---------------------------------
   sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp | 2
   sandbox/stm/branches/vbe/boost/stm/tx/object.hpp | 12 --
   sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp | 3
   5 files changed, 37 insertions(+), 245 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
@@ -15,13 +15,10 @@
 #define BOOST_STM_NON_TX_NUMERIC__HPP
 
 //-----------------------------------------------------------------------------
+#include <boost/stm/non_tx/object.hpp>
 //-----------------------------------------------------------------------------
-#include <assert.h>
-#include <boost/stm/transaction.hpp>
-#include <boost/stm/non_tx/detail/cache_map.hpp>
 
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 namespace boost { namespace stm { namespace non_tx {
 
 //-----------------------------------------------------------------------------
@@ -32,119 +29,18 @@
 //-----------------------------------------------------------------------------
 
 template <typename T>
-class numeric {
+class numeric : public object< numeric<T>, T >
+{
+ typedef object< numeric<T> ,T > base_type;
 public:
- T val_;
     //-----------------------------------------------------------------------------
- numeric() : val_(0) {}
-
- //
+ numeric() : base_type(0) {}
     template<class U>
- numeric(numeric<U> const& r) : val_(r.value()) {}
-
- // contructor from a implicitly convertible to T
- template <typename U>
- numeric(U v) : val_(v) {}
- //
- ~numeric() {}
-
- operator T() const { return value(); }
- operator T&() { return ref(); }
-
- T& ref() {
- transaction* tx=current_transaction();
- if (tx!=0) {
- if (tx->forced_to_abort()) {
- tx->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
-
- detail::cache<T>* r(tx->write_ptr(detail::cache_map::get(&val_)));
- return *(r->get());
- }
- return val_;
- }
-
- T value() const {
- transaction* tx=current_transaction();
- if (tx!=0) {
- if (tx->forced_to_abort()) {
- tx->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- detail::cache<T>* r(tx->read_ptr(detail::cache_map::get(&val_)));
- return *(r->get());
- }
- return val_;
- }
-
-#if 0
- numeric& operator--() { --ref(); return *this; }
- T operator--(int) { T n = val_; --ref(); return n; }
-
- numeric& operator++() { ++ref(); return *this; }
- T operator++(int) { T n = val_; ++ref(); return n; }
-
- template <typename U>
- numeric& operator+=(U const &rhs) {
- ref() += rhs;
- return *this;
- }
-
+ numeric(numeric<U> const& r) : base_type(r) {}
     template <typename U>
- numeric& operator-=(U const &rhs) {
- ref() -= rhs;
- return *this;
- }
-
- template <typename U>
- T operator+(U const &rhs) const {
- return value()+u;
- }
-
- template <typename U>
- T operator-(U const &rhs) const {
- return value()+u;
- }
- // as lvalue
- template <typename U>
- numeric& operator=(U& u) {
- ref()=u;
- return *this;
- }
- void swap(numeric & other) { // never throws
- std::swap(obj_, other.obj_);
- }
-#endif
-
+ numeric(U v) : base_type(v) {}
 };
-#if 0
 
-// 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 numeric<T>& lhs, const numeric<U>& rhs) {
- return lhs.ref()==rhs.ref();
-}
-
-template <typename T, typename U>
-inline bool operator==(const T& lhs, const numeric<U>& rhs) {
- return lhs==rhs.ref();
-}
-
-template <typename T, typename U>
-inline bool operator==(const numeric<T>& lhs, const U& rhs) {
- return lhs.ref()==rhs;
-}
-
-template <typename T, typename U>
-inline bool operator!=(const numeric<T>& lhs, const numeric<U>& rhs) {
- return lhs.ref()!=rhs.ref();
-}
-
-template<class T> inline void swap(numeric<T> & a, numeric<T> & b) {
- a.swap(b);
-}
-#endif
 
 typedef numeric<bool> boolean;
 

Added: sandbox/stm/branches/vbe/boost/stm/non_tx/object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/object.hpp 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,86 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_NON_TX_OBJECT__HPP
+#define BOOST_STM_NON_TX_OBJECT__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/non_tx/detail/cache_map.hpp>
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm { namespace non_tx {
+
+//-----------------------------------------------------------------------------
+// class object wraps a non object type providing
+// a transactional view on a transactional context
+// a non-transactional view on a non-transactional context
+// Note: the sizeof(object<T>)==sizeof(T)
+//-----------------------------------------------------------------------------
+
+template <typename Final, typename T>
+class object {
+protected:
+ T val_;
+public:
+ //-----------------------------------------------------------------------------
+ object() : val_() {}
+
+ // constructors
+ template<typename F, typename U>
+ object(object<F,U> const& r) : val_(r.value()) {}
+
+ // contructor from a convertible to T
+ template <typename U>
+ object(U v) : val_(v) {}
+
+ //-----------------------------------------------------------------------------
+ // accessors
+ operator T() const { return value(); }
+ operator T&() { return ref(); }
+
+ //-----------------------------------------------------------------------------
+ T& ref() {
+ transaction* tx=current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ detail::cache<T>* r(tx->write_ptr(detail::cache_map::get(&val_)));
+ return *(r->get());
+ }
+ return val_;
+ }
+
+ //-----------------------------------------------------------------------------
+ T value() const {
+ transaction* tx=current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ detail::cache<T>* r(tx->read_ptr(detail::cache_map::get(&val_)));
+ return *(r->get());
+ }
+ return val_;
+ }
+};
+
+}}}
+#endif
+
+

Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/pointer.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/pointer.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/pointer.hpp 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
@@ -15,11 +15,10 @@
 #define BOOST_STM_NON_TX_POINTER__HPP
 
 //-----------------------------------------------------------------------------
+#include <boost/stm/non_tx/object.hpp>
 //-----------------------------------------------------------------------------
-#include <boost/stm/transaction.hpp>
 
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 namespace boost { namespace stm { namespace non_tx {
 
 //-----------------------------------------------------------------------------
@@ -31,148 +30,52 @@
 //-----------------------------------------------------------------------------
 
 template <typename T>
-class pointer
+class pointer : public object< pointer<T> ,T* >
 {
-protected:
- T* val_;
+ typedef object< pointer<T> , T* > base_type;
+
 public:
     //-----------------------------------------------------------------------------
- pointer() : val_(0) {}
-
- //
+ pointer() : base_type(static_cast<T*>(0)) {}
     template<class U>
- pointer(pointer<U> const& r) : val_(r.value()) {}
-
- // contructor from a implicitly convertible to T
+ pointer(pointer<U> const& r) : base_type(r) {}
     template <typename U>
- pointer(U* v) : val_(v) {}
- pointer(T* v) : val_(v) {}
- //
- ~pointer() {}
-
- operator T*() const { return get(); }
- operator T*&() { return get(); }
-
- T*& get() {
- transaction* tx=current_transaction();
- if (tx!=0) {
- if (tx->forced_to_abort()) {
- tx->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- detail::cache<T*>* r(tx->write_ptr(detail::cache_map::get(&val_)));
- return *(r->get());
-
- }
- return val_;
- }
-
- T* get() const {
- transaction* tx=current_transaction();
- if (tx!=0) {
- if (tx->forced_to_abort()) {
- tx->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- return tx->read(*this).val_;
- detail::cache<T*>* r(tx->read_ptr(detail::cache_map::get(&val_)));
- return *(r->get());
- }
- return val_;
- }
+ pointer(U* v) : base_type(v) {}
+ //pointer(T* v) : base_type(v) {}
 
     T* operator->() const {
- return this->get();
+ return this->value();
     }
- T & operator*() const {
- return *this->get();
+ T& operator*() const {
+ return *this->value();
     }
 
- T * operator->() {
- return this->get();
+ T* operator->() {
+ return this->ref();
     }
- T & operator*() {
- return *this->get();
+ T& operator*() {
+ return *this->ref();
     }
 
 };
 
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 template <typename C, typename R>
-class pointer_to_member
+class pointer_to_member : public transaction_object< pointer_to_member<C,R> >
 {
-protected:
- R C::* val_;
+ typedef object< pointer_to_member<C,R> ,R C::*> base_type;
 public:
     //-----------------------------------------------------------------------------
- pointer_to_member() : val_(0) {}
-
- //
- pointer_to_member(pointer_to_member const& r) : val_(r.value()) {}
-
- // contructor from a implicitly convertible to T
- pointer_to_member(R C::* v) : val_(v) {}
- //
-
- operator R C::*() const { return get(); }
- operator R C::*&() { return get(); }
-
- R C::*& get() {
- transaction* tx=current_transaction();
- if (tx!=0) {
- if (tx->forced_to_abort()) {
- tx->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
-
- detail::cache<R C::*>* r(tx->write_ptr(detail::cache_map::get(&val_)));
- return *(r->get());
- }
- return val_;
- }
-
- R C::* const * get() const {
- transaction* tx=current_transaction();
- if (tx!=0) {
- if (tx->forced_to_abort()) {
- tx->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- detail::cache<R C::*>* r(tx->read_ptr(detail::cache_map::get(&val_)));
- return *(r->get());
- }
- return val_;
- }
+ pointer_to_member() : base_type(static_cast<R C::*>(0)) {}
 
+ template <typename D, typename S>
+ pointer_to_member(pointer_to_member<D,S> const& r) : base_type(r) {}
+ template <typename D, typename S>
+ pointer_to_member(S D::* v) : base_type(v) {}
+ //pointer_to_member(R C::* v) : base_type(v) {}
 };
 
-#if 0
-
-// 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 pointer<T>& lhs, const pointer<U>& rhs) {
- return lhs.ref()==rhs.ref();
-}
-
-template <typename T, typename U>
-inline bool operator==(const T& lhs, const pointer<U>& rhs) {
- return lhs==rhs.ref();
-}
-
-template <typename T, typename U>
-inline bool operator==(const pointer<T>& lhs, const U& rhs) {
- return lhs.ref()==rhs;
-}
-
-template <typename T, typename U>
-inline bool operator!=(const pointer<T>& lhs, const pointer<U>& rhs) {
- return lhs.ref()!=rhs.ref();
-}
-
-template<class T> inline void swap(pointer<T> & a, pointer<T> & b) {
- a.swap(b);
-}
-#endif
-
 }}}
 #endif
 

Modified: sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
@@ -15,8 +15,8 @@
 #define BOOST_STM_TX_NUMERIC__HPP
 
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 #include <boost/stm/tx/object.hpp>
+//-----------------------------------------------------------------------------
 
 //-----------------------------------------------------------------------------
 namespace boost { namespace stm { namespace tx {

Modified: sandbox/stm/branches/vbe/boost/stm/tx/object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/object.hpp 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
@@ -46,18 +46,12 @@
     // contructor from a convertible to T
     template <typename U>
     object(U v) : val_(v) {}
- //object(T v) : val_(v) {}
-
- #if 0
- template<typename F, typename U>
- object& operator=(object<F, U> const& r) {
- val_=r.value();
- }
- #endif
 
     operator T() const { return value(); }
     operator T&() { return ref(); }
 
+ //-----------------------------------------------------------------------------
+ // accessors
     T& ref() {
         transaction* tx=current_transaction();
         if (tx!=0) {
@@ -71,6 +65,7 @@
         return val_;
     }
 
+ //-----------------------------------------------------------------------------
     T value() const {
         transaction* tx=current_transaction();
         if (tx!=0) {
@@ -82,7 +77,6 @@
         }
         return val_;
     }
-
 };
 
 }}}

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 2009-10-23 11:16:32 EDT (Fri, 23 Oct 2009)
@@ -15,10 +15,9 @@
 #define BOOST_STM_TX_POINTER__HPP
 
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 #include <boost/stm/tx/object.hpp>
-
 //-----------------------------------------------------------------------------
+
 //-----------------------------------------------------------------------------
 namespace boost { namespace stm { namespace tx {
 


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