Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56656 - in sandbox/stm/branches/vbe/boost: . stm stm/contention_managers stm/detail stm/non_tx stm/non_tx/detail stm/tx
From: vicente.botet_at_[hidden]
Date: 2009-10-08 15:31:50


Author: viboes
Date: 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
New Revision: 56656
URL: http://svn.boost.org/trac/boost/changeset/56656

Log:
TBoost.Stm vbe
* file reorganization
* adding tx/numerics.hpp, tx/pointer.hpp, non_tx/numerics.hpp, non_tx/pointer.hpp

Added:
   sandbox/stm/branches/vbe/boost/stm/contention_managers/
   sandbox/stm/branches/vbe/boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm_i.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/non_tx/
   sandbox/stm/branches/vbe/boost/stm/non_tx/detail/
   sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/non_tx/integers.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx/
   sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp (contents, props changed)
Removed:
   sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp
Text files modified:
   sandbox/stm/branches/vbe/boost/stm.hpp | 7
   sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp | 41 ++----
   sandbox/stm/branches/vbe/boost/stm/detail/config.hpp | 2
   sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp | 24 ++--
   sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp | 10
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp | 24 ++--
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp | 24 ++--
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp | 24 ++--
   sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp | 16 +-
   sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 232 +++++++++++++++------------------------
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 21 --
   sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp | 26 +--
   12 files changed, 185 insertions(+), 266 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-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -44,7 +44,8 @@
 #include <boost/stm/datatypes.hpp>
 #include <boost/stm/exceptions.hpp>
 #include <boost/stm/move.hpp>
-#include <boost/stm/non_tx_smart_ptr.hpp>
+#include <boost/stm/non_tx/numeric.hpp>
+#include <boost/stm/non_tx/smart_ptr.hpp>
 #include <boost/stm/synchro.hpp>
 #include <boost/stm/transaction.hpp>
 #include <boost/stm/transaction_bookkeeping.hpp>
@@ -52,7 +53,9 @@
 #include <boost/stm/transaction_object_ptr.hpp>
 #include <boost/stm/transactional_object.hpp>
 #include <boost/stm/tx_ptr.hpp>
-#include <boost/stm/tx_smart_ptr.hpp>
+#include <boost/stm/tx/numeric.hpp>
+#include <boost/stm/tx/pointer.hpp>
+#include <boost/stm/tx/smart_ptr.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 #endif // TRANSACTION_H

Added: sandbox/stm/branches/vbe/boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,78 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_EXCEPT_AND_BACK_OFF_ABORT_NOTICE_CM_H
+#define BOOST_STM_EXCEPT_AND_BACK_OFF_ABORT_NOTICE_CM_H
+
+namespace boost { namespace stm {
+ class transaction;
+
+////////////////////////////////////////////////////////////////////////////
+//
+// this class backs off (and sleeps) when aborting. this is commonly known
+// as "exponential backoff" for locking mechanisms.
+//
+////////////////////////////////////////////////////////////////////////////
+class except_and_back_off_on_abort_notice_cm //: public base_contention_manager
+{
+public:
+
+#if 0
+ static void init(int const initialSleepTime, int const sleepIncrease,
+ int const maxIncreases)
+ {
+ sleepTime_=initialSleepTime;
+ kSleepFactorIncrease_=sleepIncrease;
+ kMaxIncreases_=maxIncreases;
+ initialSleepTime_=initialSleepTime;
+ kMaxSleepTime_ = kSleepFactorIncrease_ * sleepTime_ * kMaxIncreases_;
+ }
+#endif
+ ////////////////////////////////////////////////////////////////////////////
+ static void abort_on_write(transaction &t,
+ base_transaction_object const &in);
+ static void abort_on_read(transaction const &t,
+ base_transaction_object const &in);
+ static void abort_on_delete(transaction const &t,
+ base_transaction_object const &in);
+ static void abort_on_new(transaction const &t);
+
+ ////////////////////////////////////////////////////////////////////////////
+ static void perform_isolated_tx_wait_priority_promotion(transaction &lhs);
+
+ ////////////////////////////////////////////////////////////////////////////
+ static void perform_irrevocable_tx_wait_priority_promotion(transaction &lhs);
+ inline static int lock_sleep_time() { return 10; }
+
+ //--------------------------------------------------------------------------
+ // this code is only ever called if "validation" is on not "invalidation"
+ // so don't worry about this code EVER stopping invalidation from committing
+ //--------------------------------------------------------------------------
+ static bool abort_before_commit(transaction const &t);
+
+ static bool permission_to_abort(transaction const &lhs, transaction const &rhs);
+
+ static bool allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
+ bool txTryingToAbortIsIrrevocable, transaction const &rhs);
+
+//private:
+
+ static int sleepTime_;
+ static int const kSleepFactorIncrease_;
+ static int kMaxSleepTime_;
+ static int const kMaxIncreases_;
+ static int const initialSleepTime_;
+};
+
+}}
+#endif

Added: sandbox/stm/branches/vbe/boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm_i.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm_i.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,75 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_EXCEPT_AND_BACK_OFF_ABORT_NOTICE_CM_H
+#define BOOST_STM_EXCEPT_AND_BACK_OFF_ABORT_NOTICE_CM_H
+
+namespace boost { namespace stm {
+ class transaction;
+
+////////////////////////////////////////////////////////////////////////////
+//
+// this class backs off (and sleeps) when aborting. this is commonly known
+// as "exponential backoff" for locking mechanisms.
+//
+////////////////////////////////////////////////////////////////////////////
+class except_and_back_off_on_abort_notice_cm //: public base_contention_manager
+{
+public:
+
+ except_and_back_off_on_abort_notice_cm(int const initialSleepTime, int const sleepIncrease,
+ int const maxIncreases)
+ : sleepTime_(initialSleepTime), kSleepFactorIncrease_(sleepIncrease),
+ kMaxIncreases_(maxIncreases), initialSleepTime_(initialSleepTime)
+ {
+ kMaxSleepTime_ = kSleepFactorIncrease_ * sleepTime_ * kMaxIncreases_;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ void abort_on_write(transaction &t,
+ base_transaction_object const &in);
+ void abort_on_read(transaction const &t,
+ base_transaction_object const &in);
+ void abort_on_delete(transaction const &t,
+ base_transaction_object const &in);
+ void abort_on_new(transaction const &t);
+
+ ////////////////////////////////////////////////////////////////////////////
+ void perform_isolated_tx_wait_priority_promotion(transaction &lhs);
+
+ ////////////////////////////////////////////////////////////////////////////
+ void perform_irrevocable_tx_wait_priority_promotion(transaction &lhs);
+ inline int lock_sleep_time() { return 10; }
+
+ //--------------------------------------------------------------------------
+ // this code is only ever called if "validation" is on not "invalidation"
+ // so don't worry about this code EVER stopping invalidation from committing
+ //--------------------------------------------------------------------------
+ bool abort_before_commit(transaction const &t);
+
+ bool permission_to_abort(transaction const &lhs, transaction const &rhs);
+
+ bool allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
+ bool txTryingToAbortIsIrrevocable, transaction const &rhs);
+
+private:
+
+ int sleepTime_;
+ int const kSleepFactorIncrease_;
+ int kMaxSleepTime_;
+ int const kMaxIncreases_;
+ int const initialSleepTime_;
+};
+
+}}
+#endif

Modified: sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -24,11 +24,11 @@
 
 #ifdef PERFORMING_LATM
 #include <boost/stm/transaction.hpp>
-#define LOCK(a) boost::stm::transaction::lock_(a)
-#define UNLOCK(a) boost::stm::transaction::unlock_(a)
+#define BOOST_STM_LOCK(a) boost::stm::transaction::lock_(a)
+#define BOOST_STM_UNLOCK(a) boost::stm::transaction::unlock_(a)
 #else
-#define LOCK(a) boost::stm::lock(a)
-#define UNLOCK(a) boost::stm::unlock(a)
+#define BOOST_STM_LOCK(a) boost::stm::lock(a)
+#define BOOST_STM_UNLOCK(a) boost::stm::unlock(a)
 #endif
 
 //---------------------------------------------------------------------------
@@ -59,23 +59,23 @@
    typedef std::multimap<size_t const, Mutex*> ThreadedLockContainer;
    typedef ThreadedLockContainer::iterator ThreadedLockIter;
 
- auto_lock(Mutex &mutex) : donePostStep_(false), hasLock_(false), lock_(0)
+ auto_lock(Mutex &mutex) : hasLock_(false), lock_(0)
    {
       do_auto_lock(&mutex);
    }
 
- auto_lock(Mutex *mutex) : donePostStep_(false), hasLock_(false), lock_(0)
+ auto_lock(Mutex *mutex) : hasLock_(false), lock_(0)
    {
       do_auto_lock(mutex);
    }
 
 
- auto_lock(size_t timeOut, Mutex &mutex) : donePostStep_(false), hasLock_(false), lock_(0)
+ auto_lock(size_t timeOut, Mutex &mutex) : hasLock_(false), lock_(0)
    {
       do_timed_auto_lock(timeOut, &mutex);
    }
 
- auto_lock(size_t timeOut, Mutex *mutex) : donePostStep_(false), hasLock_(false), lock_(0)
+ auto_lock(size_t timeOut, Mutex *mutex) : hasLock_(false), lock_(0)
    {
       do_timed_auto_lock(timeOut, mutex);
    }
@@ -92,17 +92,6 @@
       return VC6_fix;
    }
 
