Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56325 - in sandbox/stm/branches/vbe: boost boost/stm boost/stm/detail libs/stm/example libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-09-20 15:47:09


Author: viboes
Date: 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
New Revision: 56325
URL: http://svn.boost.org/trac/boost/changeset/56325

Log:
TBoost.Stm vbe
* bug on transaction:_object::clone function
* adding transaction_object_ptr.hpp and example counter_ptr
* adding some constructors and assignments to write_ptr
Added:
   sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp (contents, props changed)
   sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp (contents, props changed)
Text files modified:
   sandbox/stm/branches/vbe/boost/stm.hpp | 1 +
   sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp | 6 ++++--
   sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 4 ----
   sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp | 20 ++++++++++++++++++++
   sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp | 6 +++---
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 4 ++--
   sandbox/stm/branches/vbe/libs/stm/example/bank.cpp | 5 ++---
   sandbox/stm/branches/vbe/libs/stm/example/counter.cpp | 7 ++++---
   sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 | 3 ++-
   9 files changed, 38 insertions(+), 18 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-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -37,6 +37,7 @@
 
 #include <boost/stm/transaction.hpp>
 #include <boost/stm/contention_manager.hpp>
+#include <boost/stm/transaction_object_ptr.hpp>
 #include <boost/stm/detail/tx_ptr.hpp>
 #include <boost/stm/tx_smart_ptr.hpp>
 #include <boost/stm/non_tx_smart_ptr.hpp>

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-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -192,7 +192,7 @@
 #endif
    {}
 
-#if 0
+#if 1
     base_transaction_object(const base_transaction_object &t)
         : transactionThread_(kInvalidThread)
         , newMemory_(0)
@@ -306,7 +306,8 @@
 
     //--------------------------------------------------------------------------
     virtual base_transaction_object* clone() const {
- return cache_clone(*this);
+ Derived* tmp = cache_clone(*static_cast<Derived const*>(this));
+ return tmp;
     }
 
    //--------------------------------------------------------------------------
@@ -354,6 +355,7 @@
    native_trans() : value_(T()) {}
    native_trans(T const &rhs) : value_(rhs) {}
    native_trans(native_trans const &rhs) : value_(rhs.value_) {}
