Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57115 - in sandbox/stm/branches/vbe: boost boost/stm boost/stm/contention_managers boost/stm/detail boost/stm/synch boost/stm/tx boost/stm/txw libs/stm/src libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-10-23 14:22:50


Author: viboes
Date: 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
New Revision: 57115
URL: http://svn.boost.org/trac/boost/changeset/57115

Log:
TBoost.STM vbe: File reorganization

Added:
   sandbox/stm/branches/vbe/boost/stm/TBRbase_contention_manager.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp
   sandbox/stm/branches/vbe/boost/stm/TBRmove.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/move.hpp
   sandbox/stm/branches/vbe/boost/stm/TBRselect_contention_manager.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/select_contention_manager.hpp
   sandbox/stm/branches/vbe/boost/stm/TBRshallow_transaction_object.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp
   sandbox/stm/branches/vbe/boost/stm/TBRtransactional_object.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp
   sandbox/stm/branches/vbe/boost/stm/contention_managers/base_contention_manager.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/contention_managers/select_contention_manager.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/detail/TBRauto_lock.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp
   sandbox/stm/branches/vbe/boost/stm/detail/move.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/synch/
   sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx/TBRsmart_ptr.hpp
      - copied unchanged from r57055, /sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp
   sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/txw/
   sandbox/stm/branches/vbe/boost/stm/txw/smart_ptr.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp (contents, props changed)
Removed:
   sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp
   sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp
   sandbox/stm/branches/vbe/boost/stm/move.hpp
   sandbox/stm/branches/vbe/boost/stm/select_contention_manager.hpp
   sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp
   sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp
   sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp
Text files modified:
   sandbox/stm/branches/vbe/boost/stm.hpp | 20 +++++++-------------
   sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp | 5 +++--
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 14 ++++----------
   sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp | 2 +-
   sandbox/stm/branches/vbe/libs/stm/test/smart.cpp | 1 +
   sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h | 1 +
   6 files changed, 17 insertions(+), 26 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-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -16,27 +16,21 @@
 
 #include <boost/stm/detail/config.hpp>
 
-#include <boost/stm/base_contention_manager.hpp>
 #include <boost/stm/base_transaction_object.hpp>
 #include <boost/stm/cache_fct.hpp>
-#include <boost/stm/contention_manager.hpp>
 #include <boost/stm/datatypes.hpp>
 #include <boost/stm/exceptions.hpp>
 #include <boost/stm/language_like.hpp>
-#include <boost/stm/move.hpp>
-#include <boost/stm/non_tx/numeric.hpp>
-#include <boost/stm/non_tx/pointer.hpp>
-#include <boost/stm/non_tx/smart_ptr.hpp>
-#include <boost/stm/shallow_transaction_object.hpp>
+//#include <boost/stm/move.hpp>
 #include <boost/stm/transaction.hpp>
 #include <boost/stm/transaction_bookkeeping.hpp>
-#include <boost/stm/transaction_object.hpp>
 #include <boost/stm/transaction_object_ptr.hpp>
-#include <boost/stm/transactional_object.hpp>
-#include <boost/stm/tx_ptr.hpp>
-#include <boost/stm/tx/numeric.hpp>
-#include <boost/stm/tx/pointer.hpp>
-#include <boost/stm/tx/smart_ptr.hpp>
+
+#include <boost/stm/contention_managers.hpp>
+#include <boost/stm/non_tx.hpp>
+#include <boost/stm/synch.hpp>
+#include <boost/stm/tx.hpp>
+#include <boost/stm/txw.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 #endif // TRANSACTION_H

Deleted: sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,74 +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_BASE_CONTENTION_MANAGER__HPP
-#define BOOST_STM_BASE_CONTENTION_MANAGER__HPP
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-#include <list>
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-#include <boost/stm/detail/config.hpp>
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class transaction;
-class base_transaction_object;
-
-//-----------------------------------------------------------------------------
-class base_contention_manager
-{
-public:
- virtual void abort_on_new(transaction const &t) = 0;
- virtual void abort_on_delete(transaction const &t,
- base_transaction_object const &in) = 0;
-
- virtual void abort_on_read(transaction const &t,
- base_transaction_object const &in) = 0;
- virtual void abort_on_write(transaction &t,
- base_transaction_object const &in) = 0;
-
- virtual bool abort_before_commit(transaction const &t) = 0;
-
- virtual bool permission_to_abort
- (transaction const &lhs, transaction const &rhs) = 0;
-
- virtual bool permission_to_abort
- (transaction const &lhs, std::list<transaction*> &rhs)
- { return true; }
-
- virtual bool allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
- bool txIsIrrevocable, transaction const &rhs) = 0;
-
- virtual int lock_sleep_time() { return 10; }
-
- virtual void perform_isolated_tx_wait_priority_promotion(transaction &) = 0;
- virtual void perform_irrevocable_tx_wait_priority_promotion(transaction &) = 0;
-
- virtual ~base_contention_manager() {};
-};
-
-
-} // namespace core
-}
-#endif // BOOST_STM_BASE_CONTENTION_MANAGER__HPP
-
-

Modified: sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -24,13 +24,14 @@
 //-----------------------------------------------------------------------------
 #include <boost/stm/detail/config.hpp>
 //-----------------------------------------------------------------------------
-#include <boost/stm/base_contention_manager.hpp>
+#include <boost/stm/contention_managers/base_contention_manager.hpp>
 #include <boost/stm/base_transaction_object.hpp>
 #include <boost/stm/cache_fct.hpp>
 #include <boost/stm/datatypes.hpp>
 #include <boost/stm/exceptions.hpp>
-#include <boost/stm/move.hpp>
 #include <boost/stm/transaction_object.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/move.hpp>
 
 //-----------------------------------------------------------------------------
 #endif // BOOST_STM_BASE_TRANSACTION_H

