Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56345 - in sandbox/stm/branches/vbe/boost: . stm stm/detail
From: vicente.botet_at_[hidden]
Date: 2009-09-21 16:48:27


Author: viboes
Date: 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
New Revision: 56345
URL: http://svn.boost.org/trac/boost/changeset/56345

Log:
TBoost.Stm vbe
* file reorganization

Added:
   sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/datatypes.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/detail/transactions_stack.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/exceptions.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/move.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/synchro.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp (contents, props changed)
   sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp (contents, props changed)
Text files modified:
   sandbox/stm/branches/vbe/boost/stm.hpp | 11
   sandbox/stm/branches/vbe/boost/stm/base_transaction.hpp | 540 ---------------------------------------
   sandbox/stm/branches/vbe/boost/stm/contention_manager.hpp | 31 ++
   sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp | 144 ----------
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 114 +++----
   5 files changed, 101 insertions(+), 739 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -35,12 +35,17 @@
 #ifndef BOOST_STM__HPP
 #define BOOST_STM__HPP
 
-#include <boost/stm/transaction.hpp>
+#include <boost/stm/detail/config.hpp>
+
+#include <boost/stm/base_transaction_object.hpp>
+#include <boost/stm/base_contention_manager.hpp>
 #include <boost/stm/contention_manager.hpp>
+#include <boost/stm/non_tx_smart_ptr.hpp>
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/transaction_object.hpp>
 #include <boost/stm/transaction_object_ptr.hpp>
-#include <boost/stm/detail/tx_ptr.hpp>
 #include <boost/stm/tx_smart_ptr.hpp>
-#include <boost/stm/non_tx_smart_ptr.hpp>
+#include <boost/stm/tx_ptr.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 #endif // TRANSACTION_H

Added: sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/base_contention_manager.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,69 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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 <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 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-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -14,539 +14,25 @@
 #ifndef BOOST_STM_BASE_TRANSACTION_H
 #define BOOST_STM_BASE_TRANSACTION_H
 
-#include <pthread.h>
-//#include <boost/thread/mutex.hpp>
-//#include <boost/thread/locks.hpp>
-
-#include <boost/stm/detail/memory_pool.hpp>
-#include <stdarg.h>
-#include <list>
-
-#ifndef BOOST_STM_USE_BOOST_MUTEX
- typedef pthread_mutex_t Mutex;
-#else
- typedef boost::mutex Mutex;
-#endif
-
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-
-class base_transaction_object;
-
-template <class T> T* cache_clone(const T& val);
-template <class T> void cache_copy(const T* const ori, T* target);
-void cache_release(base_transaction_object* ptr);
-
-template <class T> inline T* cache_clone_constructor(const T&);
-
-template <class T> T* cache_allocate();
-template <class T> void cache_deallocate(T*);
-
-class transaction;
-
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-typedef pthread_mutex_t PLOCK;
-#else
-typedef boost::mutex PLOCK;
-#endif
-
-//-----------------------------------------------------------------------------
-// boolean which is used to invoke "begin_transaction()" upon transaction
-// object construction (so two lines of code aren't needed to make a
-// transaction start, in case the client wants to start the transaction
-// immediately).
-//-----------------------------------------------------------------------------
-bool const begin_transaction = true;
-
-unsigned const kInvalidThread = 0xffffffff;
-
-//-----------------------------------------------------------------------------
-// The possible states a transaction can be in:
-//
-// e_no_state - initial state of transaction.
-// e_aborted - aborted transaction.
-// e_committed - transaction has committed.
-// e_hand_off - transaction memory has been handed off to another
-// transaction. This is the vital state for in-flight
-// transactions which are composed.
-// e_in_flight - transaction currently in process.
-//-----------------------------------------------------------------------------
-enum transaction_state
-{
- e_no_state = -1, // no state is -1
- e_aborted, // ensure aborted = 0
- e_committed, // committed is positive
- e_hand_off, // so is handoff in case bool conversion
- e_in_flight
-};
-
-#if BUILD_MOVE_SEMANTICS
-template <class T>
-inline typename std::remove_reference<T>::type&& draco_move(T &&t)
-{
- return t;
-}
-
-bool const kDracoMoveSemanticsCompiled = true;
-#else
-bool const kDracoMoveSemanticsCompiled = false;
-#endif
-
-class aborted_transaction_exception_no_unlocks {};
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-class aborted_transaction_exception : public std::exception
-{
-public:
- aborted_transaction_exception(char const * const what) : what_(what) {}
-
- //virtual char const * what() const { return what_; }
-
-private:
- char const * const what_;
-};
-
-typedef aborted_transaction_exception aborted_tx;
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-
-#if 0
- template <typename T>
- inline int lock(T *lock) { throw "unsupported lock type"; }
-
- template <typename T>
- inline int trylock(T *lock) { throw "unsupported lock type"; }
-
- template <typename T>
- inline int unlock(T *lock) { throw "unsupported lock type"; }
-
- template <>
- inline int lock(Mutex &lock) { return pthread_mutex_lock(&lock); }
-
- template <>
- inline int lock(Mutex *lock) { return pthread_mutex_lock(lock); }
-
- template <>
- inline int trylock(Mutex &lock) { return pthread_mutex_trylock(&lock); }
-
- template <>
- inline int trylock(Mutex *lock) { return pthread_mutex_trylock(lock); }
-
- template <>
- inline int unlock(Mutex &lock) { return pthread_mutex_unlock(&lock); }
-
- template <>
- inline int unlock(Mutex *lock) { return pthread_unlock(lock); }
-#else
- inline int lock(PLOCK &lock) { return pthread_mutex_lock(&lock); }
- inline int lock(PLOCK *lock) { return pthread_mutex_lock(lock); }
-
- inline int trylock(PLOCK &lock) { return pthread_mutex_trylock(&lock); }
- inline int trylock(PLOCK *lock) { return pthread_mutex_trylock(lock); }
-
- inline int unlock(PLOCK &lock) { return pthread_mutex_unlock(&lock); }
- inline int unlock(PLOCK *lock) { return pthread_mutex_unlock(lock); }
-#endif
-#else
- inline void lock(PLOCK &lock) { lock.lock(); }
- inline void lock(PLOCK *lock) { lock->lock(); }
-
- inline bool trylock(PLOCK &lock) { return lock.try_lock(); }
- inline bool trylock(PLOCK *lock) { return lock->try_lock(); }
-
- inline void unlock(PLOCK &lock) { lock.unlock(); }
- inline void unlock(PLOCK *lock) { lock->unlock(); }
-#endif
-
 //-----------------------------------------------------------------------------