- void post_step()
- {
- release_lock();
- donePostStep_ = true;
- }
-
- bool done_post_step() const
- {
- return donePostStep_;
- }
-
 private:
 
    void do_timed_auto_lock(size_t timeOut, Mutex *mutex)
@@ -138,7 +127,7 @@
       lock_ = mutex;
       if (thread_has_lock(mutex)) return;
 
- LOCK(mutex);
+ BOOST_STM_LOCK(mutex);
       hasLock_ = true;
 
       insert_into_threaded_lock_map(mutex);
@@ -149,7 +138,7 @@
       if (hasLock_)
       {
          hasLock_ = false;
- UNLOCK(lock_);
+ BOOST_STM_UNLOCK(lock_);
          remove_thread_has_lock(lock_);
       }
    }
@@ -208,15 +197,17 @@
    //auto_lock(auto_lock const &);
    //auto_lock& operator=(auto_lock const &);
 
- bool donePostStep_;
    bool hasLock_;
    Mutex *lock_;
 };
 
-#define use_lock(L) if (0 != rand()+1) for (boost::stm::auto_lock ___l(L); !___l.done_post_step(); ___l.post_step())
-#define use_timed_lock(T, L) if (0 != rand()+1) for (boost::stm::auto_lock ___l(T, L); !___l.done_post_step(); ___l.post_step())
+#define use_lock(L) if (bool __end=false); else \
+ for (boost::stm::auto_lock ___l(L); !__end; __end=true)
+#define use_timed_lock(T, L) if (bool __end=false); else \
+ for (boost::stm::auto_lock ___l(T, L); !__end; __end=false)
+#define try_timed_lock(T, L) if (bool __end=false); else \
+ try { for (boost::stm::auto_lock ___l(T, L); !__end; __end=false)
 
-#define try_timed_lock(T, L) try { for (boost::stm::auto_lock ___l(T, L); !___l.done_post_step(); ___l.post_step())
 #define catch_lock_timeout(E) } catch (std::timer_lock_exception &E)
 #define lock_timeout } catch (std::timer_lock_exception &E)
 

Modified: sandbox/stm/branches/vbe/boost/stm/detail/config.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/config.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/config.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -47,7 +47,7 @@
 // BOOST_STM_CM_STATIC_CONF when you want a staticacly configured CM
 // BOOST_STM_CM_DYNAMIC_CONF when you want a polymorphic CM configured at run time
 
-//#define BOOST_STM_CM_STATIC_CONF 1
+#define BOOST_STM_CM_STATIC_CONF 1
 //#define BOOST_STM_CM_DYNAMIC_CONF 1
 
 // Define only one of

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -58,8 +58,8 @@
    //--------------------------------------------------------------------------
    if (latmLockedLocks_.empty())
    {
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
       std::list<transaction*> txList;
       for (InflightTxes::iterator i = transactionsInFlight_.begin();
@@ -74,8 +74,8 @@
          }
          else
          {
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
             return false;
          }
       }
@@ -85,14 +85,14 @@
          (*it)->force_to_abort();
       }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
    }
 
    try { latmLockedLocks_.insert(mutex); }
    catch (...)
    {
- unlock_inflight_access();
+ unlock(inflight_lock());
       throw;
    }
 
@@ -113,9 +113,9 @@
       t->add_to_obtained_locks(mutex);
 
       t->commit_deferred_update_tx();
- lock_latm_access();
+ lock(latm_lock());
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
 
       // TBR if (hadLock) return 0;
       // TBR else return lock(mutex);
@@ -177,9 +177,9 @@
       t->add_to_obtained_locks(mutex);
 
       t->commit_deferred_update_tx();
- lock_latm_access();
+ lock(latm_lock());
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
 
       if (hadLock) return 0;
       else return trylock(mutex);
@@ -240,7 +240,7 @@
 
    latmLockedLocks_.erase(mutex);
 
- if (latmLockedLocks_.empty()) unlock_inflight_access();
+ if (latmLockedLocks_.empty()) unlock(inflight_lock());
 
    latmLockedLocksOfThreadMap_.erase(mutex);
    unlock(&latmMutex_);

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -107,9 +107,9 @@
       bool hadLock = t->is_currently_locked_lock(mutex);
       t->add_to_currently_locked_locks(mutex);
 
- lock_latm_access();
+ lock(latm_lock());
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
 
       // TBR if (hadLock) return 0;
       // TBR else return lock(mutex);
@@ -174,9 +174,9 @@
       bool hadLock = t->is_currently_locked_lock(mutex);
       t->add_to_currently_locked_locks(mutex);
 
- lock_latm_access();
+ lock(latm_lock());
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
 
       if (hadLock) return 0;
       else return trylock(mutex);
@@ -244,7 +244,7 @@
    {
       latmLockedLocks_.erase(mutex);
 
- if (latmLockedLocks_.empty()) unlock_inflight_access();
+ if (latmLockedLocks_.empty()) unlock(inflight_lock());
    }
 
    latmLockedLocksOfThreadMap_.erase(mutex);

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -58,8 +58,8 @@
    //--------------------------------------------------------------------------
    if (latmLockedLocks_.empty())
    {
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
       std::list<transaction*> txList;
       for (InflightTxes::iterator i = transactionsInFlight_.begin();
@@ -74,8 +74,8 @@
          }
          else
          {
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
             return false;
          }
       }
@@ -90,8 +90,8 @@
       //-----------------------------------------------------------------------
       thread_conflicting_mutexes_set_all(true);
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
       //-----------------------------------------------------------------------
       // now we must stall until all in-flight transactions are gone, otherwise
@@ -103,8 +103,8 @@
    try { latmLockedLocks_.insert(mutex); }
    catch (...)
    {
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       throw;
    }
 
@@ -127,7 +127,7 @@
       // this method locks LATM and keeps it locked upon returning if param true
       wait_until_all_locks_are_released(true);
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
 
       if (hadLock) return 0;
       else lock(mutex);
@@ -189,7 +189,7 @@
       // this method locks LATM and keeps it locked upon returning if param true
       wait_until_all_locks_are_released(true);
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
 
       if (hadLock) return 0;
       else return trylock(mutex);
@@ -252,11 +252,11 @@
 
    if (latmLockedLocks_.empty())
    {
- lock_general_access();
+ lock(general_lock());
 
       thread_conflicting_mutexes_set_all(false);
 
- unlock_general_access();
+ unlock(general_lock());
    }
 
    latmLockedLocksOfThreadMap_.erase(mutex);

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -66,8 +66,8 @@
       //--------------------------------------------------------------------------
       if (latmLockedLocks_.empty())
       {
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
          std::list<transaction*> txList;
          for (InflightTxes::iterator i = transactionsInFlight_.begin();
@@ -82,8 +82,8 @@
             }
             else
             {
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
                return false;
             }
          }
@@ -98,8 +98,8 @@
          //-----------------------------------------------------------------------
           thread_conflicting_mutexes_set_all(true);
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
          //-----------------------------------------------------------------------
          // now we must stall until all in-flight transactions are gone, otherwise
@@ -123,9 +123,9 @@
    {
       transaction::must_be_in_tm_conflicting_lock_set(mutex);
       t->make_isolated();
- lock_latm_access();
+ lock(latm_lock());
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
       lock(mutex);
       return 0;
    }
@@ -181,9 +181,9 @@
    {
       transaction::must_be_in_tm_conflicting_lock_set(mutex);
       t->make_isolated();
- lock_latm_access();
+ lock(latm_lock());
       latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- unlock_latm_access();
+ unlock(latm_lock());
       return trylock(mutex);
    }
 
@@ -251,11 +251,11 @@
 
       if (latmLockedLocks_.empty())
       {
- lock_general_access();
+ lock(general_lock());
 
           thread_conflicting_mutexes_set_all(false);
 
- unlock_general_access();
+ unlock(general_lock());
       }
    }
 

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -51,8 +51,8 @@
    // set. do not keep in-flight transactions blocked once the transactions have
    // been processed.
    //--------------------------------------------------------------------------
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
    std::list<transaction *> txList;
    std::set<size_t> txThreadId;
@@ -75,8 +75,8 @@
          }
          else
          {
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
             return false;
          }
       }
@@ -112,8 +112,8 @@
          throw;
       }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
       //-----------------------------------------------------------------------
       // now wait until all the txs which conflict with this mutex are no longer
@@ -123,8 +123,8 @@
       {
          bool conflictingTxInFlight = false;
 
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
          for (InflightTxes::iterator i = transactionsInFlight_.begin();
             i != transactionsInFlight_.end(); ++i)
@@ -137,16 +137,16 @@
             }
          }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
          if (conflictingTxInFlight) SLEEP(10);
          else return true;
       }
    }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
    return true;
 }

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -50,13 +50,13 @@
 {
    while (true)
    {
- lock_latm_access();
+ lock(latm_lock());
       if (latmLockedLocks_.empty()) break;
- unlock_latm_access();
+ unlock(latm_lock());
       SLEEP(10);
    }
 
- if (!keepLatmLocked) unlock_latm_access();
+ if (!keepLatmLocked) unlock(latm_lock());
 }
 
 //----------------------------------------------------------------------------
@@ -342,9 +342,9 @@
 //----------------------------------------------------------------------------
 inline void boost::stm::transaction::clear_tx_conflicting_locks()
 {
- lock_general_access();
+ lock(general_lock());
    get_tx_conflicting_locks().clear();
- unlock_general_access();
+ unlock(general_lock());
 }
 
 //----------------------------------------------------------------------------