Added: sandbox/stm/branches/vbe/boost/stm/contention_managers/base_contention_manager.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/contention_managers/base_contention_manager.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,74 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_BASE_CONTENTION_MANAGER__HPP
+#define BOOST_STM_BASE_CONTENTION_MANAGER__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// forward declarations
+//-----------------------------------------------------------------------------
+class transaction;
+class base_transaction_object;
+
+//-----------------------------------------------------------------------------
+class base_contention_manager
+{
+public:
+ virtual void abort_on_new(transaction const &t) = 0;
+ virtual void abort_on_delete(transaction const &t,
+ base_transaction_object const &in) = 0;
+
+ virtual void abort_on_read(transaction const &t,
+ base_transaction_object const &in) = 0;
+ virtual void abort_on_write(transaction &t,
+ base_transaction_object const &in) = 0;
+
+ virtual bool abort_before_commit(transaction const &t) = 0;
+
+ virtual bool permission_to_abort
+ (transaction const &lhs, transaction const &rhs) = 0;
+
+ virtual bool permission_to_abort
+ (transaction const &lhs, std::list<transaction*> &rhs)
+ { return true; }
+
+ virtual bool allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
+ bool txIsIrrevocable, transaction const &rhs) = 0;
+
+ virtual int lock_sleep_time() { return 10; }
+
+ virtual void perform_isolated_tx_wait_priority_promotion(transaction &) = 0;
+ virtual void perform_irrevocable_tx_wait_priority_promotion(transaction &) = 0;
+
+ virtual ~base_contention_manager() {};
+};
+
+
+} // namespace core
+}
+#endif // BOOST_STM_BASE_CONTENTION_MANAGER__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/contention_managers/select_contention_manager.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/contention_managers/select_contention_manager.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,146 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_SELECT_CONTENTION_MANAGER__HPP
+#define BOOST_STM_SELECT_CONTENTION_MANAGER__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+
+#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/contention_managers/except_and_back_off_on_abort_notice_cm.hpp>
+#else
+#include BOOST_STM_CM_STATIC_CONF
+#endif
+#else
+#include <boost/stm/contention_managers/base_contention_manager.hpp>
+
+//#if defined(BOOST_STM_CM_DYNAMIC_CONF)
+//#include <boost/stm/contention_managers/polymorphic.hpp>
+//#endif
+#endif
+
+namespace boost { namespace stm {
+
+
+#if defined(BOOST_STM_CM_STATIC_CONF)
+ inline static contention_manager_type* get_contention_manager() {
+ static contention_manager_type cm_;return &cm_;
+ }
+ inline static void cm_abort_on_new(transaction const &t) {
+ return contention_manager_type::abort_on_new(t);
+ }
+ inline static void cm_abort_on_delete(transaction const &t,
+ base_transaction_object const &in) {
+ return contention_manager_type::abort_on_delete(t,in);
+ }
+
+ inline static void cm_abort_on_read(transaction const &t,
+ base_transaction_object const &in) {
+ return contention_manager_type::abort_on_read(t,in);
+ }
+ inline static void cm_abort_on_write(transaction &t,
+ base_transaction_object const &in) {
+ return contention_manager_type::abort_on_write(t,in);
+ }
+
+ inline static bool cm_abort_before_commit(transaction const &t) {
+ return contention_manager_type::abort_before_commit(t);
+ }
+
+ inline static bool cm_permission_to_abort(transaction const &lhs, transaction const &rhs) {
+ return contention_manager_type::permission_to_abort(lhs,rhs);
+ }
+
+ inline static bool cm_permission_to_abort(transaction const &lhs, std::list<transaction*> &rhs) {
+ return contention_manager_type::permission_to_abort(lhs,rhs);
+ }
+
+ inline static bool cm_allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
+ bool txIsIrrevocable, transaction const &rhs) {
+ return contention_manager_type::allow_lock_to_abort_tx(lockWaitTime,lockAborted,txIsIrrevocable,rhs);
+ }
+
+ inline static int cm_lock_sleep_time() {
+ return contention_manager_type::lock_sleep_time();
+ }
+
+ inline static void cm_perform_isolated_tx_wait_priority_promotion(transaction &t) {
+ return contention_manager_type::perform_isolated_tx_wait_priority_promotion(t);
+ }
+ inline static void cm_perform_irrevocable_tx_wait_priority_promotion(transaction &t) {
+ return contention_manager_type::perform_irrevocable_tx_wait_priority_promotion(t);
+ }
+
+#else
+ struct poly_contention_manager {
+ static base_contention_manager *cm_;
+ };
+ inline static void contention_manager(base_contention_manager *rhs) {
+ delete poly_contention_manager::cm_; poly_contention_manager::cm_ = rhs;
+ }
+ inline static base_contention_manager* get_contention_manager() {
+ return poly_contention_manager::cm_;
+ }
+ inline static base_contention_manager* get_cm() {
+ return poly_contention_manager::cm_;
+ }
+
+ inline static void cm_abort_on_new(transaction const &t) {
+ return get_cm()->abort_on_new(t);
+ }
+ inline static void cm_abort_on_delete(transaction const &t, base_transaction_object const &in) {
+ return get_cm()->abort_on_delete(t,in);
+ }
+
+ inline static void cm_abort_on_read(transaction const &t, base_transaction_object const &in) {
+ return get_cm()->abort_on_read(t,in);
+ }
+ inline static void cm_abort_on_write(transaction &t, base_transaction_object const &in) {
+ return get_cm()->abort_on_write(t,in);
+ }
+
+ inline static bool cm_abort_before_commit(transaction const &t) {
+ return get_cm()->abort_before_commit(t);
+ }
+
+ inline static bool cm_permission_to_abort(transaction const &lhs, transaction const &rhs) {
+ return get_cm()->permission_to_abort(lhs,rhs);
+ }
+
+ inline static bool cm_permission_to_abort(transaction const &lhs, std::list<transaction*> &rhs) {
+ return get_cm()->permission_to_abort(lhs,rhs);
+ }
+
+ inline static bool cm_allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
+ bool txIsIrrevocable, transaction const &rhs) {
+ return get_cm()->allow_lock_to_abort_tx(lockWaitTime,lockAborted,txIsIrrevocable,rhs); }
+
+ inline static int cm_lock_sleep_time() {
+ return get_cm()->lock_sleep_time();
+ }
+
+ inline static void cm_perform_isolated_tx_wait_priority_promotion(transaction &t) {
+ return get_cm()->perform_isolated_tx_wait_priority_promotion(t);
+ }
+ inline static void cm_perform_irrevocable_tx_wait_priority_promotion(transaction &t) {
+ return get_cm()->perform_irrevocable_tx_wait_priority_promotion(t);
+ }
+
+#endif
+
+
+}}
+#endif // CONTENTION_MANAGER_H