+ ~native_trans() {}
 
    native_trans& operator=(T const &rhs) { value_ = rhs; return *this; }
 

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 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -1901,7 +1901,6 @@
       {
          for (MemoryContainerList::iterator j = i->second.begin(); j != i->second.end(); ++j)
          {
- //std::cout << __LINE__ << " delete @" << int(*j) << std::endl;
             delete *j;
          }
          deletionBuffer_.erase(i);
@@ -2018,10 +2017,7 @@
 #if PERFORMING_VALIDATION
       i->first->version_++;
 #endif
-
- //delete i->second;
       cache_release(i->second);
-
    }
 
    writeList().clear();

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-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -23,6 +23,9 @@
 namespace boost { namespace stm {
 
 template <typename T>
+class write_ptr;
+
+template <typename T>
 class read_ptr
 {
 public:
@@ -92,6 +95,7 @@
    mutable transaction &t_;
    mutable T *tx_ptr_;
    mutable bool written_;
+ template <typename X> friend class write_ptr;
 };
 
 //-----------------------------------------------------------------------------
@@ -105,6 +109,22 @@
       t_(t), tx_obj_(t_.write(tx_obj))
    {}
 
+ inline write_ptr(transaction &t, T* 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_))
+ {}
+
+ write_ptr& operator=(T const* ptr) {
+ tx_obj_=*t_.write_ptr(ptr);
+ return *this;
+ }
+ write_ptr& operator=(read_ptr<T> & tx_obj) {
+ tx_obj_=*t_.write_ptr(tx_obj.tx_ptr_);
+ return *this;
+ }
    inline T& operator*()
    {
       if (t_.forced_to_abort())

Modified: sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -152,9 +152,9 @@
 // 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>.
+// A rd_ptr<T> is constructed from an T pointer or reference.
+// Once a rd_ptr<T> has been constructed, an cache is opened for
+// reading.
 // 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

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-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -2094,7 +2094,6 @@
 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_copy(&val, p);
@@ -2104,7 +2103,8 @@
 #else
 template <class T>
 inline T* cache_clone(const T& val) {
- return new T(val);
+ T* tmp=new T(val);
+ return tmp;
 }
 #endif
 

Added: sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -0,0 +1,63 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TRANSACTION_OBJECT_PTR__H
+#define BOOST_STM_TRANSACTION_OBJECT_PTR__H
+
+
+#include <boost/stm/base_transaction.hpp>
+
+namespace boost { namespace stm {
+
+template <typename TO>
+class transaction_object_ptr : public transaction_object<transaction_object_ptr<TO> > {
+public:
+ TO* ptr_;
+ typedef transaction_object_ptr<TO> this_type;
+ typedef transaction_object<transaction_object_ptr<TO> > base_type;
+ transaction_object_ptr() : base_type(), ptr_(0) {
+ std::cout << "transaction_object_ptr "<< __LINE__ <<" " << __FILE__ << " "<< int(this) << std::endl;
+ }
+ transaction_object_ptr(const transaction_object_ptr & rhs) : base_type(rhs), ptr_(rhs.ptr_) {
+ std::cout << "transaction_object_ptr "<< __LINE__ <<" " << __FILE__ << " "<< int(this) <<" "<< int(&rhs) << std::endl;
+ }
+ transaction_object_ptr(transaction_object_ptr & rhs) : base_type(rhs), ptr_(rhs.rhs) {
+ std::cout << "transaction_object_ptr "<< __LINE__ <<" " << __FILE__ << " "<< int(this) <<" "<< int(&rhs) << std::endl;
+ }
+ transaction_object_ptr(TO* ptr) : base_type(), ptr_(ptr) {
+ std::cout << "transaction_object_ptr "<<__LINE__ <<" " << __FILE__ << " "<< int(this) << std::endl;
+ }
+ ~transaction_object_ptr() {
+ std::cout << "transaction_object_ptr "<<__LINE__ <<" " << __FILE__ << " "<< int(this) << std::endl;
+ }
+ this_type& operator=(TO* rhs) {
+ ptr_=rhs;
+ return *this;
+ }
+
+ TO* get() const {
+ std::cout << "get" << std::endl;
+ return ptr_;
+ }
+
+ inline TO& operator*() const { return *get(); }
+ //inline TO* operator->() const { return get(); }
+
+ };
+
+
+} // namespace core
+}
+#endif // BASE_TRANSACTION_H
+
+

Modified: sandbox/stm/branches/vbe/libs/stm/example/bank.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/bank.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/bank.cpp 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -15,10 +15,8 @@
 #include <boost/foreach.hpp>
 #include <boost/thread.hpp>
 #include <boost/shared_ptr.hpp>
-//#include <string>
 #include <vector>
 #include <list>
-//#include <iostream>
 #include <stdlib.h>
 #define foreach BOOST_FOREACH
 
@@ -67,6 +65,7 @@
     }
 };
 