@@ -509,7 +509,7 @@
 inline boost::stm::transaction* boost::stm::transaction::get_inflight_tx_of_same_thread
 (bool hasTxInFlightMutex)
 {
- if (!hasTxInFlightMutex) lock_inflight_access();
+ if (!hasTxInFlightMutex) lock(inflight_lock());
 
    for (InflightTxes::iterator i = transactionsInFlight_.begin();
       i != transactionsInFlight_.end(); ++i)
@@ -523,12 +523,12 @@
       //--------------------------------------------------------------------
       if (t->thread_id() == THREAD_ID)
       {
- if (!hasTxInFlightMutex) unlock_inflight_access();
+ if (!hasTxInFlightMutex) unlock(inflight_lock());
          return t;
       }
    }
 
- if (!hasTxInFlightMutex) unlock_inflight_access();
+ if (!hasTxInFlightMutex) unlock(inflight_lock());
    return 0;
 }
 }}

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-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -125,16 +125,16 @@
    //-----------------------------------------------------------------------
    while (true)
    {
- lock_inflight_access();
+ lock(inflight_lock());
 
       if (!irrevocableTxInFlight())
       {
          tx_type(eIrrevocableTx);
- unlock_inflight_access();
+ unlock(inflight_lock());
          return;
       }
 
- unlock_inflight_access();
+ unlock(inflight_lock());
       SLEEP(10);
       cm_perform_irrevocable_tx_wait_priority_promotion(*this);
    }
@@ -160,20 +160,20 @@
          ("aborting tx in make_isolated");
       }
 
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
       if (!irrevocableTxInFlight() && canAbortAllInFlightTxs())
       {
          tx_type(eIrrevocableAndIsolatedTx);
          abortAllInFlightTxs();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
          return;
       }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       //SLEEP(10);
       cm_perform_isolated_tx_wait_priority_promotion(*this);
    }
@@ -238,12 +238,12 @@
    //--------------------------------------------------------------------------
    if (is_only_reading())
    {
- unlock_general_access();
+ unlock(general_lock());
       unlock_tx();
    }
    else
    {
- lock_inflight_access();
+ lock(inflight_lock());
 
       //-----------------------------------------------------------------------
       // commit writes, clear new and deletes
@@ -256,8 +256,8 @@
       deferredCommitTransactionDeletedMemory();
 
       unlock_tx();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
    }
 
    //--------------------------------------------------------------------------
@@ -287,62 +287,6 @@
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
-inline void transaction::lock_latm_access()
-{
- lock(&latmMutex_);
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::unlock_latm_access()
-{
- unlock(&latmMutex_);
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::lock_inflight_access()
-{
- lock(&transactionsInFlightMutex_);
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::unlock_inflight_access()
-{
- unlock(&transactionsInFlightMutex_);
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::lock_general_access()
-{
- lock(&transactionMutex_);
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::unlock_general_access()
-{
- unlock(&transactionMutex_);
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::lockThreadMutex(size_t threadId)
-{
- lock(mutex(threadId));
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
-inline void transaction::unlockThreadMutex(size_t threadId)
-{
- unlock(mutex(threadId));
-}
-
-//--------------------------------------------------------------------------
-//--------------------------------------------------------------------------
 inline void transaction::lock_all_mutexes_but_this(size_t threadId)
 {
 #ifdef BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP
@@ -632,12 +576,12 @@
    //-----------------------------------------------------------------------
 #if PERFORMING_COMPOSITION
 #ifdef USING_SHARED_FORCED_TO_ABORT
- lock_inflight_access();
+ lock(inflight_lock());
    if (!otherInFlightTransactionsOfSameThreadNotIncludingThis(this))
    {
       unforce_to_abort();
    }
- unlock_inflight_access();
+ unlock(inflight_lock());
 #else
    unforce_to_abort();
 #endif
@@ -707,23 +651,23 @@
 #if PERFORMING_LATM
    while (true)
    {
- lock_inflight_access();
+ lock(inflight_lock());
 
       if (can_go_inflight() && !isolatedTxInFlight())
       {
          transactionsInFlight_.insert(this);
          state_ = e_in_flight;
- unlock_inflight_access();
+ unlock(inflight_lock());
          break;
       }
 
- unlock_inflight_access();
+ unlock(inflight_lock());
       SLEEP(10);
    }
 #else
- lock_inflight_access();
+ lock(inflight_lock());
    transactionsInFlight_.insert(this);
- unlock_inflight_access();
+ unlock(inflight_lock());
    state_ = e_in_flight;
 #endif
 }
@@ -796,11 +740,11 @@
    {
       bool wasWriting = isWriting() ? true : false;
 
- if (wasWriting) lock_general_access();
+ if (wasWriting) lock(general_lock());
       lock_tx();
       direct_abort();
       unlock_tx();
- if (wasWriting) unlock_general_access();
+ if (wasWriting) unlock(general_lock());
    }
    else
    {
@@ -826,7 +770,7 @@
       ("aborting committing transaction due to contention manager priority inversion");
    }
 
- lock_general_access();
+ lock(general_lock());
    lock_tx();
 
    //--------------------------------------------------------------------------
@@ -843,28 +787,28 @@
       // so unlock it so we can reduce contention
       //-----------------------------------------------------------------------
       bool wasWriting = isWriting() ? true : false;
- if (!wasWriting) unlock_general_access();
+ if (!wasWriting) unlock(general_lock());
       direct_abort();
       unlock_tx();
       //-----------------------------------------------------------------------
       // if this tx was writing, unlock the transaction mutex now
       //-----------------------------------------------------------------------
- if (wasWriting) unlock_general_access();
+ if (wasWriting) unlock(general_lock());
       throw aborted_transaction_exception
       ("aborting committing transaction due to contention manager priority inversion");
    }
 
    lock_all_mutexes_but_this(threadId_);
 
- lock_inflight_access();
+ lock(inflight_lock());
    transactionsInFlight_.erase(this);
 
    if (other_in_flight_same_thread_transactions())
    {
       state_ = e_hand_off;
       unlock_all_mutexes();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       bookkeeping_.inc_handoffs();
    }
    else
@@ -875,8 +819,8 @@
       if (e_committed == state_)
       {
          unlock_all_mutexes();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       }
    }
 }
@@ -906,20 +850,20 @@
    //--------------------------------------------------------------------------
    if (is_only_reading())
    {
- lock_inflight_access();
+ lock(inflight_lock());
       transactionsInFlight_.erase(this);
 
 #if PERFORMING_COMPOSITION
       if (other_in_flight_same_thread_transactions())
       {
- unlock_inflight_access();
+ unlock(inflight_lock());
          state_ = e_hand_off;
          bookkeeping_.inc_handoffs();
       }
       else
 #endif
       {
- unlock_inflight_access();
+ unlock(inflight_lock());
          tx_type(eNormalTx);
 #if PERFORMING_LATM
          get_tx_conflicting_locks().clear();
@@ -943,7 +887,7 @@
    //--------------------------------------------------------------------------
    if (forced_to_abort())
    {
- unlock_general_access();
+ unlock(general_lock());
       deferred_abort(true);
       throw aborted_transaction_exception
       ("aborting committing transaction due to contention manager priority inversion");
@@ -964,7 +908,7 @@
       // transactionsInFlightMutex
       //-----------------------------------------------------------------------
       lock_all_mutexes();
- lock_inflight_access();
+ lock(inflight_lock());
 
 #if PERFORMING_COMPOSITION
       if (other_in_flight_same_thread_transactions())
@@ -972,8 +916,8 @@
          transactionsInFlight_.erase(this);
          state_ = e_hand_off;
          unlock_all_mutexes();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
          bookkeeping_.inc_handoffs();
       }
       else
@@ -993,7 +937,7 @@
 //-----------------------------------------------------------------------------
 inline void transaction::validating_direct_end_transaction()
 {
- lock_general_access();
+ lock(general_lock());
    lock_tx();
 
    //--------------------------------------------------------------------------
@@ -1004,7 +948,7 @@
       abort();
       //bookkeeping_.inc_abort_perm_denied(threadId_);
       unlock_tx();
- unlock_general_access();
+ unlock(general_lock());
       throw aborted_transaction_exception
       ("aborting commit due to CM priority");
    }
@@ -1023,28 +967,28 @@
       // so unlock it so we can reduce contention
       //-----------------------------------------------------------------------
       bool wasWriting = isWriting() ? true : false;
- if (!wasWriting) unlock_general_access();
+ if (!wasWriting) unlock(general_lock());
       direct_abort();
       unlock_tx();
       //-----------------------------------------------------------------------
       // if this tx was writing, unlock the transaction mutex now
       //-----------------------------------------------------------------------
- if (wasWriting) unlock_general_access();
+ if (wasWriting) unlock(general_lock());
       throw aborted_transaction_exception
       ("aborting committing transaction due to contention manager priority inversion");
    }
 
    lock_all_mutexes_but_this(threadId_);
 
- lock_inflight_access();
+ lock(inflight_lock());
    transactionsInFlight_.erase(this);
 
    if (other_in_flight_same_thread_transactions())
    {
       state_ = e_hand_off;
       unlock_all_mutexes();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       bookkeeping_.inc_handoffs();
    }
    else
@@ -1055,8 +999,8 @@
       if (e_committed == state_)
       {
          unlock_all_mutexes();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       }
    }
 }
@@ -1066,8 +1010,8 @@
 //-----------------------------------------------------------------------------
 inline void transaction::validating_deferred_end_transaction()
 {
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
    lock_tx();
 
    //--------------------------------------------------------------------------
@@ -1076,8 +1020,8 @@
    if (cm_abort_before_commit(*this))
    {
       //bookkeeping_.inc_abort_perm_denied(threadId_);
- unlock_inflight_access();
- unlock_general_access();
+ unlock(inflight_lock());
+ unlock(general_lock());
       deferred_abort();
       unlock_tx();
       throw aborted_transaction_exception
@@ -1085,7 +1029,7 @@
    }
 
    // unlock this - we only needed it to check abort_before_commit()
- unlock_inflight_access();
+ unlock(inflight_lock());
 
    uint32 ms = clock();
 
@@ -1098,7 +1042,7 @@
    //--------------------------------------------------------------------------
    if (forced_to_abort())
    {
- unlock_general_access();
+ unlock(general_lock());
       deferred_abort();
       unlock_tx();
       throw aborted_transaction_exception
@@ -1114,7 +1058,7 @@
       //--------------------------------------------------------------------------
       if (is_only_reading())
       {
- lock_inflight_access();
+ lock(inflight_lock());
          transactionsInFlight_.erase(this);
 
          if (other_in_flight_same_thread_transactions())
@@ -1132,8 +1076,8 @@
             state_ = e_committed;
          }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
          bookkeeping_.inc_commits();
 #ifndef DISABLE_READ_SETS
@@ -1158,15 +1102,15 @@
       //-----------------------------------------------------------------------
       lock_all_mutexes_but_this(threadId_);
 
- lock_inflight_access();
+ lock(inflight_lock());
       transactionsInFlight_.erase(this);
 
       if (other_in_flight_same_thread_transactions())
       {
          state_ = e_hand_off;
          unlock_all_mutexes();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
          bookkeeping_.inc_handoffs();
       }
       else
@@ -1180,8 +1124,8 @@
          if (e_committed == state_)
          {
             unlock_tx();
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
          }
       }
    }
@@ -1300,7 +1244,7 @@
 #endif
       if (!alreadyRemovedFromInFlight)
       {
- lock_inflight_access();
+ lock(inflight_lock());
          // if I'm the last transaction of this thread, reset abort to false
          transactionsInFlight_.erase(this);
       }
@@ -1315,7 +1259,7 @@
 #endif
       if (!alreadyRemovedFromInFlight)
       {
- unlock_inflight_access();
+ unlock(inflight_lock());
       }
    }
    catch (...)
@@ -1350,7 +1294,7 @@
 
    if (alreadyRemovedFromInFlight)
    {
- lock_inflight_access();
+ lock(inflight_lock());
       // if I'm the last transaction of this thread, reset abort to false
       transactionsInFlight_.erase(this);
 
@@ -1363,7 +1307,7 @@
       unforce_to_abort();
 #endif
 
- unlock_inflight_access();
+ unlock(inflight_lock());
    }
    else unforce_to_abort();
 }
@@ -1411,8 +1355,8 @@
    catch (aborted_transaction_exception&)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
       direct_abort();
       unlock_tx();
@@ -1425,8 +1369,8 @@
    catch (...)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
       direct_abort();
       unlock_tx();
@@ -1487,8 +1431,8 @@
             ++stalling_;
             size_t local_clock = global_clock();
 
- unlock_inflight_access();
- unlock_general_access();
+ unlock(inflight_lock());
+ unlock(general_lock());
             unlock_all_mutexes();
 
             for (;;)
@@ -1505,8 +1449,8 @@
                   throw aborted_transaction_exception_no_unlocks();
                }
 
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
                // if our stalling on tx is gone, continue
                if (transactionsInFlight_.end() == transactionsInFlight_.find(stallingOn))