Deleted: sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,234 +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_AUTO_LOCK_H
-#define BOOST_STM_AUTO_LOCK_H
-
-//---------------------------------------------------------------------------
-#include <pthread.h>
-#include <stdexcept>
-//---------------------------------------------------------------------------
-#include <string>
-#include <iostream>
-#include <map>
-#include <vector>
-//---------------------------------------------------------------------------
-#include <boost/stm/detail/config.hpp>
-//---------------------------------------------------------------------------
-#include <boost/stm/datatypes.hpp>
-#ifdef PERFORMING_LATM
-#include <boost/stm/transaction.hpp>
-#else
-#endif
-//---------------------------------------------------------------------------
-
-
-//---------------------------------------------------------------------------
-#ifdef PERFORMING_LATM
-#define BOOST_STM_LOCK(a) boost::stm::transaction::lock_(a)
-#define BOOST_STM_UNLOCK(a) boost::stm::transaction::unlock_(a)
-#else
-#define BOOST_STM_LOCK(a) boost::synchro::lock(a)
-#define BOOST_STM_UNLOCK(a) boost::synchro::unlock(a)
-#endif
-
-//---------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-
-//---------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-class timer_lock_exception : public std::exception
-{
-public:
- timer_lock_exception(char const * const what) : what_(what) {}
-
- //virtual char const * what() const { return what_; }
-
-private:
- char const * const what_;
-};
-
-
-typedef timer_lock_exception timer_err;
-
-//---------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-class auto_lock
-{
-public:
- typedef std::pair<thread_id_t const, Mutex*> ThreadedLockPair;
- typedef std::multimap<thread_id_t const, Mutex*> ThreadedLockContainer;
- typedef ThreadedLockContainer::iterator ThreadedLockIter;
-
- auto_lock(Mutex &mutex) : hasLock_(false), lock_(0)
- {
- do_auto_lock(&mutex);
- }
-
- auto_lock(Mutex *mutex) : hasLock_(false), lock_(0)
- {
- do_auto_lock(mutex);
- }
-
-
- auto_lock(milliseconds_t timeOut, Mutex &mutex) : hasLock_(false), lock_(0)
- {
- do_timed_auto_lock(timeOut, &mutex);
- }
-
- auto_lock(milliseconds_t timeOut, Mutex *mutex) : hasLock_(false), lock_(0)
- {
- do_timed_auto_lock(timeOut, mutex);
- }
-
- ~auto_lock() { do_auto_unlock(); }
-
- bool has_lock() { return hasLock_; }
-
- void release_lock() { do_auto_unlock(); }
-
- static int VC6_fix()
- {
- static int VC6_fix = 0;
- return VC6_fix;
- }
-
-private:
-
- void do_timed_auto_lock(milliseconds_t timeOut, Mutex *mutex)
- {
- lock_ = mutex;
-
- if (thread_has_lock(mutex)) return;
-
- for (milliseconds_t i = 0; i < timeOut; ++i)
- {
- if (synchro::try_lock(*lock_))
- {
- hasLock_ = true;
- insert_into_threaded_lock_map(mutex);
- return;
- }
-
- SLEEP(1);
- }
-
- throw timer_lock_exception( "lock timed out" );
- }
-
- void insert_into_threaded_lock_map(Mutex* mutex)
- {
- synchro::lock_guard<Mutex> lock_i(*global_lock());
- threaded_locks().insert(ThreadedLockPair(this_thread::get_id(), mutex));
- }
-
- void do_auto_lock(Mutex *mutex)
- {
- lock_ = mutex;
- if (thread_has_lock(mutex)) return;
-
- BOOST_STM_LOCK(mutex);
- hasLock_ = true;
-
- insert_into_threaded_lock_map(mutex);
- }
-
- void do_auto_unlock()
- {
- if (hasLock_)
- {
- hasLock_ = false;
- BOOST_STM_UNLOCK(lock_);
- remove_thread_has_lock(lock_);
- }
- }
-
- bool thread_has_lock(Mutex *rhs)
- {
- synchro::lock_guard<Mutex> lock_g(*global_lock());
-
- for (ThreadedLockIter i = threaded_locks().begin();
- i != threaded_locks().end(); ++i)
- {
- if (i->first == this_thread::get_id() && i->second == rhs)
- {
- return true;
- }
- }
-
- return false;
- }
-
- void remove_thread_has_lock(Mutex *rhs)
- {
- synchro::lock_guard<Mutex> lock_g(*global_lock());
-
- for (ThreadedLockIter i = threaded_locks().begin();
- i != threaded_locks().end(); ++i)
- {
- if (i->first == this_thread::get_id() && i->second == rhs)
- {
- threaded_locks().erase(i);
- break;
- }
- }
- }
-
- static Mutex *global_lock()
- {
-#ifndef BOOST_STM_USE_BOOST_MUTEX
- static Mutex globalLock = PTHREAD_MUTEX_INITIALIZER;
-#else
- static Mutex globalLock;
-#endif
- return &globalLock;
- }
-
- static ThreadedLockContainer &threaded_locks()
- {
- static ThreadedLockContainer localThreadedLocks;
- return localThreadedLocks;
- }
-
- //auto_lock(auto_lock const &);
- //auto_lock& operator=(auto_lock const &);
-
- bool hasLock_;
- Mutex *lock_;
-};
-
-//---------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-#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 catch_lock_timeout(E) } catch (std::timer_lock_exception &E)
-#define lock_timeout } catch (std::timer_lock_exception &E)
-
-}}
-
-#endif // BOOST_STM_AUTO_LOCK_H
-
-
-
-
-
-
-
-
-

Added: sandbox/stm/branches/vbe/boost/stm/detail/move.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/detail/move.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_MOVE__HPP
+#define BOOST_STM_MOVE__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#if BUILD_MOVE_SEMANTICS
+#include <type_traits>
+#endif
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+#if BUILD_MOVE_SEMANTICS
+bool const kDracoMoveSemanticsCompiled = true;
+#else
+bool const kDracoMoveSemanticsCompiled = false;
+#endif
+
+#if BUILD_MOVE_SEMANTICS
+template <class T>
+inline typename std::remove_reference<T>::type&& draco_move(T &&t)
+{
+ return t;
+}
+#endif
+
+} // namespace core
+}
+#endif // BOOST_STM_DATATYPES__HPP
+
+

Deleted: sandbox/stm/branches/vbe/boost/stm/move.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/move.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,46 +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_MOVE__HPP
-#define BOOST_STM_MOVE__HPP
-
-//-----------------------------------------------------------------------------
-#include <boost/stm/detail/config.hpp>
-//-----------------------------------------------------------------------------
-#if BUILD_MOVE_SEMANTICS
-#include <type_traits>
-#endif
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-#if BUILD_MOVE_SEMANTICS
-bool const kDracoMoveSemanticsCompiled = true;
-#else
-bool const kDracoMoveSemanticsCompiled = false;
-#endif
-
-#if BUILD_MOVE_SEMANTICS
-template <class T>
-inline typename std::remove_reference<T>::type&& draco_move(T &&t)
-{
- return t;
-}
-#endif
-
-} // namespace core
-}
-#endif // BOOST_STM_DATATYPES__HPP
-
-