-// this is the base class of all the transactional objects.
-// it tracks:
-// transactionThread_: the thread identifier holding the write acces to this transactional object
-// version: the version when performing validation
-// newMemory_: states whether this object is a new object
-// transactional objets must specialize the pure virtual functions
-// copy_state(base_transaction_object const * const rhs)
-// move_state(base_transaction_object * rhs) if BUILD_MOVE_SEMANTICS
-// cache_deallocate() if BOOST_STM_USE_MEMCOPY
-// copy_state is used to copy the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
-// move_state is used to move the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
-// cache_deallocate is used to release the backup/working copy when the transaction ends if direct/defered policy is used
-// when USE_STM_MEMORY_MANAGER is defined this class provides two functions (retrieve_mem and return_mem) and to manage a pool of memory
-//-----------------------------------------------------------------------------
-
-class base_transaction_object
-{
-public:
-
- base_transaction_object() : transactionThread_(kInvalidThread),
- newMemory_(0)
-#if PERFORMING_VALIDATION
- ,version_(0)
-#endif
- {}
-
-#if 1
- base_transaction_object(const base_transaction_object &t)
- : transactionThread_(kInvalidThread)
- , newMemory_(0)
-#if PERFORMING_VALIDATION
- , version_(0)
-#endif
- {}
-#endif
-
- virtual base_transaction_object* clone() const = 0;
- virtual void copy_state(base_transaction_object const * const rhs) = 0;
-#if BUILD_MOVE_SEMANTICS
- virtual void move_state(base_transaction_object * rhs) = 0;
-#else
- virtual void move_state(base_transaction_object * rhs) {};
-#endif
- virtual ~base_transaction_object() {};
-#ifdef BOOST_STM_USE_MEMCOPY
- virtual void cache_deallocate()=0;
-#endif
-
- void transaction_thread(size_t rhs) const { transactionThread_ = rhs; }
- size_t const & transaction_thread() const { return transactionThread_; }
-
-#if USE_STM_MEMORY_MANAGER
- static void alloc_size(size_t size) { memory_.alloc_size(size); }
-#else
- static void alloc_size(size_t size) { }
-#endif
-
- void new_memory(size_t rhs) const { newMemory_ = rhs; }
- size_t const & new_memory() const { return newMemory_; }
-
-#if PERFORMING_VALIDATION
- size_t version_;
-#endif
-
-//protected:
-
-#if USE_STM_MEMORY_MANAGER
- static void return_mem(void *mem, size_t size)
- {
-#ifndef BOOST_STM_USE_BOOST_MUTEX
- lock(&transactionObjectMutex_);
- memory_.returnChunk(mem, size);
- unlock(&transactionObjectMutex_);
-#else
- boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
- memory_.returnChunk(mem, size);
-#endif
- }
-
- static void* retrieve_mem(size_t size)
- {
-#ifndef BOOST_STM_USE_BOOST_MUTEX
- lock(&transactionObjectMutex_);
- void *mem = memory_.retrieveChunk(size);
- unlock(&transactionObjectMutex_);
-#else
- boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
- void *mem = memory_.retrieveChunk(size);
-#endif
-
- return mem;
- }
-#endif
-
-private:
-
- //--------------------------------------------------------------------------
- // int instead of bool for architecture word-boundary alignment
- //
- // transactionThread_ means a transaction is writing to this memory.
- //
- // in direct environments, this flag means memory being written to directly
- //
- // in deferred environments, this flag means this is memory that was copied
- // and being written to off to the side
- //
- // it's important to note the differences between as direct reads and writes
- // and deferred reads and writes behave very differently when using this
- // flag.
- //--------------------------------------------------------------------------
- mutable size_t transactionThread_;
-
- mutable size_t newMemory_;
-#if USE_STM_MEMORY_MANAGER
- static Mutex transactionObjectMutex_;
- static MemoryPool<base_transaction_object> memory_;
-#endif
-};
-
-
-//-----------------------------------------------------------------------------
-// transaction object mixin
-// Provides the definition of the virtual functions
-// 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
-
-// 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 transaction_object : public base_transaction_object
-{
-public:
-
- //--------------------------------------------------------------------------
- virtual base_transaction_object* clone() const {
- Derived* tmp = cache_clone(*static_cast<Derived const*>(this));
- return tmp;
- }
-
- //--------------------------------------------------------------------------
- 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
-
-#ifdef BOOST_STM_USE_MEMCOPY
- virtual void cache_deallocate() {
- boost::stm::cache_deallocate(this);
- }
-
-#endif
-
-#if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
- {
- return retrieve_mem(size);
- }
-
- void operator delete(void* mem)
- {
- static Derived elem;
- static size_t elemSize = sizeof(elem);
- return_mem(mem, elemSize);
- }
-#endif
-
-};
-
-template <typename T> class native_trans :
-public transaction_object< native_trans<T> >
-{
-public:
-
- native_trans() : value_(T()) {}
- native_trans(T const &rhs) : value_(rhs) {}
- native_trans(native_trans const &rhs) : value_(rhs.value_) {}
- ~native_trans() {}
-
- native_trans& operator=(T const &rhs) { value_ = rhs; return *this; }
-
- native_trans& operator--() { --value_; return *this; }
- native_trans operator--(int) { native_trans n = *this; --value_; return n; }
-
- native_trans& operator++() { ++value_; return *this; }
- native_trans operator++(int) { native_trans n = *this; ++value_; return n; }
-
- native_trans& operator+=(T const &rhs)
- {
- value_ += rhs;
- return *this;
- }
-
- native_trans operator+(native_trans const &rhs)
- {
- native_trans ret = *this;
- ret.value_ += rhs.value_;
- return ret;
- }
-
- //template <>
- operator T() const
- {
- return this->value_;
- }
-
-#if BUILD_MOVE_SEMANTICS
- //--------------------------------------------------
- // move semantics
- //--------------------------------------------------
- native_trans(native_trans &&rhs) { value_ = rhs.value_;}
- native_trans& operator=(native_trans &&rhs)
- { value_ = rhs.value_; return *this; }
-#endif
-
- T& value() { return value_; }
- T const & value() const { return value_; }
-
-private:
- T value_;
-};
-
+#include <stdarg.h>
+#include <pthread.h>
 //-----------------------------------------------------------------------------