+
 struct teller {
     teller(bank* b)
         : bank_(b){
@@ -297,7 +296,7 @@
 
     int res=0;
     res+=test_account();
- res+=test_vector_int();
+ //res+=test_vector_int();
 
     return res;
 

Modified: sandbox/stm/branches/vbe/libs/stm/example/counter.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/counter.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/counter.cpp 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -85,9 +85,10 @@
     th3.join();
     th4.join();
 
- bool fails=!check(2);
- fails = fails || !assign();
- fails = fails || !test_const(counter);
+ int fails=0;
+ fails += !check(2);
+ fails += !assign();
+ fails += !test_const(counter);
     return fails;
 }
 

Added: sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp 2009-09-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -0,0 +1,143 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/stm.hpp>
+#include <boost/thread.hpp>
+#include <vector>
+#include <list>
+#include <stdlib.h>
+
+using namespace std;
+using namespace boost;
+using namespace boost::stm;
+
+typedef native_trans<int> tx_int;
+typedef transaction_object_ptr<tx_int> tx_int_ptr;
+typedef transaction_object_ptr<const tx_int> tx_int_const_ptr;
+
+tx_int counter;
+tx_int_ptr counter_ptr, counter2_ptr;
+//tx_int_const_ptr counter_const_ptr;
+
+void inc() {
+ thread_initializer thi;
+
+ use_atomic(_) {
+ // ++(*counter_ptr)
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ //tx_int_ptr tmp = *tx_counter_ptr_ptr;
+ write_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
+ ++(*tx_counter_ptr);
+ }
+}
+void decr() {
+ thread_initializer thi;
+
+ use_atomic(_) {
+ // --(*counter_ptr)
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ write_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
+ --(*tx_counter_ptr);
+ }
+}
+bool check(int val) {
+ //thread_initializer thi;
+ bool res;
+ use_atomic(_) {
+ // *counter_ptr==val
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ read_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
+ res =(*tx_counter_ptr==val);
+ }
+ return res;
+}
+
+bool assign() {
+ //thread_initializer thi;
+ use_atomic(_) {
+ // *tx_counter2_ptr=*tx_counter_ptr;
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ write_ptr<tx_int_ptr> tx_counter2_ptr_ptr(_, counter2_ptr);
+ tx_counter2_ptr_ptr=tx_counter_ptr_ptr;
+ }
+ bool res=true;
+ use_atomic(_) {
+ //read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ //read_ptr<tx_int_ptr> tx_counter2_ptr_ptr(_, counter2_ptr);
+ //res = (tx_counter2_ptr_ptr==tx_counter2_ptr_ptr) ;
+ //res= (_.read(counter_ptr)==_.read(counter2_ptr));
+ }
+ return res;
+}
+#if 0
+bool test_const(tx_int_const_ptr& const ptr) {
+ //thread_initializer thi;
+ use_atomic(_) {
+ write_ptr<tx_int_const_ptr> tx_counter_const_ptr_ptr(_, counter_const_ptr);
+ tx_counter_const_ptr_ptr=ptr;
+ }
+ bool res=true;
+ use_atomic(_) {
+ //res =(c==counter2) ;
+ }
+ return res;
+}
+#endif
+
+int test_counter() {
+ use_atomic(_) {
+ write_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ _.throw_if_forced_to_abort_on_new();
+ //tx_int* tmp=_.as_new(new tx_int());
+ //tx_int* tmp=&counter;
+ *tx_counter_ptr_ptr=_.as_new(new tx_int());
+ //*tx_counter_ptr_ptr=&counter;
+ std::cout << __LINE__ <<" " << __FILE__ << std::endl;
+
+ //(_.write(counter_ptr)).ptr_=_.as_new(new tx_int());
+ }
+ std::cout << __LINE__ <<" " << __FILE__ << std::endl;
+ thread th1(inc);
+ thread th2(decr);
+#if 0
+ thread th3(inc);
+ thread th4(inc);
+#endif
+
+ th1.join();
+ th2.join();
+#if 0
+ th3.join();
+ th4.join();
+#endif
+ std::cout << __LINE__ <<" " << __FILE__ << std::endl;
+ bool fails=false;
+ std::cout << __LINE__ <<" " << __FILE__ << std::endl;
+ fails=fails || check(0);
+ //fails = fails || !assign();
+ //fails = fails || !test_const(counter);
+ return fails;
+}
+
+int main() {
+ transaction::enable_dynamic_priority_assignment();
+ transaction::do_deferred_updating();
+ transaction::initialize();
+ thread_initializer thi;
+ srand(time(0));
+
+ test_counter();
+
+ return 0;
+
+}

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-20 15:47:07 EDT (Sun, 20 Sep 2009)
@@ -45,8 +45,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 ../example/bank.cpp ]
+ #[ run ../example/bank.cpp ]
           #[ run ../example/list.cpp ]
           [ run ../example/counter.cpp ]
+ [ run ../example/counter_ptr.cpp ]
           [ run ../example/non_tx_counter.cpp ]
     ;


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