Deleted: sandbox/stm/branches/vbe/boost/stm/select_contention_manager.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/select_contention_manager.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,145 +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_SELECT_CONTENTION_MANAGER__HPP
-#define BOOST_STM_SELECT_CONTENTION_MANAGER__HPP
-
-//-----------------------------------------------------------------------------
-#include <boost/stm/detail/config.hpp>
-//-----------------------------------------------------------------------------
-
-#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/contention_managers/except_and_back_off_on_abort_notice_cm.hpp>
-#else
-#include BOOST_STM_CM_STATIC_CONF
-//#include <boost/stm/contention_managers/default.hpp>
-#endif
-#else
-#if defined(BOOST_STM_CM_DYNAMIC_CONF)
-#include <boost/stm/contention_managers/polymorphic.hpp>
-#endif
-#endif
-
-namespace boost { namespace stm {
-
-
-#if defined(BOOST_STM_CM_STATIC_CONF)
- inline static contention_manager_type* get_contention_manager() {
- static contention_manager_type cm_;return &cm_;
- }
- inline static void cm_abort_on_new(transaction const &t) {
- return contention_manager_type::abort_on_new(t);
- }
- inline static void cm_abort_on_delete(transaction const &t,
- base_transaction_object const &in) {
- return contention_manager_type::abort_on_delete(t,in);
- }
-
- inline static void cm_abort_on_read(transaction const &t,
- base_transaction_object const &in) {
- return contention_manager_type::abort_on_read(t,in);
- }
- inline static void cm_abort_on_write(transaction &t,
- base_transaction_object const &in) {
- return contention_manager_type::abort_on_write(t,in);
- }
-
- inline static bool cm_abort_before_commit(transaction const &t) {
- return contention_manager_type::abort_before_commit(t);
- }
-
- inline static bool cm_permission_to_abort(transaction const &lhs, transaction const &rhs) {
- return contention_manager_type::permission_to_abort(lhs,rhs);
- }
-
- inline static bool cm_permission_to_abort(transaction const &lhs, std::list<transaction*> &rhs) {
- return contention_manager_type::permission_to_abort(lhs,rhs);
- }
-
- inline static bool cm_allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
- bool txIsIrrevocable, transaction const &rhs) {
- return contention_manager_type::allow_lock_to_abort_tx(lockWaitTime,lockAborted,txIsIrrevocable,rhs);
- }
-
- inline static int cm_lock_sleep_time() {
- return contention_manager_type::lock_sleep_time();
- }
-
- inline static void cm_perform_isolated_tx_wait_priority_promotion(transaction &t) {
- return contention_manager_type::perform_isolated_tx_wait_priority_promotion(t);
- }
- inline static void cm_perform_irrevocable_tx_wait_priority_promotion(transaction &t) {
- return contention_manager_type::perform_irrevocable_tx_wait_priority_promotion(t);
- }
-
-#else
- struct poly_contention_manager {
- static base_contention_manager *cm_;
- };
- inline static void contention_manager(base_contention_manager *rhs) {
- delete poly_contention_manager::cm_; poly_contention_manager::cm_ = rhs;
- }
- inline static base_contention_manager* get_contention_manager() {
- return poly_contention_manager::cm_;
- }
- inline static base_contention_manager* get_cm() {
- return poly_contention_manager::cm_;
- }
-
- inline static void cm_abort_on_new(transaction const &t) {
- return get_cm()->abort_on_new(t);
- }
- inline static void cm_abort_on_delete(transaction const &t, base_transaction_object const &in) {
- return get_cm()->abort_on_delete(t,in);
- }
-
- inline static void cm_abort_on_read(transaction const &t, base_transaction_object const &in) {
- return get_cm()->abort_on_read(t,in);
- }
- inline static void cm_abort_on_write(transaction &t, base_transaction_object const &in) {
- return get_cm()->abort_on_write(t,in);
- }
-
- inline static bool cm_abort_before_commit(transaction const &t) {
- return get_cm()->abort_before_commit(t);
- }
-
- inline static bool cm_permission_to_abort(transaction const &lhs, transaction const &rhs) {
- return get_cm()->permission_to_abort(lhs,rhs);
- }
-
- inline static bool cm_permission_to_abort(transaction const &lhs, std::list<transaction*> &rhs) {
- return get_cm()->permission_to_abort(lhs,rhs);
- }
-
- inline static bool cm_allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
- bool txIsIrrevocable, transaction const &rhs) {
- return get_cm()->allow_lock_to_abort_tx(lockWaitTime,lockAborted,txIsIrrevocable,rhs); }
-
- inline static int cm_lock_sleep_time() {
- return get_cm()->lock_sleep_time();
- }
-
- inline static void cm_perform_isolated_tx_wait_priority_promotion(transaction &t) {
- return get_cm()->perform_isolated_tx_wait_priority_promotion(t);
- }
- inline static void cm_perform_irrevocable_tx_wait_priority_promotion(transaction &t) {
- return get_cm()->perform_irrevocable_tx_wait_priority_promotion(t);
- }
-
-#endif
-
-
-}}
-#endif // CONTENTION_MANAGER_H

Deleted: sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,167 +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_SHALLOW_TRANSACTION_OBJECT__HPP
-#define BOOST_STM_SHALLOW_TRANSACTION_OBJECT__HPP
-
-//-----------------------------------------------------------------------------
-//#include <stdarg.h>
-#include <pthread.h>
-//-----------------------------------------------------------------------------
-#include <list>
-//-----------------------------------------------------------------------------
-#include <boost/stm/detail/config.hpp>
-//-----------------------------------------------------------------------------
-#include <boost/stm/base_transaction_object.hpp>
-#include <boost/stm/cache_fct.hpp>
-#include <boost/stm/datatypes.hpp>
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class transaction;
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-// transaction object mixin making shallow copy
-// Provides the definition of the virtual functions
-// clone: use copy constructor
-// copy_state: use assignement
-// move_state and
-// cache_deallocate: use delete
-// Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
-
-// The parameter Base=base_transaction_object allows to mic transaction_object and polymorphism
-// class B : transaction_object<B> {}
-// class D : transaction_object<D, B> {}
-// the single issue is the forward constructors from transaction_object<D, B> to B
-//-----------------------------------------------------------------------------
-
-template <class Derived, typename Base=base_transaction_object>
-class shallow_transaction_object : public base_transaction_object
-{
-public:
-
- //--------------------------------------------------------------------------
- virtual base_transaction_object* clone(transaction* t) const {
- Derived* tmp = cache_clone(t, *static_cast<Derived const*>(this));
- return tmp;
- }
-
- //--------------------------------------------------------------------------
- virtual void cache_deallocate() {
- boost::stm::cache_deallocate(this);
- }
-
- //--------------------------------------------------------------------------
- virtual void copy_state(base_transaction_object const * const rhs)
- {
- boost::stm::cache_copy(static_cast<Derived const * const>(rhs), static_cast<Derived *>(this));
- }
-
-#if BUILD_MOVE_SEMANTICS
- virtual void move_state(base_transaction_object * rhs)
- {
- static_cast<Derived &>(*this) = draco_move
- (*(static_cast<Derived*>(rhs)));
- }
-#endif
-
-
-#if USE_STM_MEMORY_MANAGER
- void* operator new(std::size_t size, const std::nothrow_t&) throw ()
- {
- return retrieve_mem(size);
- }
- void* operator new(std::size_t size) throw (std::bad_alloc)
- {
- void* ptr= retrieve_mem(size);
- if (ptr==0) throw std::bad_alloc;
- return ptr;
- }
-
- void operator delete(void* mem) throw ()
- {
- static Derived elem;
- static std::size_t elemSize = sizeof(elem);
- return_mem(mem, elemSize);
- }
-#endif
-
-};
-
-template <typename T> class shallow_native_trans :
-public shallow_transaction_object< shallow_native_trans<T> >
-{
-public:
-
- shallow_native_trans() : value_(T()) {}
- shallow_native_trans(T const &rhs) : value_(rhs) {}
- shallow_native_trans(shallow_native_trans const &rhs) : value_(rhs.value_) {}
- ~shallow_native_trans() {}
-
- shallow_native_trans& operator=(T const &rhs) { value_ = rhs; return *this; }
-
- shallow_native_trans& operator--() { --value_; return *this; }
- shallow_native_trans operator--(int) { shallow_native_trans n = *this; --value_; return n; }
-
- shallow_native_trans& operator++() { ++value_; return *this; }
- shallow_native_trans operator++(int) { shallow_native_trans n = *this; ++value_; return n; }
-
- shallow_native_trans& operator+=(T const &rhs)
- {
- value_ += rhs;
- return *this;
- }
-
- shallow_native_trans operator+(shallow_native_trans const &rhs)
- {
- shallow_native_trans ret = *this;
- ret.value_ += rhs.value_;
- return ret;
- }
-
- //template <>
- operator T() const
- {
- return this->value_;
- }
-
-#if BUILD_MOVE_SEMANTICS
- //--------------------------------------------------
- // move semantics
- //--------------------------------------------------
- shallow_native_trans(shallow_native_trans &&rhs) { value_ = rhs.value_;}
- shallow_native_trans& operator=(shallow_native_trans &&rhs)
- { value_ = rhs.value_; return *this; }
-#endif
-
- T& value() { return value_; }
- T const & value() const { return value_; }
-
-private:
- T value_;
-};
-
-}}
-#endif // BOOST_STM_SHALLOW_TRANSACTION_OBJECT__HPP
-
-

