$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r53499 - sandbox/stm/libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-05-31 09:35:52
Author: viboes
Date: 2009-05-31 09:35:51 EDT (Sun, 31 May 2009)
New Revision: 53499
URL: http://svn.boost.org/trac/boost/changeset/53499
Log:
TBoost.Stm linkedlist implementation using as_new
Text files modified: 
   sandbox/stm/libs/stm/test/testLinkedList.cpp |    15 +++                                     
   sandbox/stm/libs/stm/test/testLinkedList.h   |   157 ++++++++++++++++++++++++++++++++++++--- 
   2 files changed, 156 insertions(+), 16 deletions(-)
Modified: sandbox/stm/libs/stm/test/testLinkedList.cpp
==============================================================================
--- sandbox/stm/libs/stm/test/testLinkedList.cpp	(original)
+++ sandbox/stm/libs/stm/test/testLinkedList.cpp	2009-05-31 09:35:51 EDT (Sun, 31 May 2009)
@@ -44,7 +44,9 @@
 ///////////////////////////////////////////////////////////////////////////////
 static void* TestLinkedListInserts(void *threadId)
 {
-   list_node<list_node_type> node;
+#ifdef BOOST_STM_LL_USES_NODE
+    list_node<list_node_type> node;
+#endif    
    transaction::initialize_thread();
 
    int start = *(int*)threadId;
@@ -65,8 +67,13 @@
    int i;
    for (i = startingValue; i < endingValue; ++i)
    {
+#ifdef BOOST_STM_LL_USES_NODE
+      //list_node<list_node_type> node(i);
       node.value() = i;
       llist->insert(node);
+#else       
+      llist->insert(i);
+#endif       
    }
 
    if (kDoMove)
@@ -78,6 +85,7 @@
          node1.value() = j;
          //node2.value() = -j;
          llist->move(node1, node2);
+          
       }
 
    }
@@ -100,8 +108,13 @@
    {
       for (i = startingValue; i < endingValue; ++i)
       {
+         //list_node<list_node_type> node(i);
+#ifdef BOOST_STM_LL_USES_NODE
          node.value() = i;
          llist->remove(node);
+#else
+         llist->remove(i);
+#endif          
       }
    }
 
Modified: sandbox/stm/libs/stm/test/testLinkedList.h
==============================================================================
--- sandbox/stm/libs/stm/test/testLinkedList.h	(original)
+++ sandbox/stm/libs/stm/test/testLinkedList.h	2009-05-31 09:35:51 EDT (Sun, 31 May 2009)
@@ -1,10 +1,10 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Justin E. Gottchlich 2009. 
-// (C) Copyright Vicente J. Botet Escriba 2009. 
+// (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 
+// 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.
@@ -26,8 +26,10 @@
 {
 public:
 
-   list_node() : value_(0), next_(0) {}
-   explicit list_node(int const &rhs) : value_(rhs), next_(NULL) {}
+   list_node() : value_(0), next_(0) {
+       }
+   explicit list_node(T const &rhs) : value_(rhs), next_(NULL) {
+       }
 
    // zero initialization for native types
    void clear() { value_ = T(); next_ = NULL; }
@@ -57,7 +59,7 @@
       return *this;
    }
 
-   list_node(list_node &&rhs) : next_(rhs.next_), value_(boost::stm::draco_move(rhs.value_)) 
+   list_node(list_node &&rhs) : next_(rhs.next_), value_(boost::stm::draco_move(rhs.value_))
    { rhs.next_ = 0; }
 
    list_node& operator=(list_node&& rhs)
@@ -68,11 +70,10 @@
    }
 #endif
 
-
 private:
 
-   list_node *next_;
    T value_;
+   list_node *next_;
 };
 
 ////////////////////////////////////////////////////////////////////////////
@@ -91,7 +92,7 @@
       bool succeeded1 = true, succeeded2 = true;
       transaction_state state = e_no_state;
 
-      do 
+      do
       {
          try
          {
@@ -102,7 +103,7 @@
          }
          catch (aborted_transaction_exception&) {}
 
-         if (!succeeded1 || !succeeded2) 
+         if (!succeeded1 || !succeeded2)
          {
             return false; // auto abort of t
          }
@@ -123,9 +124,26 @@
          catch (aborted_transaction_exception&) {}
       }
    }
+#ifdef BOOST_STM_USES_PARAM
+   bool insert(T val)
+#else
+   bool insert(const T& val)
+#endif
+   {
+      using namespace boost::stm;
 
+      for (transaction t; ;t.restart())
+      {
+         try { return internal_insert(val, t); }
+         catch (aborted_transaction_exception&) {}
+      }
+   }
    ////////////////////////////////////////////////////////////////////////////
+#ifdef BOOST_STM_USES_PARAM
+   bool lookup(T val)
+#else
    bool lookup(T const &val)
+#endif
    {
       using namespace boost::stm;
 
@@ -148,6 +166,21 @@
       }
    }
 