@@ -1518,8 +1462,8 @@
                   break;
                }
 
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
             }
 
             lock_all_mutexes();
@@ -1539,8 +1483,8 @@
       }
 
       transactionsInFlight_.erase(this);
- unlock_inflight_access();
- unlock_general_access();
+ unlock(inflight_lock());
+ unlock(general_lock());
 
       deferredCommitWriteState();
 
@@ -1587,8 +1531,8 @@
    catch (aborted_transaction_exception&)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       deferred_abort();
       unlock_tx();
 
@@ -1600,8 +1544,8 @@
    catch (...)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       deferred_abort();
       unlock_tx();
 
@@ -1672,8 +1616,8 @@
    catch (aborted_transaction_exception&)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
       direct_abort();
       unlock_tx();
@@ -1686,8 +1630,8 @@
    catch (...)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
 
       direct_abort();
       unlock_tx();
@@ -1780,8 +1724,8 @@
    catch (aborted_transaction_exception&)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       deferred_abort();
       unlock_tx();
 
@@ -1793,8 +1737,8 @@
    catch (...)
    {
       unlock_all_mutexes_but_this(threadId_);
- unlock_general_access();
- unlock_inflight_access();
+ unlock(general_lock());
+ unlock(inflight_lock());
       deferred_abort();
       unlock_tx();
 

Added: sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,148 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_DETAIL_CACHE_MAP__HPP
+#define BOOST_STM_NON_TX_DETAIL_CACHE_MAP__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <map>
+#include <boost/stm/base_transaction_object.hpp>
+#include <boost/stm/cache_fct.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+namespace non_tx { namespace detail {
+
+//-----------------------------------------------------------------------------
+// This class defines the transactional cache of a non transactional variable.
+// There is a map from the address of the variable of type T to an instance of this class
+//
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class cache : public base_transaction_object {
+public:
+ T* const value_;
+ mutable T* ptr_;
+
+ inline cache(T& ref)
+ : base_transaction_object()
+ , value_(&ref), ptr_(0) {}
+
+ inline cache(T* ptr)
+ : base_transaction_object()
+ , value_(ptr), ptr_(0) {}
+
+ inline ~cache() {
+ delete ptr_;
+ }
+
+ inline T const * get() const {
+ if(ptr_!=0) return ptr_;
+ else return value_;
+ }
+
+ inline T * get() {
+ return ptr_;
+ }
+ virtual base_transaction_object* clone() const {
+ cache* tmp = cache_clone(*this);
+ if (tmp->value_!=0) {
+ tmp->ptr_ = new T(*value_);
+ }
+ return tmp;
+ }
+
+ virtual void copy_state(base_transaction_object const * const rhs) {
+ if (value_==0) return;
+ *value_= *(static_cast<cache<T> const * const>(rhs)->ptr_);
+ delete ptr_;
+ ptr_=0;
+ }
+
+#ifdef BOOST_STM_USE_MEMCOPY
+ virtual void cache_deallocate() {
+ delete ptr_;
+ ptr_=0;
+ boost::stm::cache_deallocate(this);
+ }
+#endif
+
+#if USE_STM_MEMORY_MANAGER
+ void* operator new(size_t size) throw ()
+ {
+ return retrieve_mem(size);
+ }
+
+ void operator delete(void* mem)
+ {
+ return_mem(mem, sizeof(transactional_object<T>));
+ }
+#endif
+
+private:
+ //cache(cache<T> const & r);
+
+ //: base_transaction_object(r)
+ //, value_(r.value_), ptr_(r.ptr_) {}
+
+
+ //cache & operator=(cache const & r);
+ //{
+ // value_ = r.value_;
+ // ptr_ = r.ptr_;
+ // return *this;
+ //}
+
+};
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class cache_map {
+ typedef std::map<void*, base_transaction_object*> map_type;
+ static std::map<void*, base_transaction_object*> map_;
+public:
+ template <typename T>
+ static cache<T>* get(T* ptr) {
+ map_type::iterator it = map_.find(ptr);
+ cache<T>* res=0;
+ if (it == map_.end()) {
+ res= new cache<T>(ptr);
+ map_.insert(std::make_pair(ptr, res));
+ } else {
+ res=static_cast<cache<T>*>(it->second);
+ }
+ return res;
+ }
+ template <typename T>
+ static cache<T>* get(T const* ptr) {
+ map_type::iterator it = map_.find(const_cast<T*>(ptr));
+ cache<T>* res=0;
+ if (it == map_.end()) {
+ res= new cache<T>(const_cast<T*>(ptr));
+ map_.insert(std::make_pair(const_cast<T*>(ptr), res));
+ } else {
+ res=static_cast<cache<T>*>(it->second);
+ }
+ return res;
+ }
+};
+
+}}
+}}
+#endif
+
+

Added: sandbox/stm/branches/vbe/boost/stm/non_tx/integers.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/integers.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,161 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TX_SMART_PTR__HPP
+#define BOOST_STM_TX_SMART_PTR__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 {
+
+template <typename T>
+class numeric;
+class chat_t;
+class uchat_t;
+class short_t;
+class ushort_t;
+class int_t;
+class uint_t;
+class long_t;
+class ulong_t;
+
+//-----------------------------------------------------------------------------
+// class numeric wraps a transactional_object providing builting operators
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class numeric {
+public:
+ T val_;
+ //-----------------------------------------------------------------------------
+ numeric() : val_(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=transaction::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=transaction::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;
+ }
+
+ 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
+
+};
+#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
+
+}}}
+#endif
+
+

Added: sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,165 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_NUMERIC__HPP
+#define BOOST_STM_NON_TX_NUMERIC__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 {
+
+
+//-----------------------------------------------------------------------------
+// class numeric wraps a transactional_object providing builting operators
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class numeric {
+public:
+ T val_;
+ //-----------------------------------------------------------------------------
+ numeric() : val_(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=transaction::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=transaction::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;
+ }
+
+ 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
+
+};
+#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;
+
+typedef numeric<char> char_t;
+typedef numeric<unsigned char> uchar_t;
+typedef numeric<short> short_t;
+typedef numeric<unsigned short> ushort_t;
+typedef numeric<int> int_t;
+typedef numeric<unsigned int> uint_t;
+typedef numeric<long> long_t;
+typedef numeric<unsigned long> ulong_t;
+
+typedef numeric<float> float_t;
+typedef numeric<double> double_t;
+
+}}}
+#endif
+
+