Added: sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,234 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_SYNC_AUTO_LOCK_H
+#define BOOST_STM_SYNC_AUTO_LOCK_H
+
+//---------------------------------------------------------------------------
+#include <pthread.h>
+#include <stdexcept>
+//---------------------------------------------------------------------------
+#include <string>
+#include <iostream>
+#include <map>
+#include <vector>
+//---------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//---------------------------------------------------------------------------
+#include <boost/stm/datatypes.hpp>
+#ifdef PERFORMING_LATM
+#include <boost/stm/transaction.hpp>
+#else
+#endif
+//---------------------------------------------------------------------------
+
+
+//---------------------------------------------------------------------------
+#ifdef PERFORMING_LATM
+#define BOOST_STM_LOCK(a) boost::stm::transaction::lock_(a)
+#define BOOST_STM_UNLOCK(a) boost::stm::transaction::unlock_(a)
+#else
+#define BOOST_STM_LOCK(a) boost::synchro::lock(a)
+#define BOOST_STM_UNLOCK(a) boost::synchro::unlock(a)
+#endif
+
+//---------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+
+//---------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class timer_lock_exception : public std::exception
+{
+public:
+ timer_lock_exception(char const * const what) : what_(what) {}
+
+ //virtual char const * what() const { return what_; }
+
+private:
+ char const * const what_;
+};
+
+
+typedef timer_lock_exception timer_err;
+
+//---------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class auto_lock
+{
+public:
+ typedef std::pair<thread_id_t const, Mutex*> ThreadedLockPair;
+ typedef std::multimap<thread_id_t const, Mutex*> ThreadedLockContainer;
+ typedef ThreadedLockContainer::iterator ThreadedLockIter;
+
+ auto_lock(Mutex &mutex) : hasLock_(false), lock_(0)
+ {
+ do_auto_lock(&mutex);
+ }
+
+ auto_lock(Mutex *mutex) : hasLock_(false), lock_(0)
+ {
+ do_auto_lock(mutex);
+ }
+
+
+ auto_lock(milliseconds_t timeOut, Mutex &mutex) : hasLock_(false), lock_(0)
+ {
+ do_timed_auto_lock(timeOut, &mutex);
+ }
+
+ auto_lock(milliseconds_t timeOut, Mutex *mutex) : hasLock_(false), lock_(0)
+ {
+ do_timed_auto_lock(timeOut, mutex);
+ }
+
+ ~auto_lock() { do_auto_unlock(); }
+
+ bool has_lock() { return hasLock_; }
+
+ void release_lock() { do_auto_unlock(); }
+
+ static int VC6_fix()
+ {
+ static int VC6_fix = 0;
+ return VC6_fix;
+ }
+
+private:
+
+ void do_timed_auto_lock(milliseconds_t timeOut, Mutex *mutex)
+ {
+ lock_ = mutex;
+
+ if (thread_has_lock(mutex)) return;
+
+ for (milliseconds_t i = 0; i < timeOut; ++i)
+ {
+ if (synchro::try_lock(*lock_))
+ {
+ hasLock_ = true;
+ insert_into_threaded_lock_map(mutex);
+ return;
+ }
+
+ SLEEP(1);
+ }
+
+ throw timer_lock_exception( "lock timed out" );
+ }
+
+ void insert_into_threaded_lock_map(Mutex* mutex)
+ {
+ synchro::lock_guard<Mutex> lock_i(*global_lock());
+ threaded_locks().insert(ThreadedLockPair(this_thread::get_id(), mutex));
+ }
+
+ void do_auto_lock(Mutex *mutex)
+ {
+ lock_ = mutex;
+ if (thread_has_lock(mutex)) return;
+
+ BOOST_STM_LOCK(mutex);
+ hasLock_ = true;
+
+ insert_into_threaded_lock_map(mutex);
+ }
+
+ void do_auto_unlock()
+ {
+ if (hasLock_)
+ {
+ hasLock_ = false;
+ BOOST_STM_UNLOCK(lock_);
+ remove_thread_has_lock(lock_);
+ }
+ }
+
+ bool thread_has_lock(Mutex *rhs)
+ {
+ synchro::lock_guard<Mutex> lock_g(*global_lock());
+
+ for (ThreadedLockIter i = threaded_locks().begin();
+ i != threaded_locks().end(); ++i)
+ {
+ if (i->first == this_thread::get_id() && i->second == rhs)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ void remove_thread_has_lock(Mutex *rhs)
+ {
+ synchro::lock_guard<Mutex> lock_g(*global_lock());
+
+ for (ThreadedLockIter i = threaded_locks().begin();
+ i != threaded_locks().end(); ++i)
+ {
+ if (i->first == this_thread::get_id() && i->second == rhs)
+ {
+ threaded_locks().erase(i);
+ break;
+ }
+ }
+ }
+
+ static Mutex *global_lock()
+ {
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+ static Mutex globalLock = PTHREAD_MUTEX_INITIALIZER;
+#else
+ static Mutex globalLock;
+#endif
+ return &globalLock;
+ }
+
+ static ThreadedLockContainer &threaded_locks()
+ {
+ static ThreadedLockContainer localThreadedLocks;
+ return localThreadedLocks;
+ }
+
+ //auto_lock(auto_lock const &);
+ //auto_lock& operator=(auto_lock const &);
+
+ bool hasLock_;
+ Mutex *lock_;
+};
+
+//---------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#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 catch_lock_timeout(E) } catch (std::timer_lock_exception &E)
+#define lock_timeout } catch (std::timer_lock_exception &E)
+
+}}
+
+#endif // BOOST_STM_AUTO_LOCK_H
+
+
+
+
+
+
+
+
+

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-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -32,13 +32,13 @@
 //-----------------------------------------------------------------------------
 #include <boost/stm/base_transaction.hpp>
 #include <boost/stm/datatypes.hpp>
-#include <boost/stm/move.hpp>
 #include <boost/stm/transaction_bookkeeping.hpp>
-#include <boost/stm/select_contention_manager.hpp>
+#include <boost/stm/contention_managers/select_contention_manager.hpp>
 //-----------------------------------------------------------------------------
 #include <boost/stm/detail/bloom_filter.hpp>
 #include <boost/stm/detail/deleters.hpp>
 #include <boost/stm/detail/monotonic_storage.hpp>
+#include <boost/stm/detail/move.hpp>
 #include <boost/stm/detail/transactions_stack.hpp>
 #include <boost/stm/detail/vector_map.hpp>
 #include <boost/stm/detail/vector_set.hpp>
@@ -2089,14 +2089,8 @@
 
 #include <boost/stm/detail/transaction_impl.hpp>
 #include <boost/stm/detail/latm_general_impl.hpp>
-#include <boost/stm/detail/auto_lock.hpp>
-#include <boost/stm/tx_ptr.hpp>
-
-#if defined(BOOST_STM_CM_STATIC_CONF)
-#if defined(BOOST_STM_CM_STATIC_CONF_ExceptAndBackOffOnAbortNoticeCM)
-#include <boost/stm/detail/except_and_back_off_on_abort_notice_cm_impl.hpp>
-#endif
-#endif
+//#include <boost/stm/synch/auto_lock.hpp>
+//#include <boost/stm/tx_ptr.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 #endif // BOOST_STM_TRANSACTION__HPP