-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 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() {};
-};
-
+#include <list>
 //-----------------------------------------------------------------------------
-class DefaultContentionManager : public base_contention_manager
-{
-public:
- //--------------------------------------------------------------------------
- void abort_on_new(transaction const &t);
- void abort_on_delete(transaction const &t,
- base_transaction_object const &in);
-
- void abort_on_read(transaction const &t,
- base_transaction_object const &in);
- void abort_on_write(transaction &t,
- base_transaction_object const &in);
-
- virtual bool abort_before_commit(transaction const &t)
- {
- return false;
- }
-
- virtual bool permission_to_abort
- (transaction const &lhs, transaction const &rhs)
- { return true; }
-
- virtual bool allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
- bool txIsIrrevocable, transaction const &rhs);
-
- virtual void perform_isolated_tx_wait_priority_promotion(transaction &);
- virtual void perform_irrevocable_tx_wait_priority_promotion(transaction &);
-};
-
 //-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
 //-----------------------------------------------------------------------------
- template<typename Lockable>
- class lock_guard2
- {
- private:
- Lockable& m;
- //bool owns_;
-
- explicit lock_guard2(lock_guard2&);
- lock_guard2& operator=(lock_guard2&);
- public:
- inline explicit lock_guard2(Lockable& m_):
- m(m_)
- {
- lock();
- }
- inline ~lock_guard2()
- {
- //unlock();
- }
- //inline bool owns_lock() { return owns_;}
- inline void lock() {
- //if (owns_)
- stm::lock(m);
- //owns_=true;
- }
- inline void unlock() {
- //if (owns_)
- stm::unlock(m);
- //owns_=false;
- }
- //inline void release() {
- // owns_=false;
- //}
- };
-
+#include <boost/stm/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/synchro.hpp>
+#include <boost/stm/transaction_object.hpp>
 
 //-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-template <typename T>
-class var_auto_lock
-{
-public:
-
- //--------------------------------------------------------------------------
- typedef T lock_type;
- typedef std::list<lock_type*> lock_list;
-
- //--------------------------------------------------------------------------
- var_auto_lock(lock_type *l, ...)
- {
- va_list ap;
- va_start(ap, l);
-
- while (l)
- {
- lockList_.push_back(l);
- l = va_arg(ap, lock_type*);
- }
-
- va_end(ap);
-
- std::list<PLOCK*>::iterator i = lockList_.begin();
-
- for (; i != lockList_.end(); ++i)
- {
- lock(*i);
- }
- }
-
- //--------------------------------------------------------------------------
- ~var_auto_lock()
- {
- for (std::list<PLOCK*>::iterator i = lockList_.begin(); i != lockList_.end(); ++i)
- {
- unlock(*i);
- }
- }
-
-private:
- std::list<lock_type*> lockList_;
-
-};
-
-
-} // namespace core
-}
-#endif // BASE_TRANSACTION_H
+#endif // BOOST_STM_BASE_TRANSACTION_H
 
 