Added: sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,282 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_SMART_PTR__HPP
+#define BOOST_STM_NON_TX_SMART_PTR__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <assert.h>
+#include <map>
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/non_tx/detail/cache_map.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+namespace non_tx {
+
+template <typename T>
+class rd_ptr;
+template <typename T>
+class wr_ptr;
+template <typename T>
+class upgrd_ptr;
+
+//-----------------------------------------------------------------------------
+// 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 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
+// upgrd_ptr instead which is safe.
+//-----------------------------------------------------------------------------
+
+
+template <typename T>
+class rd_ptr {
+ typedef rd_ptr<T> this_type;
+public:
+ mutable transaction& tx_;
+ mutable detail::cache<T>* ptr_;
+
+ inline rd_ptr(transaction &t, T const * ptr) : tx_(t),
+ ptr_(&t.insert_and_return_read_memory(*detail::cache_map::get(ptr)))
+ {}
+
+ inline rd_ptr(transaction &t, T const & obj) : tx_(t),
+ ptr_(&t.insert_and_return_read_memory(*detail::cache_map::get(&obj)))
+ {}
+
+ template<class Y>
+ inline rd_ptr & operator=(Y const* ptr) { // never throws
+ ptr_=tx_.insert_and_return_read_memory(*detail::cache_map::get(ptr));
+ return *this;
+ }
+
+ template<class Y>
+ inline rd_ptr & operator=(Y const& ref) { // never throws
+ ptr_=tx_.insert_and_return_read_memory(*detail::cache_map::get(&ref));
+ return *this;
+ }
+
+ const T* get() const {
+ if (tx_.forced_to_abort()) {
+ tx_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return ptr_->get();
+ }
+
+ inline const T & operator*() const { return *get(); }
+ inline const T* operator->() const { return get(); }
+
+
+ typedef detail::cache<T>* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+
+};
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(transaction& tx, T* ptr) {
+ return rd_ptr<T>(tx, ptr);
+}
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(transaction& tx, T& ref) {
+ return rd_ptr<T>(tx, ref);
+}
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(T* ptr) {
+ transaction* tx = transaction::current_transaction();
+ assert(tx==0);
+ return rd_ptr<T>(*tx, ptr);
+}
+
+template <typename T>
+inline rd_ptr<T> make_rd_ptr(T& ref) {
+ transaction* tx = transaction::current_transaction();
+ assert(tx==0);
+ return rd_ptr<T>(*tx, ref);
+}
+
+template <typename T>
+inline void delete_ptr(rd_ptr<T> ptr) {
+ if (ptr.ptr_==0) return;
+ ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+
+
+//-----------------------------------------------------------------------------
+// A upgrd_ptr<T> ("upgradable 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 upgrd_ptr<T> is constructed from an tx_ptr<T> through a constructor
+// having also the transaction as parameter.
+// 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>.
+// It is safe to derreference a rd_ptr<T> after having assigned the same
+// tx_ptr<T> to a wr_ptr<T>.
+// A upgrd_ptr<T> can be upgraded to a wr_ptr<T> through a constructor.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class upgrd_ptr {
+ typedef upgrd_ptr<T> this_type;
+public:
+ mutable transaction* tx_;
+ mutable detail::cache<T>* ptr_;
+ mutable bool written_;
+
+ inline upgrd_ptr(transaction &t, T* ptr) : tx_(&t),
+ ptr_(const_cast<detail::cache<T>*>(t.read_ptr(detail::cache_map::get(ptr)))), written_(false) {}
+
+ inline upgrd_ptr(transaction &t, T& ref) : tx_(&t),
+ ptr_(const_cast<detail::cache<T>*>(t.read_ptr(detail::cache_map::get(&ref)))), written_(false) {}
+
+ template<class Y>
+ inline upgrd_ptr & operator=(Y* ptr) {
+ ptr_=const_cast<detail::cache<T>*>(tx_->read_ptr(detail::cache_map::get(ptr)));
+ return *this;
+ }
+
+ template<class Y>
+ inline upgrd_ptr & operator=(Y& ref) {
+ ptr_=const_cast<detail::cache<T>*>(tx_->read_ptr(detail::cache_map::get(&ref)));
+ return *this;
+ }
+
+ const T* get() const {
+ if (tx_->forced_to_abort()) {
+ tx_->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ // we don't hold the written object and
+ // we have alrerady written an object on this transaction maybe is this one
+ if (!written_ && tx_->written()) {
+ detail::cache<T>* temp = tx_->get_written(*ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp) {
+ ptr_ = temp;
+ written_ = true;
+ }
+ }
+
+ return &ptr_->value;
+ }
+
+ inline T const & operator*() const { return *get(); }
+ inline T const * operator->() const { return get(); }
+
+ //operator const T*() const { return get(); }
+
+ typedef detail::cache<T>* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+ inline void write_ptr(detail::cache<T>* ptr) {
+ ptr_ = ptr;
+ written_ = true;
+ }
+
+ T* write_ptr() {
+ if (tx_->forced_to_abort()) {
+ tx_->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ // we are already holding the written object
+ if (written_) return ptr_;
+
+ detail::cache<T>* temp = tx_->get_written(ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp) {
+ ptr_ = temp;
+ written_ = true;
+ } else {
+ ptr_ = tx_->write_ptr(ptr_);
+ written_ = true;
+ }
+
+ return ptr_;
+ }
+
+};
+
+template <typename T>
+inline void delete_ptr(upgrd_ptr<T> const& ptr) {
+ if (ptr.ptr_==0) return;
+ if (ptr.tx_==0) delete ptr.ptr_;
+ ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+inline void delete_ptr(transaction& tx, upgrd_ptr<T> const& ptr) {
+ if (ptr.ptr_==0) return;
+ tx.delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+class wr_ptr {
+ typedef wr_ptr<T> this_type;
+public:
+ mutable transaction& tx_;
+ mutable detail::cache<T>* ptr_;
+
+ inline wr_ptr(transaction &t, T* ptr) : tx_(t),
+ ptr_(t.write_ptr(detail::cache_map::get(ptr)))
+ {}
+
+ inline wr_ptr(transaction &t, T& obj) : tx_(t),
+ ptr_(t.write_ptr(detail::cache_map::get(&obj)))
+ {}
+
+
+ T* get() {
+ if (tx_.forced_to_abort()) {
+ tx_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return ptr_->get();
+ }
+
+ inline T& operator*() { return *get(); }
+ inline T* operator->() { return get(); }
+
+ typedef detail::cache<T>* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+};
+
+
+}
+}}
+#endif
+
+

Deleted: sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx_smart_ptr.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
+++ (empty file)
@@ -1,396 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (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_SMART_PTR__HPP
-#define BOOST_STM_NON_TX_SMART_PTR__HPP
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-#include <assert.h>
-#include <map>
-#include <boost/stm/transaction.hpp>
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-namespace non_tx {
-
-template <typename T>
-class rd_ptr;
-template <typename T>
-class wr_ptr;
-template <typename T>
-class upgrd_ptr;
-
-//-----------------------------------------------------------------------------
-// This class defines the transactional cache of a non transactional variable.
-// There is a map from the address of the variable of type T to an instance of this class
-//
-//-----------------------------------------------------------------------------
-
-namespace detail {
-
-template <typename T>
-class cache : public base_transaction_object {
-public:
- T* const value_;
- mutable T* ptr_;
-
- inline cache(T& ref)
- : base_transaction_object()
- , value_(&ref), ptr_(0) {}
-
- inline cache(T* ptr)
- : base_transaction_object()
- , value_(ptr), ptr_(0) {}
-
- inline ~cache() {
- delete ptr_;
- }
-
- inline T* get() const {
- if(ptr_!=0) return ptr_;
- else return value_;
- }
-
- virtual base_transaction_object* clone() const {
- cache* tmp = cache_clone(*this);
- if (tmp->value_!=0) {
- tmp->ptr_ = new T(*value_);
- }
- return tmp;
- }
-
- virtual void copy_state(base_transaction_object const * const rhs) {
- if (value_==0) return;
- *value_= *(static_cast<cache<T> const * const>(rhs)->ptr_);
- delete ptr_;
- ptr_=0;
- }
-
-#ifdef BOOST_STM_USE_MEMCOPY
- virtual void cache_deallocate() {
- delete ptr_;
- ptr_=0;
- boost::stm::cache_deallocate(this);
- }
-#endif
-
-#if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
- {
- return retrieve_mem(size);
- }
-
- void operator delete(void* mem)
- {
- return_mem(mem, sizeof(transactional_object<T>));
- }
-#endif
-
-private:
- //cache(cache<T> const & r);
-
- //: base_transaction_object(r)
- //, value_(r.value_), ptr_(r.ptr_) {}
-
-
- //cache & operator=(cache const & r);
- //{
- // value_ = r.value_;
- // ptr_ = r.ptr_;
- // return *this;
- //}
-
-};
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-class cache_map {
- typedef std::map<void*, base_transaction_object*> map_type;
- static std::map<void*, base_transaction_object*> map_;
-public:
- template <typename T>
- static cache<T>* get(T* ptr) {
- map_type::iterator it = map_.find(ptr);
- cache<T>* res=0;
- if (it == map_.end()) {
- res= new cache<T>(ptr);
- map_.insert(std::make_pair(ptr, res));
- } else {
- res=static_cast<cache<T>*>(it->second);
- }
- return res;
- }
- template <typename T>
- static cache<T>* get(T const* ptr) {
- map_type::iterator it = map_.find(const_cast<T*>(ptr));
- cache<T>* res=0;
- if (it == map_.end()) {
- res= new cache<T>(const_cast<T*>(ptr));
- map_.insert(std::make_pair(const_cast<T*>(ptr), res));
- } else {
- res=static_cast<cache<T>*>(it->second);
- }
- return res;
- }
-};
-
-}
-//-----------------------------------------------------------------------------
-// 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 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
-// upgrd_ptr instead which is safe.
-//-----------------------------------------------------------------------------
-
-
-template <typename T>
-class rd_ptr {
- typedef rd_ptr<T> this_type;
-public:
- mutable transaction& tx_;
- mutable detail::cache<T>* ptr_;
-
- inline rd_ptr(transaction &t, T const * ptr) : tx_(t),
- ptr_(&t.insert_and_return_read_memory(*detail::cache_map::get(ptr)))
- {}
-
- inline rd_ptr(transaction &t, T const & obj) : tx_(t),
- ptr_(&t.insert_and_return_read_memory(*detail::cache_map::get(&obj)))
- {}
-
- template<class Y>
- inline rd_ptr & operator=(Y const* ptr) { // never throws
- ptr_=tx_.insert_and_return_read_memory(*detail::cache_map::get(ptr));
- return *this;
- }
-
- template<class Y>
- inline rd_ptr & operator=(Y const& ref) { // never throws
- ptr_=tx_.insert_and_return_read_memory(*detail::cache_map::get(&ref));
- return *this;
- }
-
- const T* get() const {
- if (tx_.forced_to_abort()) {
- tx_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- return ptr_->get();
- }
-
- inline const T & operator*() const { return *get(); }
- inline const T* operator->() const { return get(); }
-
-
- typedef detail::cache<T>* this_type::*unspecified_bool_type;
-
- inline operator unspecified_bool_type() const {
- return ptr_ == 0? 0: &this_type::ptr_;
- }
-
-};
-
-template <typename T>
-inline rd_ptr<T> make_rd_ptr(transaction& tx, T* ptr) {
- return rd_ptr<T>(tx, ptr);
-}
-
-template <typename T>
-inline rd_ptr<T> make_rd_ptr(transaction& tx, T& ref) {
- return rd_ptr<T>(tx, ref);
-}
-
-template <typename T>
-inline rd_ptr<T> make_rd_ptr(T* ptr) {
- transaction* tx = transaction::current_transaction();
- assert(tx==0);
- return rd_ptr<T>(*tx, ptr);
-}
-
-template <typename T>
-inline rd_ptr<T> make_rd_ptr(T& ref) {
- transaction* tx = transaction::current_transaction();
- assert(tx==0);
- return rd_ptr<T>(*tx, ref);
-}
-
-template <typename T>
-inline void delete_ptr(rd_ptr<T> ptr) {
- if (ptr.ptr_==0) return;
- ptr.tx_->delete_tx_ptr(ptr.ptr_);
-}
-
-
-
-//-----------------------------------------------------------------------------
-// A upgrd_ptr<T> ("upgradable 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 upgrd_ptr<T> is constructed from an tx_ptr<T> through a constructor
-// having also the transaction as parameter.
-// 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>.
-// It is safe to derreference a rd_ptr<T> after having assigned the same
-// tx_ptr<T> to a wr_ptr<T>.
-// A upgrd_ptr<T> can be upgraded to a wr_ptr<T> through a constructor.
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class upgrd_ptr {
- typedef upgrd_ptr<T> this_type;
-public:
- mutable transaction* tx_;
- mutable detail::cache<T>* ptr_;
- mutable bool written_;
-
- inline upgrd_ptr(transaction &t, T* ptr) : tx_(&t),
- ptr_(const_cast<detail::cache<T>*>(t.read_ptr(detail::cache_map::get(ptr)))), written_(false) {}
-
- inline upgrd_ptr(transaction &t, T& ref) : tx_(&t),
- ptr_(const_cast<detail::cache<T>*>(t.read_ptr(detail::cache_map::get(&ref)))), written_(false) {}
-
- template<class Y>
- inline upgrd_ptr & operator=(Y* ptr) {
- ptr_=const_cast<detail::cache<T>*>(tx_->read_ptr(detail::cache_map::get(ptr)));
- return *this;
- }
-
- template<class Y>
- inline upgrd_ptr & operator=(Y& ref) {
- ptr_=const_cast<detail::cache<T>*>(tx_->read_ptr(detail::cache_map::get(&ref)));
- return *this;
- }
-
- const T* get() const {
- if (tx_->forced_to_abort()) {
- tx_->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
-
- // we don't hold the written object and
- // we have alrerady written an object on this transaction maybe is this one
- if (!written_ && tx_->written()) {
- detail::cache<T>* temp = tx_->get_written(*ptr_);
-
- // if we found something, store this as the tx_ptr_
- if (0 != temp) {
- ptr_ = temp;
- written_ = true;
- }
- }
-
- return &ptr_->value;
- }
-
- inline T const & operator*() const { return *get(); }
- inline T const * operator->() const { return get(); }
-
- //operator const T*() const { return get(); }
-
- typedef detail::cache<T>* this_type::*unspecified_bool_type;
-
- inline operator unspecified_bool_type() const {
- return ptr_ == 0? 0: &this_type::ptr_;
- }
- inline void write_ptr(detail::cache<T>* ptr) {
- ptr_ = ptr;
- written_ = true;
- }
-
- T* write_ptr() {
- if (tx_->forced_to_abort()) {
- tx_->lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
-
- // we are already holding the written object
- if (written_) return ptr_;
-
- detail::cache<T>* temp = tx_->get_written(ptr_);
-
- // if we found something, store this as the tx_ptr_
- if (0 != temp) {
- ptr_ = temp;
- written_ = true;
- } else {
- ptr_ = tx_->write_ptr(ptr_);
- written_ = true;
- }
-
- return ptr_;
- }
-
-};
-
-template <typename T>
-inline void delete_ptr(upgrd_ptr<T> const& ptr) {
- if (ptr.ptr_==0) return;
- if (ptr.tx_==0) delete ptr.ptr_;
- ptr.tx_->delete_tx_ptr(ptr.ptr_);
-}
-
-template <typename T>
-inline void delete_ptr(transaction& tx, upgrd_ptr<T> const& ptr) {
- if (ptr.ptr_==0) return;
- tx.delete_tx_ptr(ptr.ptr_);
-}
-
-template <typename T>
-class wr_ptr {
- typedef wr_ptr<T> this_type;
-public:
- mutable transaction& tx_;
- mutable detail::cache<T>* ptr_;
-
- inline wr_ptr(transaction &t, T* ptr) : tx_(t),
- ptr_(t.write_ptr(detail::cache_map::get(ptr)))
- {}
-
- inline wr_ptr(transaction &t, T& obj) : tx_(t),
- ptr_(t.write_ptr(detail::cache_map::get(&obj)))
- {}
-
-
- T* get() {
- if (tx_.forced_to_abort()) {
- tx_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- return ptr_->get();
- }
-
- inline T& operator*() { return *get(); }
- inline T* operator->() { return get(); }
-
- typedef detail::cache<T>* this_type::*unspecified_bool_type;
-
- inline operator unspecified_bool_type() const {
- return ptr_ == 0? 0: &this_type::ptr_;
- }
-};
-
-
-}
-}}
-#endif
-
-

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-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -44,7 +44,7 @@
 
 #if defined(BOOST_STM_CM_STATIC_CONF)
 #if defined(BOOST_STM_CM_STATIC_CONF_except_and_back_off_on_abort_notice_cm)
-#include <boost/stm/except_and_back_off_on_abort_notice_cm.hpp>
+#include <boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm.hpp>
 #else
 #include <boost/stm/contention_managers/default.hpp>
 #endif
@@ -526,13 +526,13 @@
       // an exception here because restarting the transactions will cause it to
       // infinitely fail
       //-----------------------------------------------------------------------
- lock_inflight_access();
+ lock(inflight_lock());
       if (other_in_flight_same_thread_transactions())
       {
- unlock_inflight_access();
+ unlock(inflight_lock());
          throw aborted_transaction_exception("closed nesting throw");
       }
- unlock_inflight_access();
+ unlock(inflight_lock());
 
       return true;
    }
@@ -877,15 +877,6 @@
    void lock_tx();
    void unlock_tx();
 
- static void lock_latm_access();
- static void unlock_latm_access();
-
- static void lock_inflight_access();
- static void unlock_inflight_access();
-
- static void lock_general_access();
- static void unlock_general_access();
-
    inline static PLOCK* latm_lock() { return &latmMutex_; }
    inline static PLOCK* general_lock() { return &transactionMutex_; }
    inline static PLOCK* inflight_lock() { return &transactionsInFlightMutex_; }
@@ -943,7 +934,6 @@
 
          if (in.transaction_thread() != kInvalidThread)
          {
- //lockThreadMutex(in.transaction_thread());
             //lock_guard2<Mutex> guard(mutex(in.transaction_thread()));
             Mutex& m=mutex(in.transaction_thread());
             stm::lock(m);
@@ -963,7 +953,6 @@
 #endif
             unlock(&transactionMutex_);
             unlock_tx();
- //unlockThreadMutex(in.transaction_thread());
             stm::unlock(m);
             //guard.unlock();
 
@@ -1255,8 +1244,6 @@
    void invalidating_direct_commit();
 
    //--------------------------------------------------------------------------
- void lockThreadMutex(size_t threadId);
- void unlockThreadMutex(size_t threadId);
    static void lock_all_mutexes_but_this(size_t threadId);
    static void unlock_all_mutexes_but_this(size_t threadId);
 

Modified: sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction_object_ptr.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -11,8 +11,8 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef BOOST_STM_TRANSACTION_OBJECT_PTR__H
-#define BOOST_STM_TRANSACTION_OBJECT_PTR__H
+#ifndef BOOST_STM_TRANSACTION_OBJECT_PTR__HPP
+#define BOOST_STM_TRANSACTION_OBJECT_PTR__HPP
 
 
 #include <boost/stm/base_transaction.hpp>
@@ -25,34 +25,28 @@
     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) {
- }
- transaction_object_ptr(const transaction_object_ptr & rhs) : base_type(rhs), ptr_(rhs.ptr_) {
- }
- transaction_object_ptr(transaction_object_ptr & rhs) : base_type(rhs), ptr_(rhs.rhs) {
- }
- transaction_object_ptr(TO* ptr) : base_type(), ptr_(ptr) {
- }
- ~transaction_object_ptr() {
- }
+ transaction_object_ptr() : base_type(), ptr_(0) {}
+ transaction_object_ptr(const transaction_object_ptr & rhs) : base_type(rhs), ptr_(rhs.ptr_) {}
+ transaction_object_ptr(transaction_object_ptr & rhs) : base_type(rhs), ptr_(rhs.rhs) {}
+ transaction_object_ptr(TO* ptr) : base_type(), ptr_(ptr) {}
+ ~transaction_object_ptr() {}
+
     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
+#endif // BOOST_STM_TRANSACTION_OBJECT_PTR__HPP
 
 

Added: sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,93 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TX_NUMERIC__HPP
+#define BOOST_STM_TX_NUMERIC__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/non_tx/detail/cache_map.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm { namespace tx {
+
+template <typename T>
+class numeric : public transaction_object< numeric<T> >
+{
+protected:
+ T val_;
+public:
+ //-----------------------------------------------------------------------------
+ numeric() : val_(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=transaction::current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ return tx->write(*this).val_;
+ }
+ return val_;
+ }
+
+ T value() const {
+ transaction* tx=transaction::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_;
+ }
+ return val_;
+ }
+
+};
+
+
+typedef numeric<bool> boolean;
+
+typedef numeric<char> char_t;
+typedef numeric<unsigned char> uchar_t;
+typedef numeric<short> short_t;
+typedef numeric<unsigned short> ushort_t;
+typedef numeric<int> int_t;
+typedef numeric<unsigned int> uint_t;
+typedef numeric<long> long_t;
+typedef numeric<unsigned long> ulong_t;
+
+typedef numeric<float> float_t;
+typedef numeric<double> double_t;
+
+}}}
+#endif
+
+

Added: sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,171 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TX_POINTER__HPP
+#define BOOST_STM_TX_POINTER__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/non_tx/detail/cache_map.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm { namespace tx {
+
+//-----------------------------------------------------------------------------
+// class pointer wraps a transactional_object providing builting operators
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class pointer : public transaction_object< pointer<T> >
+{
+protected:
+ T* val_;
+public:
+ //-----------------------------------------------------------------------------
+ pointer() : val_(0) {}
+
+ //
+ template<class U>
+ pointer(pointer<U> const& r) : val_(r.value()) {}
+
+ // contructor from a implicitly convertible to T
+ 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=transaction::current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ return tx->write(*this).val_;
+ }
+ return val_;
+ }
+
+ T const * get() const {
+ transaction* tx=transaction::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_;
+ }
+ return val_;
+ }
+
+ T const * operator->() const {
+ return this->get();
+ }
+ T const & operator*() const {
+ return *this->get();
+ }
+
+ T * operator->() {
+ return this->get();
+ }
+ T & operator*() {
+ return *this->get();
+ }
+
+};
+
+template <typename C, typename R>
+class pointer_to_member : public transaction_object< pointer_to_member<C,R> >
+{
+protected:
+ R C::* val_;
+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=transaction::current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ return tx->write(*this).val_;
+ }
+ return val_;
+ }
+
+ R C::* const * get() const {
+ transaction* tx=transaction::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_;
+ }
+ return val_;
+ }
+
+};
+
+#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
+
+

