Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57076 - in sandbox/stm/branches/vbe: boost/stm/detail boost/stm/tx libs/stm/example libs/stm/example/non_tx libs/stm/example/tx libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-10-22 16:34:25


Author: viboes
Date: 2009-10-22 16:34:23 EDT (Thu, 22 Oct 2009)
New Revision: 57076
URL: http://svn.boost.org/trac/boost/changeset/57076

Log:
TBoost.STM vbe: Add tx/pointer.cpp test
* Separate the pointer part from the file numeric.cpp in tx/pointer.cpp test.
* Minor updates

Added:
   sandbox/stm/branches/vbe/libs/stm/example/non_tx/
   sandbox/stm/branches/vbe/libs/stm/example/tx/
   sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp (contents, props changed)
Text files modified:
   sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp | 20 +++---
   sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp | 7 ++
   sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp | 14 ++--
   sandbox/stm/branches/vbe/libs/stm/example/list.cpp | 45 ++++++++++------
   sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp | 109 ---------------------------------------
   sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 | 1
   6 files changed, 55 insertions(+), 141 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp 2009-10-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -37,7 +37,7 @@
 //-----------------------------------------------------------------------------
 template <typename T>
 struct base_transaction_object_deleter : deleter {
- T* ptr_;
+ T* ptr_;
     base_transaction_object_deleter(T* ptr) : ptr_(ptr) {}
     virtual void reset() {
         static_cast<base_transaction_object*>(ptr_)->transaction_thread(invalid_thread_id());
@@ -51,7 +51,7 @@
 //-----------------------------------------------------------------------------
 template <typename T>
 struct base_transaction_object_array_deleter : deleter {
- T* ptr_;
+ T* ptr_;
     std::size_t size_;
     base_transaction_object_array_deleter (T* ptr, std::size_t size) : ptr_(ptr), size_(size) {}
     virtual void reset() {
@@ -69,7 +69,7 @@
 //-----------------------------------------------------------------------------
 template <typename T>
 struct non_transaction_object_deleter : deleter {
- T* ptr_;
+ T* ptr_;
     typedef typename T::binds_list binds_type;
     typedef typename T::binds_list::iterator binds_iterator;
 
@@ -87,12 +87,12 @@
 };
 
 //-----------------------------------------------------------------------------
-// For array of non transactional object types
+// For array of non transactional object types
 //-----------------------------------------------------------------------------
 
 template <typename T>
 struct non_transaction_object_array_deleter : deleter {
- T* ptr_;
+ T* ptr_;
     std::size_t size_;
     typedef typename T::binds_list binds_type;
     typedef typename T::binds_list::iterator binds_iterator;
@@ -130,7 +130,7 @@
     inline void release(deleter_type* ptr) {
         delete ptr;
     }
-
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
     inline deleter_type* make(base_transaction_object* p) {
@@ -160,7 +160,7 @@
     inline deleter_type* make_array(base_transaction_object const & r, std::size_t size) {
         return const_cast<deleter_type*>(&r);
     }
-
+
 #else
 
 //-----------------------------------------------------------------------------
@@ -180,7 +180,7 @@
         ptr->release();
         delete ptr;
     }
-
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
     template <typename T>
@@ -199,7 +199,7 @@
     inline deleter_type* make(T const& r) {
         return new base_transaction_object_deleter<T>(const_cast<T*>(&r));
     }
-
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
     template <typename T>
@@ -218,7 +218,7 @@
     inline deleter_type* make_array(T const& r, std::size_t size) {
         return new base_transaction_object_array_deleter<T>(const_cast<T*>(&r, size));
     }
-
+
 #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-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -20,9 +20,14 @@
 //#include <boost/stm/non_tx/detail/cache_map.hpp>
 
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 namespace boost { namespace stm { namespace tx {
 
+//-----------------------------------------------------------------------------
+// mixing transactional object numeric class that wraps a numeric builtin type providing
+// a transparent transactional view on a transactional context
+// a non-transactional view on a non-transactional context
+// Note: the sizeof(numeric<T>)>>>>=sizeof(T)
+//-----------------------------------------------------------------------------
 template <typename T>
 class numeric : public transaction_object< numeric<T> >
 {

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-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -23,9 +23,12 @@
 namespace boost { namespace stm { namespace tx {
 
 //-----------------------------------------------------------------------------
-// class pointer wraps a transactional_object providing builting operators
+// mixing transactional object smart pointer providing
+// typycal smart pointer operators +
+// a transparent transactional view on a transactional context.
+// a non-transactional view on a non-transactional context
+// Note: the sizeof(pointer<T>)>>>>=sizeof(T*)
 //-----------------------------------------------------------------------------
-
 template <typename T>
 class pointer : public transaction_object< pointer<T> >
 {
@@ -56,13 +59,12 @@
                 tx->lock_and_abort();
                 throw aborted_transaction_exception("aborting transaction");
             }
-
             return tx->write(*this).val_;
         }
         return val_;
     }
 
- T const * get() const {
+ T* get() const {
         transaction* tx=current_transaction();
         if (tx!=0) {
             if (tx->forced_to_abort()) {
@@ -74,10 +76,10 @@
         return val_;
     }
 
- T const * operator->() const {
+ T* operator->() const {
         return this->get();
     }
- T const & operator*() const {
+ T& operator*() const {
         return *this->get();
     }
 

Modified: sandbox/stm/branches/vbe/libs/stm/example/list.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/list.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/list.cpp 2009-10-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -66,11 +66,11 @@
 
     std::size_t size() const {
         std::size_t res=0;
- use_atomic(_) {
+ atomic(_) {
             upgrd_ptr<std::size_t> s(_, size_);
             std::cout << "size_.get()" << s.get() << std::endl;
             res=*s;
- }
+ } end_atom
         return res;
     }
 
@@ -79,8 +79,8 @@
     //--------------------------------------------------------------------------
     void insert(const T& val) {
         cerr << __LINE__ << " insert" << endl;
- // use_atomic(_) {
- for (boost::stm::transaction _; !_.committed() && _.restart(); _.end()) {
+ atomic(_) {
+ //for (boost::stm::transaction _; !_.committed() && _.restart(); _.end()) {
         cerr << __LINE__ << " insert" << endl;
             upgrd_ptr<list_node<T> > prev(_, head_);
             upgrd_ptr<list_node<T> > curr(_, head_->next_);
@@ -103,6 +103,9 @@
                 //++(*size_tx);
 
             }
+ } end_atom
+ catch (...) {
+ cerr << __LINE__ << " insert" << endl;
         }
         cerr << __LINE__ << " insert" << endl;
    }
@@ -110,7 +113,7 @@
     // search function
     bool lookup(const T& val) const {
         bool found = false;
- use_atomic(_) {
+ atomic(_) {
             rd_ptr<list_node<T> > curr(_, head_);
             curr = curr->next_;
             while (curr) {
@@ -119,6 +122,9 @@
             }
 
             found = ((curr) && (curr->value_ == val));
+ } end_atom
+ catch (...) {
+ cerr << __LINE__ << " lookup" << endl;
         }
         return found;
     }
@@ -126,7 +132,7 @@
     // remove a node if its value == val
     void remove(const T& val)
     {
- use_atomic(_) {
+ atomic(_) {
             // find the node whose val matches the request
             upgrd_ptr<list_node<T> > prev(_,head_);
             upgrd_ptr<list_node<T> > curr(_,prev->next_);
@@ -147,7 +153,7 @@
                 prev = curr;
                 curr = prev->next_;
             }
- }
+ } end_atom
     }
 
 };
@@ -165,41 +171,46 @@
         cerr << " create size " << l->size() << endl;
         //cerr << " insert " << l.get() << endl;
         //l->insert(1);
- } catch (...) {
+ } end_atom
+ catch (...) {
         cerr << "aborted" << endl;
     }
- //cerr << l->size() << endl;
+ cerr << " create pointer " << l.get() << endl;
 }
 void insert1() {
     //thread_initializer thi;
     atomic(_) {
         cerr << __LINE__ << " try" << endl;
         cerr << __LINE__ << " insert1 size " << l->size() << endl;
- make_wr_ptr(_,l)->insert(1);
+ wr_ptr<test::list<int> > l_tx(_,l);
+ cerr << __LINE__ << " insert1 size " << l_tx->size() << endl;
+ int val = 1;
+ l_tx->insert(val);
         cerr << __LINE__ << " insert1 size " << l->size() << endl;
- } catch(...) {
+ } end_atom
+ catch(...) {
         cerr << __LINE__ << " aborted" << endl;
     }
 }
 void insert2() {
     thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
         make_wr_ptr(_,l)->insert(2);
- }
+ } end_atom
 }
 
 void insert3() {
     thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
         make_wr_ptr(_,l)->insert(3);
- }
+ } end_atom
 }
 bool check_size(std::size_t val) {
     int res=true;
- use_atomic(_) {
+ atomic(_) {
         //cerr << "size" <<make_rd_ptr(_,l)->size()<< endl;
         res = make_rd_ptr(_,l)->size()==val;
- }
+ } end_atom
     return res;
 }
 int test1() {

Modified: sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp 2009-10-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -25,110 +25,6 @@
 stm::tx::int_t counter(0);
 stm::tx::int_t counter2(0);
 
-struct A {
- A() : i(0), ptr(&i) {
-
- }
- stm::tx::int_t i;
- stm::tx::pointer<stm::tx::int_t> const ptr;
-};
-
-struct B {
- B() : a_ptr() {}
- stm::tx::pointer<A> a_ptr;
-};
-
-
-A a;
-B b;
-
-bool test_ptr() {
- {
- const stm::tx::numeric<int> ci=10;
- const stm::tx::numeric<int> cj = 10;
- stm::tx::pointer<const stm::tx::numeric<int> > pc = &ci;
- stm::tx::pointer<const stm::tx::numeric<int> > pc2 = &cj;
- pc=&cj;
- stm::tx::pointer<const stm::tx::numeric<int> > const cpc = pc;
- //cpc=pc2; // this must not compile
- stm::tx::pointer<stm::tx::pointer<const stm::tx::numeric<int> > > ppc;
- }
- {
- const int ci=10;
- const int cj = 10;
- stm::tx::pointer<const int> pc = &ci;
- stm::tx::pointer<const int> pc2 = &cj;
- pc=&cj;
- stm::tx::pointer<const int> const cpc = pc;
- //cpc=pc2; // this must not compile
- stm::tx::pointer<stm::tx::pointer<const int> > ppc;
- }
-
- stm::tx::numeric<int> i;
- stm::tx::pointer<stm::tx::numeric<int> > p;
- stm::tx::pointer<stm::tx::numeric<int> > const cp = &i;
-
- atomic(_) {
- b.a_ptr=&a;
- b.a_ptr->i =1;
- } end_atom
- atomic(_) {
- BOOST_STM_TX_RETURN(_, (b.a_ptr->i==1)&&(*b.a_ptr->ptr==1));
- } end_atom
- return false;
-}
-
-bool test_array() {
- {
- int v[2];
- int * p;
- p = &v[0];
- p = v;
- ++p;
- }
- stm::tx::numeric<int> v[2];
- stm::tx::pointer<stm::tx::numeric<int> > p;
- p = &v[0];
- p = v;
- ++p;
- bool res=true;
- return res;
-}
-
-bool test_array_ptr() {
- {
- int * v= new int[2];
- int * p;
- p = &v[0];
- p = v;
- ++p;
- }
- atomic(_) {
- //stm::tx::pointer<stm::tx::numeric<int> > v= BOOST_STM_TX_NEW_ARRAY(_, 2, stm::tx::numeric<int>);
- stm::tx::pointer<stm::tx::numeric<int> > v= BOOST_STM_NEW_ARRAY(2, stm::tx::numeric<int>);
-
- stm::tx::pointer<stm::tx::numeric<int> > p;
- p = &v[0];
- p = v;
- ++p;
- bool res=true;
- BOOST_STM_RETURN(res);
- } end_atom
- #if 0
- {
- stm::tx::pointer<stm::tx::numeric<int> > v= BOOST_STM_NEW_ARRAY(2, stm::tx::numeric<int>);
-
- stm::tx::pointer<stm::tx::numeric<int> > p;
- p = &v[0];
- p = v;
- ++p;
- }
- #endif
- bool res=true;
- BOOST_STM_RETURN(res);
- return false;
-}
-
 void inc() {
     stm::thread_initializer thi;
 
@@ -230,7 +126,7 @@
     return false;
 }
 
-int test_counter() {
+int test_all() {
 
     thread th1(inc);
     thread th2(decr);
@@ -248,7 +144,6 @@
     fails += !test_assign();
     fails += !test_less();
     fails += !test_le();
- fails += !test_ptr();
     fails += !test_const(counter);
     return fails;
 }
@@ -259,6 +154,6 @@
     stm::transaction::initialize();
     stm::thread_initializer thi;
 
- return test_counter();
+ return test_all();
 
 }

Added: sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp 2009-10-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -0,0 +1,214 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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 <assert.h>
+#include <list>
+#include <iostream>
+#include <stdlib.h>
+
+using namespace std;
+using namespace boost;
+
+stm::tx::int_t counter(0);
+stm::tx::int_t counter2(0);
+
+struct A {
+ A() : i(0), ptr(&i) {
+
+ }
+ stm::tx::int_t i;
+ stm::tx::pointer<stm::tx::int_t> const ptr;
+};
+
+struct B {
+ B() : a_ptr() {}
+ stm::tx::pointer<A> a_ptr;
+};
+
+
+bool test_ptr_to_tx_const() {
+ #if 0
+ {
+ const int ci = 10;
+ const int cj = 20;
+ const int * pc = &ci;
+ const int * pc2 = &cj;
+ pc=&cj;
+ const int * const cpc = pc;
+ //cpc=pc2; // this must not compile
+ const int ** ppc;
+ }
+ #endif
+ const stm::tx::int_t ci = 10;
+ const stm::tx::int_t cj = 20;
+ stm::tx::pointer<const stm::tx::int_t > pc = &ci;
+ stm::tx::pointer<const stm::tx::int_t > pc2 = &cj;
+ pc=&cj;
+ stm::tx::pointer<const stm::tx::int_t > const cpc = pc;
+ //cpc=pc2; // this must not compile
+ stm::tx::pointer<stm::tx::pointer<const stm::tx::int_t > > ppc;
+ return true;
+}
+bool test_ptr_to_const() {
+ const int ci = 10;
+ const int cj = 20;
+ stm::tx::pointer<const int> pc = &ci;
+ stm::tx::pointer<const int> pc2 = &cj;
+ stm::tx::pointer<const int> const cpc = pc;
+ //cpc=pc2; // this must not compile
+ stm::tx::pointer<stm::tx::pointer<const int> > ppc;
+ atomic(_) {
+ pc=&cj;
+ } end_atom
+ atomic(_) {
+ BOOST_STM_TX_RETURN(_, (pc==&cj)&&(*pc==20)&&(*cpc==10));
+ } end_atom
+ return false;
+}
+
+bool test_ptr_to_const2() {
+ const int ci = 10;
+ const int cj = 20;
+ stm::tx::pointer<const int> pc = &ci;
+ stm::tx::pointer<const int> pc2 = &cj;
+ stm::tx::pointer<const int> const cpc = pc;
+ //cpc=pc2; // this must not compile
+ stm::tx::pointer<stm::tx::pointer<const int> > ppc;
+ atomic(_) {
+ pc=pc2;
+ } end_atom
+ atomic(_) {
+ BOOST_STM_TX_RETURN(_, (pc==&cj)&&(*pc==20)&&(*cpc==10));
+ } end_atom
+ return false;
+}
+
+
+bool test_ptr_to_tx() {
+ stm::tx::int_t i;
+ stm::tx::pointer<stm::tx::int_t > p;
+ stm::tx::pointer<stm::tx::int_t > const cp = &i;
+ atomic(_) {
+ i=5;
+ p=&i;
+ } end_atom
+ atomic(_) {
+ BOOST_STM_TX_RETURN(_, (i==5)&&(p==&i));
+ } end_atom
+ return false;
+}
+
+bool test_ptr_to_tx_assignment() {
+ A a;
+ B b;
+ atomic(_) {
+ b.a_ptr=&a;
+ b.a_ptr->i =1;
+ } end_atom
+ atomic(_) {
+ BOOST_STM_TX_RETURN(_, (b.a_ptr->i==1)&&(*b.a_ptr->ptr==1));
+ } end_atom
+ return false;
+}
+
+bool test_array() {
+ {
+ int v[2];
+ int * p;
+ p = &v[0];
+ *p=1;
+ p = v;
+ ++p;
+ *p=2;
+ }
+ stm::tx::int_t v[2];
+ stm::tx::pointer<stm::tx::int_t > p;
+ atomic(_) {
+ p = &v[0];
+ *p=1;
+ p = v;
+ ++p;
+ *p=2;
+ } end_atom
+ return (v[0]==1) && (v[1]==2);
+}
+
+bool test_array_ptr() {
+ {
+ int * v= new int[2];
+ int * p;
+ p = &v[0];
+ p = v;
+ ++p;
+ }
+ stm::tx::pointer<stm::tx::int_t > v;
+ atomic(_) {
+ v= BOOST_STM_TX_NEW_ARRAY(_,2, stm::tx::int_t);
+ //_.throw_if_forced_to_abort_on_new();
+ //v= _.as_new_array(new stm::tx::int_t[2], 2);
+
+
+ stm::tx::pointer<stm::tx::int_t > p;
+ p = &v[0];
+ p = v;
+ //++p;
+ } end_atom
+
+ #if 0
+ {
+ stm::tx::pointer<stm::tx::int_t > v= BOOST_STM_NEW_ARRAY(2, stm::tx::int_t);
+
+ stm::tx::pointer<stm::tx::int_t > p;
+ p = &v[0];
+ p = v;
+ ++p;
+ }
+ #endif
+ bool res=true;
+ BOOST_STM_RETURN(res);
+ return false;
+}
+
+
+int test_all() {
+
+ //thread th1(inc);
+ //thread th2(decr);
+ //thread th3(inc1);
+ //thread th4(inc);
+
+ //th1.join();
+ //th2.join();
+ //th3.join();
+ //th4.join();
+
+ int fails=0;
+ //fails += !test_ptr_to_tx_const();
+ //fails += !test_ptr_to_tx();
+ //fails += !test_ptr_to_const();
+ //fails += !test_ptr_to_tx_assignment();
+ //fails += !test_array();
+ fails += !test_array_ptr();
+ return fails;
+}
+
+int main() {
+ stm::transaction::enable_dynamic_priority_assignment();
+ stm::transaction::do_deferred_updating();
+ stm::transaction::initialize();
+ stm::thread_initializer thi;
+ return test_all();
+}

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-10-22 16:34:23 EDT (Thu, 22 Oct 2009)
@@ -187,6 +187,7 @@
 
             [ run ../example/counter.cpp ]
             [ run ../example/numeric.cpp ]
+ [ run ../example/tx/pointer.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