Added: sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,165 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_BASE_TRANSACTION_OBJECT__HPP
+#define BOOST_STM_BASE_TRANSACTION_OBJECT__HPP
+
+//-----------------------------------------------------------------------------
+//#include <stdarg.h>
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/datatypes.hpp>
+#include <boost/stm/synchro.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/memory_pool.hpp>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// forward declarations
+//-----------------------------------------------------------------------------
+class transaction;
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// this is the base class of all the transactional objects.
+// it tracks:
+// transactionThread_: the thread identifier holding the write acces to this transactional object
+// version: the version when performing validation
+// newMemory_: states whether this object is a new object
+// transactional objets must specialize the pure virtual functions
+// copy_state(base_transaction_object const * const rhs)
+// move_state(base_transaction_object * rhs) if BUILD_MOVE_SEMANTICS
+// cache_deallocate() if BOOST_STM_USE_MEMCOPY
+// copy_state is used to copy the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
+// move_state is used to move the backup/working copy to the shared transactional object when the roolback/commit is done direct/defered policy is used
+// cache_deallocate is used to release the backup/working copy when the transaction ends if direct/defered policy is used
+// when USE_STM_MEMORY_MANAGER is defined this class provides two functions (retrieve_mem and return_mem) and to manage a pool of memory
+//-----------------------------------------------------------------------------
+
+class base_transaction_object
+{
+public:
+
+ base_transaction_object() : transactionThread_(kInvalidThread),
+ newMemory_(0)
+#if PERFORMING_VALIDATION
+ ,version_(0)
+#endif
+ {}
+
+#if 1
+ base_transaction_object(const base_transaction_object &t)
+ : transactionThread_(kInvalidThread)
+ , newMemory_(0)
+#if PERFORMING_VALIDATION
+ , version_(0)
+#endif
+ {}
+#endif
+
+ virtual base_transaction_object* clone() const = 0;
+ virtual void copy_state(base_transaction_object const * const rhs) = 0;
+#if BUILD_MOVE_SEMANTICS
+ virtual void move_state(base_transaction_object * rhs) = 0;
+#else
+ virtual void move_state(base_transaction_object * rhs) {};
+#endif
+ virtual ~base_transaction_object() {};
+#ifdef BOOST_STM_USE_MEMCOPY
+ virtual void cache_deallocate()=0;
+#endif
+
+ void transaction_thread(size_t rhs) const { transactionThread_ = rhs; }
+ size_t const & transaction_thread() const { return transactionThread_; }
+
+#if USE_STM_MEMORY_MANAGER
+ static void alloc_size(size_t size) { memory_.alloc_size(size); }
+#else
+ static void alloc_size(size_t size) { }
+#endif
+
+ void new_memory(size_t rhs) const { newMemory_ = rhs; }
+ size_t const & new_memory() const { return newMemory_; }
+
+#if PERFORMING_VALIDATION
+ size_t version_;
+#endif
+
+//protected:
+
+#if USE_STM_MEMORY_MANAGER
+ static void return_mem(void *mem, size_t size)
+ {
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+ lock(&transactionObjectMutex_);
+ memory_.returnChunk(mem, size);
+ unlock(&transactionObjectMutex_);
+#else
+ boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
+ memory_.returnChunk(mem, size);
+#endif
+ }
+
+ static void* retrieve_mem(size_t size)
+ {
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+ lock(&transactionObjectMutex_);
+ void *mem = memory_.retrieveChunk(size);
+ unlock(&transactionObjectMutex_);
+#else
+ boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
+ void *mem = memory_.retrieveChunk(size);
+#endif
+
+ return mem;
+ }
+#endif
+
+private:
+
+ //--------------------------------------------------------------------------
+ // int instead of bool for architecture word-boundary alignment
+ //
+ // transactionThread_ means a transaction is writing to this memory.
+ //
+ // in direct environments, this flag means memory being written to directly
+ //
+ // in deferred environments, this flag means this is memory that was copied
+ // and being written to off to the side
+ //
+ // it's important to note the differences between as direct reads and writes
+ // and deferred reads and writes behave very differently when using this
+ // flag.
+ //--------------------------------------------------------------------------
+ mutable size_t transactionThread_;
+
+ mutable size_t newMemory_;
+#if USE_STM_MEMORY_MANAGER
+ static Mutex transactionObjectMutex_;
+ static MemoryPool<base_transaction_object> memory_;
+#endif
+};
+
+} // namespace core
+}
+#endif // BOOST_STM_BASE_TRANSACTION_OBJECT__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,55 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_CACHE_FCT__HPP
+#define BOOST_STM_CACHE_FCT__HPP
+
+//-----------------------------------------------------------------------------
+#include <stdarg.h>
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+//#include <boost/stm/exceptions.hpp>
+//-----------------------------------------------------------------------------
+//#include <boost/stm/detail/memory_pool.hpp>
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// forward declarations
+//-----------------------------------------------------------------------------
+
+class base_transaction_object;
+
+template <class T> T* cache_clone(const T& val);
+template <class T> void cache_copy(const T* const ori, T* target);
+void cache_release(base_transaction_object* ptr);
+
+template <class T> inline T* cache_clone_constructor(const T&);
+
+template <class T> T* cache_allocate();
+template <class T> void cache_deallocate(T*);
+
+class transaction;
+
+} // namespace core
+}
+#endif // BOOST_STM_CACHE_FCT__HPP
+
+