Added: sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp 2009-10-08 15:31:47 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,566 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TX_SMART_PTR__HPP
+#define BOOST_STM_TX_SMART_PTR__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <assert.h>
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/transactional_object.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+template <typename T>
+class rd_ptr;
+template <typename T>
+class wr_ptr;
+template <typename T>
+class upgrd_ptr;
+
+//-----------------------------------------------------------------------------
+// class tx_obj wraps a transactional_object providing builting operators
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class tx_obj {
+public:
+ transactional_object<T> obj_;
+
+ //-----------------------------------------------------------------------------
+ // default constructor valid ony if T has a default constructor
+
+ tx_obj() : obj_() {}
+
+ //
+ template<class Y>
+ tx_obj(tx_obj<Y> const& r) : obj_(r.ref()) {}
+
+ template <typename T1>
+ tx_obj(T1 p1) : obj_(p1) {}
+ ~tx_obj() {}
+ #if 0
+ bool operator==(const tx_obj<T>& rhs) const {
+ return this->ref()==rhs.ref();
+ }
+
+ bool operator==(const T& rhs) const {
+ return this->ref()==rhs;
+ }
+ #endif
+
+ //operator T() const { return *this->get(); }
+
+ T* operator->() {
+ return this->get();
+ }
+ const T* operator->() const {
+ return this->get();
+ }
+ T& operator*() {
+ return this->ref();
+ }
+ const T& operator*() const {
+ return this->ref();
+ }
+ T* get() {
+ return &this->ref();
+ }
+ const T* get() const {
+ return &this->ref();
+ }
+ T& ref() {
+ transaction* tx=transaction::current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return tx->write(obj_).value;
+ }
+ return obj_.value;
+ }
+
+ const T& ref() const {
+ transaction* tx=transaction::current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return tx->read(obj_).value;
+ }
+ return obj_.value;
+ }
+
+
+ tx_obj& operator--() { --ref(); return *this; }
+ T operator--(int) { T n = obj_.value_; --ref(); return n; }
+
+ tx_obj& operator++() { ++ref(); return *this; }
+ T operator++(int) { T n = obj_.value_; ++ref(); return n; }
+
+ tx_obj& operator+=(T const &rhs) {
+ ref() += rhs;
+ return *this;
+ }
+
+ T operator+(T const &rhs) const {
+ return ref()+rhs;
+ }
+
+ void swap(tx_obj & other) { // never throws
+ std::swap(obj_, other.obj_);
+ }
+
+};
+
+// 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 tx_obj<T>& lhs, const tx_obj<U>& rhs) {
+ return lhs.ref()==rhs.ref();
+}
+
+template <typename T, typename U>
+inline bool operator==(const T& lhs, const tx_obj<U>& rhs) {
+ return lhs==rhs.ref();
+}
+
+template <typename T, typename U>
+inline bool operator==(const tx_obj<T>& lhs, const U& rhs) {
+ return lhs.ref()==rhs;
+}
+
+template <typename T, typename U>
+inline bool operator!=(const tx_obj<T>& lhs, const tx_obj<U>& rhs) {
+ return lhs.ref()!=rhs.ref();
+}
+
+template<class T> inline void swap(tx_obj<T> & a, tx_obj<T> & b) {
+ a.swap(b);
+}
+
+//-----------------------------------------------------------------------------
+// a tx_ptr<T> is an smart pointer to a transactional_object<T> (which contains an instance of T).
+// Reference fields in linked structures should always be tx_ptrs.
+// The result of derreferencing it will be the pointer to the T instance
+// When this pointer is derreference on a transaction the transactional_object<T> is set as written and
+// the transaction specific storage will be used
+// Otherwise the shared storage is used.
+// Used to initialize a rd_ptr<T>, wr_ptr<T>, or upgrd_ptr<T>.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class tx_ptr {
+public:
+ typedef tx_ptr<T> this_type;
+ transactional_object<T> * ptr_;
+
+ tx_ptr() : ptr_(0) {}
+ template<class Y>
+ explicit tx_ptr(Y * ptr) : ptr_(new transactional_object<Y>(ptr)) {}
+
+ template<class Y>
+ explicit tx_ptr(transactional_object<Y>* ptr) : ptr_(ptr) {}
+
+ tx_ptr(tx_obj<T>& r) : ptr_(r->obj_) {}
+
+ template<class Y>
+ tx_ptr(tx_ptr<Y> const& r) : ptr_(r.ptr_) {}// never throws
+
+ template<class Y>
+ tx_ptr(rd_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
+
+ template<class Y>
+ tx_ptr(wr_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
+
+ template<class Y>
+ tx_ptr(upgrd_ptr<Y> const & r) : ptr_(r.ptr_) {}// never throws
+
+ template<class Y>
+ tx_ptr & operator=(tx_ptr<Y> const & r) { // never throws
+ //this_type(r).swap(*this);
+ ptr_=r.ptr_;
+ return *this;
+ }
+ template<class Y>
+ tx_ptr& operator=(transactional_object<Y>* ptr) { // never throws
+ ptr_=ptr;
+ return *this;
+ }
+
+ //bool operator==(const tx_ptr<T>& rhs) const {
+ // return ptr_==rhs.ptr_ || this->get()==rhs.ptr_ || ptr_==rhs.get();
+ //}
+
+ T* operator->() const {
+ return this->get();
+ }
+ T& operator*() const {
+ return *this->get();
+ }
+ T* get() const {
+ if (0==ptr_) return 0;
+ transaction* tx=transaction::current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return &(tx->write_ptr(ptr_)->value);
+ }
+ return &ptr_->value;
+ }
+
+ typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+ void swap(tx_ptr & other) { // never throws
+ std::swap(ptr_, other.ptr_);
+ }
+};
+
+// 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 tx_ptr<T>& lhs, const tx_ptr<U>& rhs) {
+ return lhs.ptr_==rhs.ptr_ || lhs.get()==rhs.ptr_ || lhs.ptr_==rhs.get();
+}
+
+template <typename T, typename U>
+inline bool operator!=(const tx_ptr<T>& lhs, const tx_ptr<U>& rhs) {
+ return lhs.ptr_!=rhs.ptr_ && lhs.get()!=rhs.ptr_ && lhs.ptr_!=rhs.get();
+}
+
+template<class T>
+inline void swap(tx_ptr<T> & a, tx_ptr<T> & b) {
+ a.swap(b);
+}
+
+template <typename T>
+inline tx_ptr<T> make_tx_ptr() {
+ return tx_ptr<T>(new transactional_object<T>());
+}
+
+template <typename T, typename A1>
+inline tx_ptr<T> make_tx_ptr(A1 const &a1) {
+ return tx_ptr<T>(new transactional_object<T>(a1));
+}
+
+
+template <typename T>
+void delete_ptr(tx_ptr<T> ptr) {
+ if (ptr.ptr_==0) return;
+ transaction* tx=transaction::current_transaction();
+ if (tx==0) delete ptr.ptr_;
+ tx->delete_tx_ptr(ptr.ptr_);
+}
+
+
+template <typename T>
+void delete_ptr(transaction& tx, tx_ptr<T> ptr) {
+ if (ptr.ptr_==0) return;
+ tx.delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T, typename U>
+inline tx_ptr<T> tx_static_cast(tx_ptr<U> ptr) {
+ return tx_ptr<T>(tx_static_cast<T>(ptr->ptr_));
+}
+
+template <typename T, typename U>
+inline tx_ptr<T>* tx_dynamic_cast(tx_ptr<U> ptr) {
+ return tx_ptr<T>(tx_dynamic_cast<T>(ptr->ptr_));
+}
+
+
+//-----------------------------------------------------------------------------
+// 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>.
+// 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
+// upgrd_ptr instead which is safe.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class rd_ptr {
+ typedef rd_ptr<T> this_type;
+public:
+ mutable transaction* tx_;
+ mutable transactional_object<T>* ptr_;
+
+ inline rd_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(&t),
+ ptr_(&t.insert_and_return_read_memory(*tx_obj.ptr_))
+ {}
+
+ inline rd_ptr(transaction &t, tx_obj<T> const& tx_obj) : tx_(&t),
+ ptr_(&t.insert_and_return_read_memory(tx_obj.obj_))
+ {}
+
+ template<class Y>
+ inline rd_ptr & operator=(tx_ptr<Y> r) { // never throws
+ //this_type(r).swap(*this);
+ ptr_=r.ptr_;
+ return *this;
+ }
+
+ template<class Y>
+ inline rd_ptr& operator=(tx_obj<Y> const & r) { // never throws
+ //this_type(r).swap(*this);
+ ptr_=r.get();
+ return *this;
+ }
+
+ const T* get() const {
+ if (tx_->forced_to_abort()) {
+ tx_->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return &ptr_->value;
+ }
+
+ inline const T & operator*() const { return *get(); }
+ inline const T* operator->() const { return get(); }
+
+
+ typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+
+};
+
+template <typename T>
+rd_ptr<T> make_rd_ptr(transaction& tx, tx_ptr<T> ptr) {
+ return rd_ptr<T>(tx, ptr);
+}
+template <typename T>
+rd_ptr<T> make_rd_ptr(transaction& tx, tx_obj<T> const & ref) {
+ return rd_ptr<T>(tx, ref);
+}
+
+template <typename T>
+rd_ptr<T> make_rd_ptr(tx_ptr<T> ptr) {
+ transaction* tx = transaction::current_transaction();
+ assert(tx==0);
+ return rd_ptr<T>(*tx, ptr);
+}
+
+template <typename T>
+rd_ptr<T> make_rd_ptr(tx_obj<T> const & ref) {
+ transaction* tx = transaction::current_transaction();
+ assert(tx==0);
+ return rd_ptr<T>(*tx, ref);
+}
+
+template <typename T>
+void delete_ptr(rd_ptr<T> ptr) {
+ if (ptr.ptr_==0) return;
+ ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+void delete_ptr(transaction& tx, rd_ptr<T> ptr) {
+ if (ptr.ptr_==0) return;
+ tx.delete_tx_ptr(ptr.ptr_);
+}
+
+//-----------------------------------------------------------------------------
+// A upgrd_ptr<T> ("upgradable 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 upgrd_ptr<T> is constructed from an tx_ptr<T> through a constructor
+// having also the transaction as parameter.
+// 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>.
+// It is safe to derreference a rd_ptr<T> after having assigned the same
+// tx_ptr<T> to a wr_ptr<T>.
+// A upgrd_ptr<T> can be upgraded to a wr_ptr<T> through a constructor.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class upgrd_ptr {
+ typedef upgrd_ptr<T> this_type;
+public:
+ mutable transaction* tx_;
+ mutable transactional_object<T>* ptr_;
+ mutable bool written_;
+
+ inline upgrd_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(&t),
+ ptr_(const_cast<transactional_object<T>*>(t.read_ptr(tx_obj.ptr_))), written_(false) {}
+
+ template<class Y>
+ upgrd_ptr & operator=(tx_ptr<Y> const& r) { // never throws
+ //this_type(r).swap(*this);
+ transaction* tx=transaction::current_transaction();
+ if (tx==0) throw "error";
+ tx_=tx;
+ ptr_=r.ptr_;
+ written_=false;
+ return *this;
+ }
+
+ const T* get() const {
+ if (tx_->forced_to_abort()) {
+ tx_->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ // we don't hold the written object and
+ // we have alrerady written an object on this transaction maybe is this one
+ if (!written_ && tx_->written()) {
+ transactional_object<T>* temp = tx_->get_written(*ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp) {
+ ptr_ = temp;
+ written_ = true;
+ }
+ }
+
+ return &ptr_->value;
+ }
+
+ inline T const & operator*() const { return *get(); }
+ inline T const * operator->() const { return get(); }
+
+ //operator const T*() const { return get(); }
+
+ typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+
+ inline void write_ptr(transactional_object<T>* ptr) {
+ ptr_ = ptr;
+ written_ = true;
+ }
+
+ T* write_ptr() {
+ if (tx_->forced_to_abort()) {
+ tx_->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ // we are already holding the written object
+ if (written_) return ptr_;
+
+ transactional_object<T>* temp = tx_->get_written(ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp) {
+ ptr_ = temp;
+ written_ = true;
+ } else {
+ ptr_ = tx_->write_ptr(ptr_);
+ written_ = true;
+ }
+
+ return ptr_;
+ }
+
+};
+
+template <typename T>
+void delete_ptr(upgrd_ptr<T> const& ptr) {
+ if (ptr.ptr_==0) return;
+ if (ptr.tx_==0) delete ptr.ptr_;
+ ptr.tx_->delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+void delete_ptr(transaction& tx, upgrd_ptr<T> const& ptr) {
+ if (ptr.ptr_==0) return;
+ tx.delete_tx_ptr(ptr.ptr_);
+}
+
+//-----------------------------------------------------------------------------
+// A wr_ptr<T> ("write pointer") points to a shared object that the current transaction has opened for writing.
+// A wr_ptr<T> is initialized explicitly from an tx_ptr<T>.
+// A wr_ptr<T> can also be explicitly constructed from a upgrd_ptr<T> as an upgrade-to-writable operation.
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class wr_ptr {
+ typedef wr_ptr<T> this_type;
+public:
+ mutable transaction& tx_;
+ mutable transactional_object<T>* ptr_;
+
+ inline wr_ptr(transaction &t, tx_ptr<T> tx_obj) : tx_(t),
+ ptr_(t.write_ptr(tx_obj.ptr_))
+ {}
+
+ inline wr_ptr(transaction &t, upgrd_ptr<T> tx_obj) : tx_(t),
+ ptr_(t.write_ptr(tx_obj.ptr_))
+ {
+ tx_obj.write_ptr(ptr_);
+ }
+
+ T* get() {
+ if (tx_.forced_to_abort()) {
+ tx_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return &ptr_->value;
+ }
+
+ inline T& operator*() { return *get(); }
+ inline T* operator->() { return get(); }
+
+ typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+ inline operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+};
+
+template <typename T>
+inline wr_ptr<T> make_wr_ptr(transaction& tx, tx_ptr<T>& ptr) {
+ return wr_ptr<T>(tx, ptr);
+}
+
+
+template <typename T>
+inline wr_ptr<T> make_wr_ptr(tx_ptr<T>& ptr) {
+ transaction* tx = transaction::current_transaction();
+ return wr_ptr<T>(*tx, ptr);
+}
+
+template <typename T>
+inline void delete_ptr(wr_ptr<T> ptr) {
+ if (ptr.ptr_==0) return;
+ ptr.tx_.delete_tx_ptr(ptr.ptr_);
+}
+
+template <typename T>
+inline void delete_ptr(transaction& tx, wr_ptr<T> const& ptr) {
+ if (ptr.ptr_==0) return;
+ tx.delete_tx_ptr(ptr.ptr_);
+}
+
+}}
+#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