Deleted: sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,228 +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_TRANSACTIONAL_OBJECT__HPP
-#define BOOST_STM_TRANSACTIONAL_OBJECT__HPP
-
-#include <boost/stm/base_transaction.hpp>
-
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-//-----------------------------------------------------------------------------
-// transactional object wrapper
-// A transactional_object<T> is a base_transaction_object wrapping an instance of type T
-// Provides the definition of the virtual functions
-// forward constructors to the wrapped type
-// copy_state: relaying on the cache_copy<T> generic function
-// move_state and
-// cache_deallocate: relaying on the cache_copy<T> generic function
-// Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
-//
-// If a class D inherits from B we have that transactional_object<D> dont inherits from transactional_object<B>, but
-// we can static/dynamic cast them robustly.
-// Evidently the std::static_cast/std::dynamic_cast do not works. We need to define the specific cast
-//
-// transactional_object<D>* d=...;
-// transactional_object<B>* b=tx_static_cast<B>(d);
-//
-// transactional_object<B>* b=...;
-// transactional_object<D>* d=tx_dynamic_cast<B>(b);
-//
-//-----------------------------------------------------------------------------
-
-template <typename T>
-class transactional_object : public base_transaction_object {
-public:
- T value;
-
- transactional_object() {}
- transactional_object(const T*ptr)
- : base_transaction_object()
- , value(*ptr) {}
-
- transactional_object(transactional_object<T> const & r)
- : base_transaction_object(r)
- , value(r.value) {}
-
- template <typename T1>
- transactional_object(T1 const &p1)
- : base_transaction_object()
- , value(p1) {}
-
- template <typename T1, typename T2>
- transactional_object(T1 const &p1, T2 const &p2)
- : base_transaction_object()
- , value(p1,p2) {}
-
- transactional_object & operator=(transactional_object const & r) // =default never throws
- {
- value = r.value;
- return *this;
- }
-
-#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- virtual base_transaction_object* clone(transaction* t) const {
- transactional_object<T>* p = cache_allocate<transactional_object<T> >(t);
- if (p==0) {
- throw std::bad_alloc();
- }
- ::new (p) transactional_object<T>(*static_cast<transactional_object<T> const*>(this));
- return p;
- }
-#else
- virtual base_transaction_object* clone(transaction*) const {
- //return cache_clone(*this);
- return new transactional_object<T>(*this);
- }
-#endif
-
-#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- virtual void cache_deallocate() {
- static_cast<transactional_object<T>*>(this)->~transactional_object<T>();
- boost::stm::cache_deallocate(this);
- }
-#else
- virtual void cache_deallocate() {
- delete this;
- }
-#endif
-
- virtual void copy_state(base_transaction_object const * const rhs) {
- //cache_copy(static_cast<transactional_object<T> const * const>(rhs), this);
- *this=*static_cast<transactional_object<T> const * const>(rhs);
- }
-
- #if USE_STM_MEMORY_MANAGER
- void* operator new(std::size_t size, const std::nothrow_t&) throw ()
- {
- return retrieve_mem(size);
- }
- void* operator new(std::size_t size) throw (std::bad_alloc)
- {
- void* ptr= retrieve_mem(size);
- if (ptr==0) throw std::bad_alloc;
- return ptr;
- }
-
- void operator delete(void* mem) throw ()
- {
- static transactional_object<T> elem;
- static std::size_t elemSize = sizeof(elem);
- return_mem(mem, elemSize);
- }
- #endif
-
-};
-
-//-----------------------------------------------------------------------------
-// gets the transactional_object<T> pointer wrapping the T pointer
-//-----------------------------------------------------------------------------
-template <typename T>
-static transactional_object<T>* tx_up_cast(T* ptr) {
- return reinterpret_cast<transactional_object<T>*>(reinterpret_cast<char*>(ptr)-offsetof(transactional_object<T>, value));
-}
-
-//-----------------------------------------------------------------------------
-// static_cast two transactional_object's
-//-----------------------------------------------------------------------------
-template <typename T, typename U>
-static transactional_object<T>* tx_static_cast(transactional_object<U>* ptr) {
- return tx_up_cast(static_cast<T*>(&ptr->value));
-}
-
-//-----------------------------------------------------------------------------
-// dynamic_cast two transactional_object's
-//-----------------------------------------------------------------------------
-template <typename T, typename U>
-static transactional_object<T>* tx_dynamic_cast(transactional_object<U>* ptr) {
- T* p = dynamic_cast<T*>(&ptr->value);
- if (p==0) return 0;
- return tx_up_cast(p);
-}
-
-
-
-#ifdef BOOST_STM_USE_MEMCOPY
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-
-template <class T, class A>
-struct cache_clone<transactional_object<std::vector<T,A> > > {
- static inline transactional_object<std::vector<T,A> >* apply(const transactional_object<std::vector<T,A> >& val) {
- return new transactional_object<std::vector<T,A> >(val);
- }
-};
-} // partial_specialization_workaround
-
-#else //BOOST_STM_NO_PARTIAL_SPECIALIZATION
-
-template <class T>
-inline transactional_object<std::vector<T> >* cache_clone(const transactional_object<std::vector<T> >& val) {
- return new transactional_object<std::vector<T> >(val);
-}
-
-#endif // BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#endif
-
-
-
-#ifdef BOOST_STM_USE_MEMCOPY
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-
-template <class T>
-struct cache_copy<transactional_object<std::vector<T> > > {
- static inline void apply(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
- *target=*ori;
- }
-};
-
-} // partial_specialization_workaround
-#else
-template <class T> void cache_copy(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
- *target=*ori;
-}
-#endif
-#endif
-
-
-#ifdef BOOST_STM_USE_MEMCOPY
-#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-namespace partial_specialization_workaround {
-
-template <class T>
-struct cache_deallocate<transactional_object<std::vector<T> > > {
- static void apply(transactional_object<std::vector<T> >* ptr) {
- delete ptr;
- }
-};
-
-}
-
-#else //!BOOST_STM_NO_PARTIAL_SPECIALIZATION
-
-template <class T>
-inline void cache_deallocate(transactional_object<std::vector<T> >* ptr) {
- delete ptr;
-}
-
-#endif //BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#endif // BOOST_STM_USE_MEMCOPY
-
-
-} // namespace core
-}
-#endif // BASE_TRANSACTION_H
-
-