+#ifdef BOOST_STM_USES_PARAM
+   bool remove(T val)
+#else
+   bool remove(T const &val)
+#endif
+   {
+      using namespace boost::stm;
+
+      for (transaction t; ; t.restart())
+      {
+         try { return internal_remove(val, t); }
+         catch (aborted_transaction_exception&) {}
+      }
+   }
+
    ////////////////////////////////////////////////////////////////////////////
    void outputList(std::ofstream &o)
    {
@@ -215,7 +248,7 @@
          list_node<T> const *cur = t.read_ptr(headP->next());
          T val = rhs.value();
 
-         while (true) 
+         while (true)
          {
             if (cur->value() == val) return false;
             else if (cur->value() > val || !cur->next()) break;
@@ -255,14 +288,81 @@
       return true;
    }
 
+#ifdef BOOST_STM_USES_PARAM
+   bool internal_insert(T val, boost::stm::transaction &t)
+#else
+   bool internal_insert(const T& val, boost::stm::transaction &t)
+#endif
+   {
+      //T val = valr;
+      list_node<T> const *headP = &t.read(head_);
+
+      if (NULL != headP->next())
+      {
+         list_node<T> const *prev = headP;
+         list_node<T> const *cur = t.read_ptr(headP->next());
+
+         while (true)
+         {
+            if (cur->value() == val) return false;
+            else if (cur->value() > val || !cur->next()) break;
+
+            prev = cur;
+
+            list_node<T> const *curNext = t.read_ptr(cur->next());
+
+            if (NULL == curNext) break;
+
+            cur = curNext;
+         }
+#ifndef BOOST_STM_USES_AS_NEW
+         list_node<T> node(val);
+         list_node<T> *newNode = t.new_memory_copy(node);
+#else
+         t.throw_if_forced_to_abort_on_new();
+         list_node<T> *newNode = t.as_new(new list_node<T>(val));
+#endif
+         //--------------------------------------------------------------------
+         // if cur->next() is null it means our newNode value is greater than
+         // cur, so insert ourselves after cur.
+         //--------------------------------------------------------------------
+         if (val > cur->value()) t.write_ptr((list_node<T>*)cur)->next_for_new_mem(newNode, t);
+         //--------------------------------------------------------------------
+         // otherwise, we are smaller than cur, so insert between prev and cur
+         //--------------------------------------------------------------------
+         else
+         {
+            newNode->next(cur, t);
+            t.write_ptr((list_node<T>*)prev)->next_for_new_mem(newNode, t);
+         }
+      }
+      else
+      {
+#ifndef BOOST_STM_USES_AS_NEW
+         list_node<T> node(val);
+         list_node<T> *newNode = t.new_memory_copy(node);
+#else
+         t.throw_if_forced_to_abort_on_new();
+         list_node<T> *newNode = t.as_new(new list_node<T>(val));
+#endif
+         t.write(head_).next_for_new_mem(newNode, t);
+      }
+
+      t.end();
+      return true;
+   }
    //--------------------------------------------------------------------------
    // find the location to insert the node. if the value already exists, bail
    //--------------------------------------------------------------------------
+#ifdef BOOST_STM_USES_PARAM
+   bool internal_lookup(T val, boost::stm::transaction &t)
+#else
    bool internal_lookup(T const &val, boost::stm::transaction &t)
+#endif
    {
       list_node<T> const *cur = &t.read(head_);
 
-      for (; true ; cur = t.read(*cur).next() ) 
+      for (; true ; cur = t.read(*cur).next() )
       {
          list_node<T> const *trueCur = &t.read(*cur);
 
@@ -303,6 +403,33 @@
       return false;
    }
 
+#ifdef BOOST_STM_USES_PARAM
+   bool internal_remove(T value, boost::stm::transaction &t)
+#else
+   bool internal_remove(T const &value, boost::stm::transaction &t)
+#endif
+   {
+      list_node<T> const *prev = &t.read(head_);
+
+      for (list_node<T> const *cur = prev; cur != NULL; prev = cur)
+      {
+         cur = t.read(*cur).next();
+
+         if (NULL == cur) break;
+
+         if (cur->value() == value)
+         {
+            list_node<T> const *curNext = t.read(*cur).next();
+
+            t.delete_memory(*cur);
+            t.write(*(list_node<T>*)prev).next(curNext, t);
+            t.end();
+            return true;
+         }
+      }
+
+      return false;
+   }
    //--------------------------------------------------------------------------
    // find the location to insert the node. if the value already exists, bail
    //--------------------------------------------------------------------------
@@ -319,7 +446,7 @@
          list_node<T> const *cur = t.read_ptr(headP->next());
          T val = rhs.value();
 
-         while (true) 
+         while (true)
          {
             if (cur->value() == val) return false;
             else if (cur->value() > val || !cur->next()) break;
@@ -367,7 +494,7 @@
 
       list_node<T> const *prev = &t.read(head_);
 
-      for (list_node<T> const *cur = prev; cur != NULL; 
+      for (list_node<T> const *cur = prev; cur != NULL;
            prev = cur, cur = t.read(*cur).next())
       {
          if (cur->value() == rhs.value())