Modified: sandbox/stm/branches/vbe/boost/stm/contention_manager.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/contention_manager.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/contention_manager.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -18,6 +18,37 @@
 
 namespace boost { namespace stm {
 
+
+ //-----------------------------------------------------------------------------
+class DefaultContentionManager : public base_contention_manager
+{
+public:
+ //--------------------------------------------------------------------------
+ void abort_on_new(transaction const &t);
+ void abort_on_delete(transaction const &t,
+ base_transaction_object const &in);
+
+ void abort_on_read(transaction const &t,
+ base_transaction_object const &in);
+ void abort_on_write(transaction &t,
+ base_transaction_object const &in);
+
+ virtual bool abort_before_commit(transaction const &t)
+ {
+ return false;
+ }
+
+ virtual bool permission_to_abort
+ (transaction const &lhs, transaction const &rhs)
+ { return true; }
+
+ virtual bool allow_lock_to_abort_tx(int const & lockWaitTime, int const &lockAborted,
+ bool txIsIrrevocable, transaction const &rhs);
+
+ virtual void perform_isolated_tx_wait_priority_promotion(transaction &);
+ virtual void perform_irrevocable_tx_wait_priority_promotion(transaction &);
+};
+
 ////////////////////////////////////////////////////////////////////////////
 //
 // this class does nothing on abort notices for writes and reads

Added: sandbox/stm/branches/vbe/boost/stm/datatypes.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/datatypes.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,59 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_DATATYPES__HPP
+#define BOOST_STM_DATATYPES__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// The possible states a transaction can be in:
+//
+// e_no_state - initial state of transaction.
+// e_aborted - aborted transaction.
+// e_committed - transaction has committed.
+// e_hand_off - transaction memory has been handed off to another
+// transaction. This is the vital state for in-flight
+// transactions which are composed.
+// e_in_flight - transaction currently in process.
+//-----------------------------------------------------------------------------
+enum transaction_state
+{
+ e_no_state = -1, // no state is -1
+ e_aborted, // ensure aborted = 0
+ e_committed, // committed is positive
+ e_hand_off, // so is handoff in case bool conversion
+ e_in_flight
+};
+
+
+unsigned const kInvalidThread = 0xffffffff;
+
+
+
+} // namespace core
+}
+#endif // BOOST_STM_DATATYPES__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_MONOTONIC_STORAGE__HPP
+#define BOOST_STM_MONOTONIC_STORAGE__HPP
+
+#include <boost/stm/detail/config.hpp>
+
+namespace boost { namespace stm {
+
+#if defined(BOOST_STM_USE_MEMCOPY) && defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+ template <std::size_t size>
+ struct monotonic_storage {
+ char storage_[size];
+ char* ptr_;
+ public:
+ monotonic_storage() : ptr_(&storage_[0]) {}
+ template <typename T>
+ char* allocate() {
+ union aligned_storage {
+ char val[sizeof(T)] ;
+ int alignement;
+ };
+ char* ptr= ptr_;
+ ptr_+= sizeof(aligned_storage);
+ return ptr;
+ }
+ void reset() {ptr_=&storage_[0];}
+ };
+#endif
+
+}}
+
+///////////////////////////////////////////////////////////////////////////////
+#endif // BOOST_STM_MONOTONIC_STORAGE__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/detail/transactions_stack.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/detail/transactions_stack.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TRANSACTIONS_STACK__HPP
+#define BOOST_STM_TRANSACTIONS_STACK__HPP
+
+#include <stack>
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class transaction;
+
+namespace detail {
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+struct transactions_stack {
+ typedef std::stack<transaction*> cont_type;
+ cont_type stack_;
+ transactions_stack() {
+ // the stack at least one element (0) so we can always call to top, i.e. current transaction is 0
+ stack_.push(0);
+ }
+ void push(transaction* ptr) {stack_.push(ptr);}
+ void pop() {stack_.pop();}
+ std::size_t size() {return stack_.size();}
+ transaction* top() {return stack_.top();}
+};
+
+}
+
+typedef detail::transactions_stack TransactionsStack;
+
+}}
+
+//-----------------------------------------------------------------------------
+#endif // BOOST_STM_TRANSACTION_STACK__HPP
+
+