Added: sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,22 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_DEEP_TRANSACTION_OBJECT__HPP
+#define BOOST_STM_TX_DEEP_TRANSACTION_OBJECT__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction_object.hpp>
+//-----------------------------------------------------------------------------
+#endif // BOOST_STM_SHALLOW_TRANSACTION_OBJECT__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,167 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_SHALLOW_TRANSACTION_OBJECT__HPP
+#define BOOST_STM_TX_SHALLOW_TRANSACTION_OBJECT__HPP
+
+//-----------------------------------------------------------------------------
+//#include <stdarg.h>
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/base_transaction_object.hpp>
+#include <boost/stm/cache_fct.hpp>
+#include <boost/stm/datatypes.hpp>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// forward declarations
+//-----------------------------------------------------------------------------
+class transaction;
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// transaction object mixin making shallow copy
+// Provides the definition of the virtual functions
+// clone: use copy constructor
+// copy_state: use assignement
+// move_state and
+// cache_deallocate: use delete
+// Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
+
+// The parameter Base=base_transaction_object allows to mic transaction_object and polymorphism
+// class B : transaction_object<B> {}
+// class D : transaction_object<D, B> {}
+// the single issue is the forward constructors from transaction_object<D, B> to B
+//-----------------------------------------------------------------------------
+
+template <class Derived, typename Base=base_transaction_object>
+class shallow_transaction_object : public base_transaction_object
+{
+public:
+
+ //--------------------------------------------------------------------------
+ virtual base_transaction_object* clone(transaction* t) const {
+ Derived* tmp = cache_clone(t, *static_cast<Derived const*>(this));
+ return tmp;
+ }
+
+ //--------------------------------------------------------------------------
+ virtual void cache_deallocate() {
+ boost::stm::cache_deallocate(this);
+ }
+
+ //--------------------------------------------------------------------------
+ virtual void copy_state(base_transaction_object const * const rhs)
+ {
+ boost::stm::cache_copy(static_cast<Derived const * const>(rhs), static_cast<Derived *>(this));
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ virtual void move_state(base_transaction_object * rhs)
+ {
+ static_cast<Derived &>(*this) = draco_move
+ (*(static_cast<Derived*>(rhs)));
+ }
+#endif
+
+
+#if USE_STM_MEMORY_MANAGER
+ void* operator new(std::size_t size, const std::nothrow_t&) throw ()
+ {
+ return retrieve_mem(size);
+ }
+ void* operator new(std::size_t size) throw (std::bad_alloc)
+ {
+ void* ptr= retrieve_mem(size);
+ if (ptr==0) throw std::bad_alloc;
+ return ptr;
+ }
+
+ void operator delete(void* mem) throw ()
+ {
+ static Derived elem;
+ static std::size_t elemSize = sizeof(elem);
+ return_mem(mem, elemSize);
+ }
+#endif
+
+};
+
+template <typename T> class shallow_native_trans :
+public shallow_transaction_object< shallow_native_trans<T> >
+{
+public:
+
+ shallow_native_trans() : value_(T()) {}
+ shallow_native_trans(T const &rhs) : value_(rhs) {}
+ shallow_native_trans(shallow_native_trans const &rhs) : value_(rhs.value_) {}
+ ~shallow_native_trans() {}
+
+ shallow_native_trans& operator=(T const &rhs) { value_ = rhs; return *this; }
+
+ shallow_native_trans& operator--() { --value_; return *this; }
+ shallow_native_trans operator--(int) { shallow_native_trans n = *this; --value_; return n; }
+
+ shallow_native_trans& operator++() { ++value_; return *this; }
+ shallow_native_trans operator++(int) { shallow_native_trans n = *this; ++value_; return n; }
+
+ shallow_native_trans& operator+=(T const &rhs)
+ {
+ value_ += rhs;
+ return *this;
+ }
+
+ shallow_native_trans operator+(shallow_native_trans const &rhs)
+ {
+ shallow_native_trans ret = *this;
+ ret.value_ += rhs.value_;
+ return ret;
+ }
+
+ //template <>
+ operator T() const
+ {
+ return this->value_;
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ //--------------------------------------------------
+ // move semantics
+ //--------------------------------------------------
+ shallow_native_trans(shallow_native_trans &&rhs) { value_ = rhs.value_;}
+ shallow_native_trans& operator=(shallow_native_trans &&rhs)
+ { value_ = rhs.value_; return *this; }
+#endif
+
+ T& value() { return value_; }
+ T const & value() const { return value_; }
+
+private:
+ T value_;
+};
+
+}}
+#endif // BOOST_STM_SHALLOW_TRANSACTION_OBJECT__HPP
+
+

Deleted: sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
+++ (empty file)
@@ -1,580 +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_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=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=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=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=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 = 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 = 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) {
- std::cout << __LINE__ << " ptr_ " << ptr_ << std::endl;
- if (ptr_!=0) {
- std::cout << __LINE__ << " ptr_->value" << ptr_->value << std::endl;
- std::cout << __LINE__ << " &ptr_->value" << &ptr_->value << std::endl;
- }
- }
-
- template<class Y>
- upgrd_ptr & operator=(tx_ptr<Y> const& r) { // never throws
- //this_type(r).swap(*this);
- transaction* tx=current_transaction();
- if (tx==0) throw "error";
- tx_=tx;
- ptr_=r.ptr_;
- written_=false;
- return *this;
- }
-
- const T* get() const {
- std::cout << __LINE__ << " ptr_" << ptr_ << std::endl;
- if (ptr_==0) return 0;
- 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;
- }
- }
-
- std::cout << __LINE__ << " ptr_" << ptr_ << std::endl;
- if (ptr_!=0) {
- std::cout << __LINE__ << " ptr_->value" << ptr_->value << std::endl;
- std::cout << __LINE__ << " &ptr_->value" << &ptr_->value << std::endl;
- }
- if (ptr_==0) return 0;
- 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 = 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
-
-

Added: sandbox/stm/branches/vbe/boost/stm/txw/smart_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/txw/smart_ptr.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,580 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TXW_SMART_PTR__HPP
+#define BOOST_STM_TXW_SMART_PTR__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <assert.h>
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/txw/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=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=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=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=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 = 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 = 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) {
+ std::cout << __LINE__ << " ptr_ " << ptr_ << std::endl;
+ if (ptr_!=0) {
+ std::cout << __LINE__ << " ptr_->value" << ptr_->value << std::endl;
+ std::cout << __LINE__ << " &ptr_->value" << &ptr_->value << std::endl;
+ }
+ }
+
+ template<class Y>
+ upgrd_ptr & operator=(tx_ptr<Y> const& r) { // never throws
+ //this_type(r).swap(*this);
+ transaction* tx=current_transaction();
+ if (tx==0) throw "error";
+ tx_=tx;
+ ptr_=r.ptr_;
+ written_=false;
+ return *this;
+ }
+
+ const T* get() const {
+ std::cout << __LINE__ << " ptr_" << ptr_ << std::endl;
+ if (ptr_==0) return 0;
+ 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;
+ }
+ }
+
+ std::cout << __LINE__ << " ptr_" << ptr_ << std::endl;
+ if (ptr_!=0) {
+ std::cout << __LINE__ << " ptr_->value" << ptr_->value << std::endl;
+ std::cout << __LINE__ << " &ptr_->value" << &ptr_->value << std::endl;
+ }
+ if (ptr_==0) return 0;
+ 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 = 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
+
+

Added: sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/txw/transactional_object.hpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,228 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TXW_TRANSACTIONAL_OBJECT__HPP
+#define BOOST_STM_TXW_TRANSACTIONAL_OBJECT__HPP
+
+#include <boost/stm/base_transaction.hpp>
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// transactional object wrapper
+// A transactional_object<T> is a base_transaction_object wrapping an instance of type T
+// Provides the definition of the virtual functions
+// forward constructors to the wrapped type
+// copy_state: relaying on the cache_copy<T> generic function
+// move_state and
+// cache_deallocate: relaying on the cache_copy<T> generic function
+// Defines in addition the functions new and delete when USE_STM_MEMORY_MANAGER is defined
+//
+// If a class D inherits from B we have that transactional_object<D> dont inherits from transactional_object<B>, but
+// we can static/dynamic cast them robustly.
+// Evidently the std::static_cast/std::dynamic_cast do not works. We need to define the specific cast
+//
+// transactional_object<D>* d=...;
+// transactional_object<B>* b=tx_static_cast<B>(d);
+//
+// transactional_object<B>* b=...;
+// transactional_object<D>* d=tx_dynamic_cast<B>(b);
+//
+//-----------------------------------------------------------------------------
+
+template <typename T>
+class transactional_object : public base_transaction_object {
+public:
+ T value;
+
+ transactional_object() {}
+ transactional_object(const T*ptr)
+ : base_transaction_object()
+ , value(*ptr) {}
+
+ transactional_object(transactional_object<T> const & r)
+ : base_transaction_object(r)
+ , value(r.value) {}
+
+ template <typename T1>
+ transactional_object(T1 const &p1)
+ : base_transaction_object()
+ , value(p1) {}
+
+ template <typename T1, typename T2>
+ transactional_object(T1 const &p1, T2 const &p2)
+ : base_transaction_object()
+ , value(p1,p2) {}
+
+ transactional_object & operator=(transactional_object const & r) // =default never throws
+ {
+ value = r.value;
+ return *this;
+ }
+
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual base_transaction_object* clone(transaction* t) const {
+ transactional_object<T>* p = cache_allocate<transactional_object<T> >(t);
+ if (p==0) {
+ throw std::bad_alloc();
+ }
+ ::new (p) transactional_object<T>(*static_cast<transactional_object<T> const*>(this));
+ return p;
+ }
+#else
+ virtual base_transaction_object* clone(transaction*) const {
+ //return cache_clone(*this);
+ return new transactional_object<T>(*this);
+ }
+#endif
+
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual void cache_deallocate() {
+ static_cast<transactional_object<T>*>(this)->~transactional_object<T>();
+ boost::stm::cache_deallocate(this);
+ }
+#else
+ virtual void cache_deallocate() {
+ delete this;
+ }
+#endif
+
+ virtual void copy_state(base_transaction_object const * const rhs) {
+ //cache_copy(static_cast<transactional_object<T> const * const>(rhs), this);
+ *this=*static_cast<transactional_object<T> const * const>(rhs);
+ }
+
+ #if USE_STM_MEMORY_MANAGER
+ void* operator new(std::size_t size, const std::nothrow_t&) throw ()
+ {
+ return retrieve_mem(size);
+ }
+ void* operator new(std::size_t size) throw (std::bad_alloc)
+ {
+ void* ptr= retrieve_mem(size);
+ if (ptr==0) throw std::bad_alloc;
+ return ptr;
+ }
+
+ void operator delete(void* mem) throw ()
+ {
+ static transactional_object<T> elem;
+ static std::size_t elemSize = sizeof(elem);
+ return_mem(mem, elemSize);
+ }
+ #endif
+
+};
+
+//-----------------------------------------------------------------------------
+// gets the transactional_object<T> pointer wrapping the T pointer
+//-----------------------------------------------------------------------------
+template <typename T>
+static transactional_object<T>* tx_up_cast(T* ptr) {
+ return reinterpret_cast<transactional_object<T>*>(reinterpret_cast<char*>(ptr)-offsetof(transactional_object<T>, value));
+}
+
+//-----------------------------------------------------------------------------
+// static_cast two transactional_object's
+//-----------------------------------------------------------------------------
+template <typename T, typename U>
+static transactional_object<T>* tx_static_cast(transactional_object<U>* ptr) {
+ return tx_up_cast(static_cast<T*>(&ptr->value));
+}
+
+//-----------------------------------------------------------------------------
+// dynamic_cast two transactional_object's
+//-----------------------------------------------------------------------------
+template <typename T, typename U>
+static transactional_object<T>* tx_dynamic_cast(transactional_object<U>* ptr) {
+ T* p = dynamic_cast<T*>(&ptr->value);
+ if (p==0) return 0;
+ return tx_up_cast(p);
+}
+
+
+
+#ifdef BOOST_STM_USE_MEMCOPY
+#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
+namespace partial_specialization_workaround {
+
+template <class T, class A>
+struct cache_clone<transactional_object<std::vector<T,A> > > {
+ static inline transactional_object<std::vector<T,A> >* apply(const transactional_object<std::vector<T,A> >& val) {
+ return new transactional_object<std::vector<T,A> >(val);
+ }
+};
+} // partial_specialization_workaround
+
+#else //BOOST_STM_NO_PARTIAL_SPECIALIZATION
+
+template <class T>
+inline transactional_object<std::vector<T> >* cache_clone(const transactional_object<std::vector<T> >& val) {
+ return new transactional_object<std::vector<T> >(val);
+}
+
+#endif // BOOST_STM_NO_PARTIAL_SPECIALIZATION
+#endif
+
+
+
+#ifdef BOOST_STM_USE_MEMCOPY
+#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
+namespace partial_specialization_workaround {
+
+template <class T>
+struct cache_copy<transactional_object<std::vector<T> > > {
+ static inline void apply(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
+ *target=*ori;
+ }
+};
+
+} // partial_specialization_workaround
+#else
+template <class T> void cache_copy(const transactional_object<std::vector<T> >* const ori, transactional_object<std::vector<T> >* target) {
+ *target=*ori;
+}
+#endif
+#endif
+
+
+#ifdef BOOST_STM_USE_MEMCOPY
+#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
+namespace partial_specialization_workaround {
+
+template <class T>
+struct cache_deallocate<transactional_object<std::vector<T> > > {
+ static void apply(transactional_object<std::vector<T> >* ptr) {
+ delete ptr;
+ }
+};
+
+}
+
+#else //!BOOST_STM_NO_PARTIAL_SPECIALIZATION
+
+template <class T>
+inline void cache_deallocate(transactional_object<std::vector<T> >* ptr) {
+ delete ptr;
+}
+
+#endif //BOOST_STM_NO_PARTIAL_SPECIALIZATION
+#endif // BOOST_STM_USE_MEMCOPY
+
+
+} // namespace core
+}
+#endif // BASE_TRANSACTION_H
+
+

Modified: sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -12,7 +12,7 @@
 //////////////////////////////////////////////////////////////////////////////
 
 #include <boost/stm/transaction.hpp>
-#include <boost/stm/non_tx/smart_ptr.hpp>
+#include <boost/stm/non_tx/detail/cache_map.hpp>
 #include <boost/stm/contention_manager.hpp>
 #include <iostream>
 

Modified: sandbox/stm/branches/vbe/libs/stm/test/smart.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/smart.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/smart.cpp 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -14,6 +14,7 @@
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 #include <boost/stm/transaction.hpp>
+#include <boost/stm/tx_ptr.hpp>
 #include "smart.h"
 #include "main.h"
 

Modified: sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h 2009-10-23 14:22:47 EDT (Fri, 23 Oct 2009)
@@ -18,6 +18,7 @@
 #include "main.h"
 #include "testHT_latm.h"
 #include <boost/stm/transaction.hpp>
+#include <boost/stm/synch/auto_lock.hpp>
 #include <pthread.h>
 
 #include <fstream>


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