Modified: sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/tx_ptr.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -11,146 +11,4 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef BOOST_STM_TX_PTR__HPP
-#define BOOST_STM_TX_PTR__HPP
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-#include <boost/stm/transaction.hpp>
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-namespace boost { namespace stm {
-
-template <typename T>
-class write_ptr;
-
-template <typename T>
-class read_ptr
-{
-public:
-
- inline read_ptr(transaction &t, T const &tx_obj) :
- t_(t), tx_ptr_(&const_cast<T&>(t_.read(tx_obj))), written_(false)
- {}
-
- const T* get() const
- {
- if (t_.forced_to_abort())
- {
- t_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
-
- // we are already holding the written object
- if (written_) return tx_ptr_;
-
- T* temp = t_.get_written(*tx_ptr_);
-
- // if we found something, store this as the tx_ptr_
- if (0 != temp)
- {
- tx_ptr_ = temp;
- written_ = true;
- }
-
- return tx_ptr_;
- }
-
- inline T const & operator*() const { return *get(); }
- inline T const * operator->() const { return get(); }
-
- inline transaction &trans() { return t_; }
-
- T* write_ptr()
- {
- if (t_.forced_to_abort())
- {
- t_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
-
- // we are already holding the written object
- if (written_) return tx_ptr_;
-
- T* temp = t_.get_written(*tx_ptr_);
-
- // if we found something, store this as the tx_ptr_
- if (0 != temp)
- {
- tx_ptr_ = temp;
- written_ = true;
- }
- else
- {
- tx_ptr_ = &t_.write(*tx_ptr_);
- written_ = true;
- }
-
- return tx_ptr_;
- }
-
-private:
-
- mutable transaction &t_;
- mutable T *tx_ptr_;
- mutable bool written_;
- template <typename X> friend class write_ptr;
-};
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-template <typename T>
-class write_ptr
-{
-public:
-
- inline write_ptr(transaction &t, T & tx_obj) :
- t_(t), tx_obj_(t_.write(tx_obj))
- {}
-
- inline write_ptr(transaction &t, T* ptr) :
- t_(t), tx_obj_(t_.write_ptr(ptr))
- {}
-
- inline write_ptr(transaction &t, read_ptr<T> & tx_obj) :
- t_(t), tx_obj_(*t_.write_ptr(tx_obj.tx_ptr_))
- {}
-
- write_ptr& operator=(T const* ptr) {
- tx_obj_=*t_.write_ptr(ptr);
- return *this;
- }
- write_ptr& operator=(read_ptr<T> & tx_obj) {
- tx_obj_=*t_.write_ptr(tx_obj.tx_ptr_);
- return *this;
- }
- inline T& operator*()
- {
- if (t_.forced_to_abort())
- {
- t_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- return tx_obj_;
- }
-
- inline T* operator->()
- {
- if (t_.forced_to_abort())
- {
- t_.lock_and_abort();
- throw aborted_transaction_exception("aborting transaction");
- }
- return &tx_obj_;
- }
-
-private:
- mutable transaction &t_;
- mutable T &tx_obj_;
-};
-
-}}
-#endif
-
-
+#include <boost/stm/tx_ptr.hpp>

Added: sandbox/stm/branches/vbe/boost/stm/exceptions.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/exceptions.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_EXCEPTIONS__HPP
+#define BOOST_STM_EXCEPTIONS__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <exception>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace stm {
+
+class aborted_transaction_exception_no_unlocks {};
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class aborted_transaction_exception : public std::exception
+{
+public:
+ aborted_transaction_exception(char const * const what) : what_(what) {}
+
+ //virtual char const * what() const { return what_; }
+
+private:
+ char const * const what_;
+};
+
+typedef aborted_transaction_exception aborted_tx;
+
+}}
+
+#endif // BOOST_STM_EXCEPTIONS__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/move.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/move.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+#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
+
+

Added: sandbox/stm/branches/vbe/boost/stm/synchro.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/synchro.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,193 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_SYNCHO__HPP
+#define BOOST_STM_SYNCHO__HPP
+
+//-----------------------------------------------------------------------------
+#include <stdarg.h>
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+//#include <boost/stm/exceptions.hpp>
+//-----------------------------------------------------------------------------
+//#include <boost/stm/detail/memory_pool.hpp>
+//-----------------------------------------------------------------------------
+
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+ typedef pthread_mutex_t Mutex;
+#else
+ typedef boost::mutex Mutex;
+#endif
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// forward declarations
+//-----------------------------------------------------------------------------
+
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+typedef pthread_mutex_t PLOCK;
+#else
+typedef boost::mutex PLOCK;
+#endif
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+
+#if 0
+ template <typename T>
+ inline int lock(T *lock) { throw "unsupported lock type"; }
+
+ template <typename T>
+ inline int trylock(T *lock) { throw "unsupported lock type"; }
+
+ template <typename T>
+ inline int unlock(T *lock) { throw "unsupported lock type"; }
+
+ template <>
+ inline int lock(Mutex &lock) { return pthread_mutex_lock(&lock); }
+
+ template <>
+ inline int lock(Mutex *lock) { return pthread_mutex_lock(lock); }
+
+ template <>
+ inline int trylock(Mutex &lock) { return pthread_mutex_trylock(&lock); }
+
+ template <>
+ inline int trylock(Mutex *lock) { return pthread_mutex_trylock(lock); }
+
+ template <>
+ inline int unlock(Mutex &lock) { return pthread_mutex_unlock(&lock); }
+
+ template <>
+ inline int unlock(Mutex *lock) { return pthread_unlock(lock); }
+#else
+ inline int lock(PLOCK &lock) { return pthread_mutex_lock(&lock); }
+ inline int lock(PLOCK *lock) { return pthread_mutex_lock(lock); }
+
+ inline int trylock(PLOCK &lock) { return pthread_mutex_trylock(&lock); }
+ inline int trylock(PLOCK *lock) { return pthread_mutex_trylock(lock); }
+
+ inline int unlock(PLOCK &lock) { return pthread_mutex_unlock(&lock); }
+ inline int unlock(PLOCK *lock) { return pthread_mutex_unlock(lock); }
+#endif
+#else
+ inline void lock(PLOCK &lock) { lock.lock(); }
+ inline void lock(PLOCK *lock) { lock->lock(); }
+
+ inline bool trylock(PLOCK &lock) { return lock.try_lock(); }
+ inline bool trylock(PLOCK *lock) { return lock->try_lock(); }
+
+ inline void unlock(PLOCK &lock) { lock.unlock(); }
+ inline void unlock(PLOCK *lock) { lock->unlock(); }
+#endif
+
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+ template<typename Lockable>
+ class lock_guard2
+ {
+ private:
+ Lockable& m;
+ //bool owns_;
+
+ explicit lock_guard2(lock_guard2&);
+ lock_guard2& operator=(lock_guard2&);
+ public:
+ inline explicit lock_guard2(Lockable& m_):
+ m(m_)
+ {
+ lock();
+ }
+ inline ~lock_guard2()
+ {
+ //unlock();
+ }
+ //inline bool owns_lock() { return owns_;}
+ inline void lock() {
+ //if (owns_)
+ stm::lock(m);
+ //owns_=true;
+ }
+ inline void unlock() {
+ //if (owns_)
+ stm::unlock(m);
+ //owns_=false;
+ }
+ //inline void release() {
+ // owns_=false;
+ //}
+ };
+
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename T>
+class var_auto_lock
+{
+public:
+
+ //--------------------------------------------------------------------------
+ typedef T lock_type;
+ typedef std::list<lock_type*> lock_list;
+
+ //--------------------------------------------------------------------------
+ var_auto_lock(lock_type *l, ...)
+ {
+ va_list ap;
+ va_start(ap, l);
+
+ while (l)
+ {
+ lockList_.push_back(l);
+ l = va_arg(ap, lock_type*);
+ }
+
+ va_end(ap);
+
+ std::list<PLOCK*>::iterator i = lockList_.begin();
+
+ for (; i != lockList_.end(); ++i)
+ {
+ lock(*i);
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ ~var_auto_lock()
+ {
+ for (std::list<PLOCK*>::iterator i = lockList_.begin(); i != lockList_.end(); ++i)
+ {
+ unlock(*i);
+ }
+ }
+
+private:
+ std::list<lock_type*> lockList_;
+
+};
+
+
+} // namespace core
+}
+#endif // BOOST_STM_SYNCHO__HPP
+
+

Modified: sandbox/stm/branches/vbe/boost/stm/transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -15,24 +15,28 @@
 #define BOOST_STM_TRANSACTION__HPP
 
 //-----------------------------------------------------------------------------
+#include <assert.h>
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <iostream>
+#include <list>
+#include <map>
+#include <memory>
+#include <set>
+#include <string>
+#include <vector>
 //-----------------------------------------------------------------------------
 #include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/base_transaction.hpp>
+//-----------------------------------------------------------------------------
 #include <boost/stm/detail/datatypes.hpp>
 #include <boost/stm/detail/transaction_bookkeeping.hpp>
-#include <boost/stm/base_transaction.hpp>
 #include <boost/stm/detail/bloom_filter.hpp>
 #include <boost/stm/detail/vector_map.hpp>
 #include <boost/stm/detail/vector_set.hpp>
-#include <assert.h>
-#include <string>
-#include <iostream>
-#include <list>
-#include <set>
-#include <map>
-#include <vector>
-#include <memory>
-#include <pthread.h>
-#include <stack>
+#include <boost/stm/detail/monotonic_storage.hpp>
+#include <boost/stm/detail/transactions_stack.hpp>
 
 #if BUILD_MOVE_SEMANTICS
 #include <type_traits>
@@ -49,68 +53,46 @@
 //-----------------------------------------------------------------------------
 namespace boost { namespace stm {
 
+#if BUILD_MOVE_SEMANTICS
+bool const kDracoMoveSemanticsCompiled = true;
+#else
+bool const kDracoMoveSemanticsCompiled = false;
+#endif
 
+//-----------------------------------------------------------------------------
+// boolean which is used to invoke "begin_transaction()" upon transaction
+// object construction (so two lines of code aren't needed to make a
+// transaction start, in case the client wants to start the transaction
+// immediately).
+//-----------------------------------------------------------------------------
+bool const begin_transaction = true;
+
 #if defined(BOOST_STM_CM_STATIC_CONF)
 #if defined(BOOST_STM_CM_STATIC_CONF_ExceptAndBackOffOnAbortNoticeCM)
- typedef except_and_back_off_on_abort_notice_cm contention_manager_type;
-#endif
+typedef except_and_back_off_on_abort_notice_cm contention_manager_type;
 #endif
-
- enum LatmType
- {
- kMinLatmType = 0,
- eFullLatmProtection = kMinLatmType,
- eTmConflictingLockLatmProtection,
- eTxConflictingLockLatmProtection,
- kMaxLatmType
- };
-
- enum TxType
- {
- kMinIrrevocableType = 0,
- eNormalTx = kMinIrrevocableType,
- eIrrevocableTx,
- eIrrevocableAndIsolatedTx,
- kMaxIrrevocableType
- };
-
- typedef std::pair<base_transaction_object*, base_transaction_object*> tx_pair;
-
-
-#if defined(BOOST_STM_USE_MEMCOPY) && defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
- template <std::size_t size>
- struct monotonic_storage {
- char storage_[size];
- char* ptr_;
- public:
- monotonic_storage() : ptr_(&storage_[0]) {}
- template <typename T>
- char* allocate() {
- union aligned_storage {
- char val[sizeof(T)] ;
- int alignement;
- };
- char* ptr= ptr_;
- ptr_+= sizeof(aligned_storage);
- return ptr;
- }
- void reset() {ptr_=&storage_[0];}
- };
 #endif
 
-class transaction;
-struct TransactionsStack {
- typedef std::stack<transaction*> cont_type;
- cont_type stack_;
- TransactionsStack() {
- // the stack at least one element (0) so we can always call to top, i.e. current transaction is 0
- stack_.push(0);
- }
- void push(transaction* ptr) {stack_.push(ptr);}
- void pop() {stack_.pop();}
- std::size_t size() {return stack_.size();}
- transaction* top() {return stack_.top();}
+enum latm_type
+{
+ kMinLatmType = 0,
+ eFullLatmProtection = kMinLatmType,
+ eTmConflictingLockLatmProtection,
+ eTxConflictingLockLatmProtection,
+ kMaxLatmType
+};
+typedef latm_type LatmType;
+enum transaction_type
+{
+ kMinIrrevocableType = 0,
+ eNormalTx = kMinIrrevocableType,
+ eIrrevocableTx,
+ eIrrevocableAndIsolatedTx,
+ kMaxIrrevocableType
 };
+typedef transaction_type TxType;
+
+typedef std::pair<base_transaction_object*, base_transaction_object*> tx_pair;
 
 ///////////////////////////////////////////////////////////////////////////////
 // transaction Class

Added: sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,161 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_TRANSACTION_OBJECT__HPP
+#define BOOST_STM_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
+// Provides the definition of the virtual functions
+// 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
+
+// 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 transaction_object : public base_transaction_object
+{
+public:
+
+ //--------------------------------------------------------------------------
+ virtual base_transaction_object* clone() const {
+ Derived* tmp = cache_clone(*static_cast<Derived const*>(this));
+ return tmp;
+ }
+
+ //--------------------------------------------------------------------------
+ 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
+
+#ifdef BOOST_STM_USE_MEMCOPY
+ virtual void cache_deallocate() {
+ boost::stm::cache_deallocate(this);
+ }
+
+#endif
+
+#if USE_STM_MEMORY_MANAGER
+ void* operator new(size_t size) throw ()
+ {
+ return retrieve_mem(size);
+ }
+
+ void operator delete(void* mem)
+ {
+ static Derived elem;
+ static size_t elemSize = sizeof(elem);
+ return_mem(mem, elemSize);
+ }
+#endif
+
+};
+
+template <typename T> class native_trans :
+public transaction_object< native_trans<T> >
+{
+public:
+
+ native_trans() : value_(T()) {}
+ native_trans(T const &rhs) : value_(rhs) {}
+ native_trans(native_trans const &rhs) : value_(rhs.value_) {}
+ ~native_trans() {}
+
+ native_trans& operator=(T const &rhs) { value_ = rhs; return *this; }
+
+ native_trans& operator--() { --value_; return *this; }
+ native_trans operator--(int) { native_trans n = *this; --value_; return n; }
+
+ native_trans& operator++() { ++value_; return *this; }
+ native_trans operator++(int) { native_trans n = *this; ++value_; return n; }
+
+ native_trans& operator+=(T const &rhs)
+ {
+ value_ += rhs;
+ return *this;
+ }
+
+ native_trans operator+(native_trans const &rhs)
+ {
+ native_trans ret = *this;
+ ret.value_ += rhs.value_;
+ return ret;
+ }
+
+ //template <>
+ operator T() const
+ {
+ return this->value_;
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ //--------------------------------------------------
+ // move semantics
+ //--------------------------------------------------
+ native_trans(native_trans &&rhs) { value_ = rhs.value_;}
+ native_trans& operator=(native_trans &&rhs)
+ { value_ = rhs.value_; return *this; }
+#endif
+
+ T& value() { return value_; }
+ T const & value() const { return value_; }
+
+private:
+ T value_;
+};
+
+} // namespace core
+}
+#endif // BOOST_STM_TRANSACTION_OBJECT__HPP
+
+

Added: sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx_ptr.hpp 2009-09-21 16:48:25 EDT (Mon, 21 Sep 2009)
@@ -0,0 +1,156 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_PTR__HPP
+#define BOOST_STM_TX_PTR__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+template <typename T>
+class write_ptr;
+
+template <typename T>
+class read_ptr
+{
+public:
+
+ inline read_ptr(transaction &t, T const &tx_obj) :
+ t_(t), tx_ptr_(&const_cast<T&>(t_.read(tx_obj))), written_(false)
+ {}
+
+ const T* get() const
+ {
+ if (t_.forced_to_abort())
+ {
+ t_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ // we are already holding the written object
+ if (written_) return tx_ptr_;
+
+ T* temp = t_.get_written(*tx_ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp)
+ {
+ tx_ptr_ = temp;
+ written_ = true;
+ }
+
+ return tx_ptr_;
+ }
+
+ inline T const & operator*() const { return *get(); }
+ inline T const * operator->() const { return get(); }
+
+ inline transaction &trans() { return t_; }
+
+ T* write_ptr()
+ {
+ if (t_.forced_to_abort())
+ {
+ t_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+
+ // we are already holding the written object
+ if (written_) return tx_ptr_;
+
+ T* temp = t_.get_written(*tx_ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp)
+ {
+ tx_ptr_ = temp;
+ written_ = true;
+ }
+ else
+ {
+ tx_ptr_ = &t_.write(*tx_ptr_);
+ written_ = true;
+ }
+
+ return tx_ptr_;
+ }
+
+private:
+
+ mutable transaction &t_;
+ mutable T *tx_ptr_;
+ mutable bool written_;
+ template <typename X> friend class write_ptr;
+};
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename T>
+class write_ptr
+{
+public:
+
+ inline write_ptr(transaction &t, T & tx_obj) :
+ t_(t), tx_obj_(t_.write(tx_obj))
+ {}
+
+ inline write_ptr(transaction &t, T* ptr) :
+ t_(t), tx_obj_(t_.write_ptr(ptr))
+ {}
+
+ inline write_ptr(transaction &t, read_ptr<T> & tx_obj) :
+ t_(t), tx_obj_(*t_.write_ptr(tx_obj.tx_ptr_))
+ {}
+
+ write_ptr& operator=(T const* ptr) {
+ tx_obj_=*t_.write_ptr(ptr);
+ return *this;
+ }
+ write_ptr& operator=(read_ptr<T> & tx_obj) {
+ tx_obj_=*t_.write_ptr(tx_obj.tx_ptr_);
+ return *this;
+ }
+ inline T& operator*()
+ {
+ if (t_.forced_to_abort())
+ {
+ t_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return tx_obj_;
+ }
+
+ inline T* operator->()
+ {
+ if (t_.forced_to_abort())
+ {
+ t_.lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return &tx_obj_;
+ }
+
+private:
+ mutable transaction &t_;
+ mutable T &tx_obj_;
+};
+
+}}
+#endif
+
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk