|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56728 - in sandbox/stm/branches/vbe/boost: . stm stm/detail stm/non_tx/detail
From: vicente.botet_at_[hidden]
Date: 2009-10-12 02:32:39
Author: viboes
Date: 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
New Revision: 56728
URL: http://svn.boost.org/trac/boost/changeset/56728
Log:
TBoost.Stm vbe
* Adding transaction specific memory managers
* Adding shallow copy transactional object mixin
Added:
sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp (contents, props changed)
Text files modified:
sandbox/stm/branches/vbe/boost/stm.hpp | 1
sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp | 6 -
sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp | 6
sandbox/stm/branches/vbe/boost/stm/detail/config.hpp | 12 +-
sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp | 2
sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 18 +++++
sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp | 45 +++++++++++++-
sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 123 +++++++++++----------------------------
sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp | 63 ++++++++++++++++----
sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp | 65 +++++++++++++++-----
10 files changed, 202 insertions(+), 139 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-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -46,6 +46,7 @@
#include <boost/stm/move.hpp>
#include <boost/stm/non_tx/numeric.hpp>
#include <boost/stm/non_tx/smart_ptr.hpp>
+#include <boost/stm/shallow_transaction_object.hpp>
#include <boost/stm/synchro.hpp>
#include <boost/stm/transaction.hpp>
#include <boost/stm/transaction_bookkeeping.hpp>
Modified: sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -47,7 +47,7 @@
// 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
+// cache_deallocate()
// 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
@@ -75,7 +75,7 @@
{}
#endif
- virtual base_transaction_object* clone() const = 0;
+ virtual base_transaction_object* clone(transaction* t) 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;
@@ -83,9 +83,7 @@
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_; }
Modified: sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -36,17 +36,17 @@
//-----------------------------------------------------------------------------
class base_transaction_object;
+class transaction;
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> inline T* cache_clone_constructor(const T&);
-template <class T> T* cache_allocate();
+template <class T> T* cache_allocate(transaction*);
template <class T> void cache_deallocate(T*);
-class transaction;
} // namespace core
}
Modified: sandbox/stm/branches/vbe/boost/stm/detail/config.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/config.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/config.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -34,8 +34,9 @@
// OTHER: each TSS data has its specific TSS
#define USE_SINGLE_THREAD_CONTEXT_MAP 1
-#define BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP 1
-
+//#define BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP 1
+
+
///////////////////////////////////////////////////////////////////////////////
// When USE_SINGLE_THREAD_CONTEXT_MAP or BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP are defined you can want to store references to the TSS or not
// BOOST_STM_TX_CONTAINS_REFERENCES_TO_TSS_FIELDS if you want to add these references
@@ -56,15 +57,14 @@
#define BOOST_STM_CM_STATIC_CONF_except_and_back_off_on_abort_notice_cm 1
///////////////////////////////////////////////////////////////////////////////
-// BOOST_STM_USE_MEMCOPY: STM uses memcpy insted of the copy constructor
-#define BOOST_STM_USE_MEMCOPY 1
+// BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+//#define BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER 1
-//// The cache using memcpy can use the following memory managers
+//// The cache using BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER can use the following memory managers
//// BOOST_STM_CACHE_USE_MALLOC: uses malloc/free
//// BOOST_STM_CACHE_USE_MEMORY_MANAGER: uses the class specific memory manager
//// BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER: uses the monotonic storage memory manager
-
#define BOOST_STM_CACHE_USE_MALLOC 1
//#define BOOST_STM_CACHE_USE_MEMORY_MANAGER 1
//#define BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER 1
Modified: sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/monotonic_storage.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -18,7 +18,7 @@
namespace boost { namespace stm {
-#if defined(BOOST_STM_USE_MEMCOPY) && defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
+#if defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template <std::size_t size>
Modified: sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -721,7 +721,7 @@
invalidating_deferred_end_transaction();
#endif
}
-#if defined(BOOST_STM_USE_MEMCOPY) && defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
+#if defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
context_.mstorage_.reset();
#endif
}
@@ -834,6 +834,7 @@
// this is an optimization to check forced to abort before obtaining the
// transaction mutex, so if we do need to abort we do it now
//--------------------------------------------------------------------------
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
#ifndef DELAY_INVALIDATION_DOOMED_TXS_UNTIL_COMMIT
if (forced_to_abort())
{
@@ -850,12 +851,14 @@
//--------------------------------------------------------------------------
if (is_only_reading())
{
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
lock(inflight_lock());
transactionsInFlight_.erase(this);
#if PERFORMING_COMPOSITION
if (other_in_flight_same_thread_transactions())
{
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
unlock(inflight_lock());
state_ = e_hand_off;
bookkeeping_.inc_handoffs();
@@ -863,6 +866,7 @@
else
#endif
{
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
unlock(inflight_lock());
tx_type(eNormalTx);
#if PERFORMING_LATM
@@ -871,12 +875,16 @@
#endif
state_ = e_committed;
}
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
++global_clock();
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
return;
}
- while (0 != trylock(&transactionMutex_)) { }
+ while (0 != trylock(&transactionMutex_)) {
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
+ }
//--------------------------------------------------------------------------
// as much as I'd like to transactionsInFlight_.erase() here, we have
@@ -885,6 +893,7 @@
// anyway. so we actually lose performance by doing it here and then
// doing it again inside abort()
//--------------------------------------------------------------------------
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
if (forced_to_abort())
{
unlock(general_lock());
@@ -907,12 +916,14 @@
// al threads, because aborted threads will try to obtain the
// transactionsInFlightMutex
//-----------------------------------------------------------------------
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
lock_all_mutexes();
lock(inflight_lock());
#if PERFORMING_COMPOSITION
if (other_in_flight_same_thread_transactions())
{
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
transactionsInFlight_.erase(this);
state_ = e_hand_off;
unlock_all_mutexes();
@@ -924,10 +935,13 @@
#endif
{
// commit releases the inflight mutex as soon as its done with it
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
invalidating_deferred_commit();
}
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
++global_clock();
+ //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
}
}
Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -58,22 +58,34 @@
inline T * get() {
return ptr_;
}
- virtual base_transaction_object* clone() const {
+
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual base_transaction_object* clone(transaction* t) const {
+ cache* tmp = new(t) cache<T>(*this);
+#else
+ virtual base_transaction_object* clone(transaction*) const {
cache* tmp = new cache<T>(*this);
+#endif
if (tmp->value_!=0) {
tmp->ptr_ = new T(*value_);
}
return tmp;
}
-#ifdef BOOST_STM_USE_MEMCOPY
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual void cache_deallocate() {
+ delete ptr_;
+ ptr_=0;
+ this->~cache<T>();
+ boost::stm::cache_deallocate(this);
+ }
+#else
virtual void cache_deallocate() {
delete ptr_;
ptr_=0;
delete this;
}
-#endif
-
+#endif
virtual void copy_state(base_transaction_object const * const rhs) {
if (value_==0) return;
*value_= *(static_cast<cache<T> const * const>(rhs)->ptr_);
@@ -81,6 +93,29 @@
ptr_=0;
}
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ void* operator new(size_t size, transaction* t)
+ {
+ return boost::stm::cache_allocate<cache<T> >(t);
+ }
+#if USE_STM_MEMORY_MANAGER
+ void* operator new(size_t size) throw ()
+ {
+ return retrieve_mem(size);
+ }
+
+ void operator delete(void* mem)
+ {
+ return_mem(mem, sizeof(cache<T>));
+ }
+#else
+ void* operator new(size_t size) throw ()
+ {
+ return ::operator new(size);
+ }
+#endif
+#else
+
#if USE_STM_MEMORY_MANAGER
void* operator new(size_t size) throw ()
{
@@ -92,6 +127,8 @@
return_mem(mem, sizeof(cache<T>));
}
#endif
+#endif
+
private:
//cache(cache<T> const & r);
Added: sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -0,0 +1,161 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_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(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 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
+
+
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-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -177,7 +177,7 @@
#ifdef USE_SINGLE_THREAD_CONTEXT_MAP
struct tx_context
{
- #if defined(BOOST_STM_USE_MEMCOPY) && defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
+ #if defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
monotonic_storage<6*1000*1000> mstorage_;
#endif
MemoryContainerList newMem;
@@ -212,7 +212,6 @@
#endif
{
// the current transaction is 0
- //transactions_.push(static_cast<transaction*>(0));
transactions_.push(0);
#ifndef BOOST_STM_USE_BOOST_MUTEX
pthread_mutex_init(&mutex_, 0);
@@ -738,52 +737,6 @@
}
//--------------------------------------------------------------------------
- template <typename T>
- T* new_memory(T*)
- {
- if (forced_to_abort())
- {
- if (!direct_updating())
- {
- deferred_abort(true);
- throw aborted_tx("");
- }
-
-#ifndef DELAY_INVALIDATION_DOOMED_TXS_UNTIL_COMMIT
- cm_abort_on_new(*this);
-#endif
- }
- T *newNode = new T();
- newNode->transaction_thread(threadId_);
- newNode->new_memory(1);
- newMemoryList().push_back(newNode);
-
- return newNode;
- }
-
- //--------------------------------------------------------------------------
- template <typename T>
- T* new_memory_copy(T const &rhs)
- {
- if (forced_to_abort())
- {
- if (!direct_updating())
- {
- deferred_abort(true);
- throw aborted_tx("");
- }
-#ifndef DELAY_INVALIDATION_DOOMED_TXS_UNTIL_COMMIT
- cm_abort_on_new(*this);
-#endif
- }
- T *newNode = new T(rhs);
- newNode->transaction_thread(threadId_);
- newNode->new_memory(1);
- newMemoryList().push_back(newNode);
-
- return newNode;
- }
-
void throw_if_forced_to_abort_on_new() {
if (forced_to_abort()) {
if (!direct_updating()) {
@@ -796,6 +749,7 @@
}
}
+ //--------------------------------------------------------------------------
template <typename T>
T* as_new(T *newNode)
{
@@ -805,6 +759,22 @@
return newNode;
}
+ //--------------------------------------------------------------------------
+ template <typename T>
+ T* new_memory(T*)
+ {
+ throw_if_forced_to_abort_on_new();
+ return as_new(new T());
+ }
+
+ //--------------------------------------------------------------------------
+ template <typename T>
+ T* new_memory_copy(T const &rhs)
+ {
+ throw_if_forced_to_abort_on_new();
+ return as_new(new T(rhs));
+ }
+
void begin();
bool restart();
@@ -1028,7 +998,7 @@
}
in.transaction_thread(threadId_);
- writeList().insert(tx_pair((base_transaction_object*)&in, in.clone()));
+ writeList().insert(tx_pair((base_transaction_object*)&in, in.clone(this)));
#if USE_BLOOM_FILTER
bloom().insert((size_t)&in);
#endif
@@ -1171,7 +1141,7 @@
wbloom().set_bv2(bloom().h2());
//sm_wbv().set_bit((size_t)&in % sm_wbv().size());
#endif
- base_transaction_object* returnValue = in.clone();
+ base_transaction_object* returnValue = in.clone(this);
returnValue->transaction_thread(threadId_);
writeList().insert(tx_pair((base_transaction_object*)&in, returnValue));
#ifndef USE_BLOOM_FILTER
@@ -1633,7 +1603,8 @@
inline static TransactionsStack &transactions(thread_id_t id) {
return *threadTransactionsStack_.find(id)->second;
}
- private:
+ private:
+
////////////////////////////////////////
#else //BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP
@@ -1800,7 +1771,7 @@
return i->second->transactions_;
}
private:
-
+
#endif
@@ -1975,14 +1946,13 @@
};
-#ifdef BOOST_STM_USE_MEMCOPY
-template <class T> T* cache_allocate() {
- #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER)
+template <class T> T* cache_allocate(transaction* t) {
+ #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER)
return reinterpret_cast<T*>(T::retrieve_mem(sizeof(T)));
#elif defined(BOOST_STM_CACHE_USE_MALLOC)
return reinterpret_cast<T*>(malloc(sizeof(T)));
#elif defined(BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER)
- return reinterpret_cast<T*>(context_.mstorage_.allocate<T>());
+ return reinterpret_cast<T*>(t->context_.mstorage_.allocate<T>());
#else
#error "BOOST_STM_CACHE_USE_MEMORY_MANAGER, BOOST_STM_CACHE_USE_MALLOC or BOOST_STM_CACHE_USE_TSS_MONOTONIC_MEMORY_MANAGER must be defined"
#endif
@@ -2000,7 +1970,7 @@
struct cache_deallocate {
static void apply(T* ptr) {
if (ptr) {
- #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER)
+ #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER)
base_transaction_object::return_mem(ptr,sizeof(T));
#elif defined(BOOST_STM_CACHE_USE_MALLOC)
free(ptr);
@@ -2023,7 +1993,7 @@
template <class T>
inline void cache_deallocate(T* ptr) {
if (ptr) {
- #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER)
+ #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER
base_transaction_object::return_mem(ptr,sizeof(T));
#elif defined(BOOST_STM_CACHE_USE_MALLOC)
free(ptr);
@@ -2034,17 +2004,11 @@
}
}
#endif //BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#endif // BOOST_STM_USE_MEMCOPY
inline void cache_release(base_transaction_object* ptr) {
-#ifdef BOOST_STM_USE_MEMCOPY
ptr->cache_deallocate();
-#else
- delete ptr;
-#endif
}
-#ifdef BOOST_STM_USE_MEMCOPY
#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
namespace partial_specialization_workaround {
template <class T>
@@ -2052,8 +2016,8 @@
template <class T>
struct cache_clone {
- static inline T* apply(const T& val) {
- T* p = cache_allocate<T>();
+ static inline T* apply(transaction* t, const T& val) {
+ T* p = cache_allocate<T>(t);
if (p==0) {
throw std::bad_alloc();
}
@@ -2065,14 +2029,14 @@
} // partial_specialization_workaround
template <class T>
-inline T* cache_clone(const T& val) {
- return partial_specialization_workaround::cache_clone<T>::apply(val);
+inline T* cache_clone(transaction* t, const T& val) {
+ return partial_specialization_workaround::cache_clone<T>::apply(t, val);
}
#else //BOOST_STM_NO_PARTIAL_SPECIALIZATION
template <class T>
-inline T* cache_clone(const T& val) {
- T* p = cache_allocate<T>();
+inline T* cache_clone(transaction* t, const T& val) {
+ T* p = cache_allocate<T>(t);
if (p==0) {
throw std::bad_alloc();
}
@@ -2080,21 +2044,11 @@
return p;
}
#endif // BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#else
-template <class T>
-inline T* cache_clone(const T& val) {
- T* tmp=new T(val);
- return tmp;
-}
-#endif
template <class T> void cache_copy(const T* const ori, T* target);
-// When BOOST_STM_USE_MEMCOPY is defined
-// this function must be specialized for objects that are non transactional by deleting the object, e.g.
#ifdef BOOST_STM_NO_PARTIAL_SPECIALIZATION
-#ifdef BOOST_STM_USE_MEMCOPY
namespace partial_specialization_workaround {
template <class T> struct cache_copy;
@@ -2107,24 +2061,15 @@
};
} // partial_specialization_workaround
-#endif
template <class T> void cache_copy(const T* const ori, T* target) {
-#ifdef BOOST_STM_USE_MEMCOPY
partial_specialization_workaround::cache_copy<T>::apply(ori, target);
-#else
- *target=*ori;
-#endif
}
#else
template <class T> void cache_copy(const T* const ori, T* target) {
-#ifdef BOOST_STM_USE_MEMCOPY
memcpy(target, ori, sizeof(T));
-#else
- *target=*ori;
-#endif
}
#endif
Modified: sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -43,9 +43,10 @@
//-----------------------------------------------------------------------------
// transaction object mixin
// Provides the definition of the virtual functions
-// copy_state: relaying on the cache_copy<T> generic function
+// clone: use copy constructor
+// copy_state: use assignement
// move_state and
-// cache_deallocate: relaying on the cache_copy<T> generic function
+// 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
@@ -57,17 +58,37 @@
class transaction_object : public base_transaction_object
{
public:
+ typedef transaction_object<Derived, Base> this_type;
//--------------------------------------------------------------------------
- virtual base_transaction_object* clone() const {
- Derived* tmp = cache_clone(*static_cast<Derived const*>(this));
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual base_transaction_object* clone(transaction* t) const {
+ Derived* tmp = new(t) Derived(*static_cast<Derived const*>(this));
return tmp;
}
+#else
+ virtual base_transaction_object* clone(transaction*) const {
+ Derived* tmp = new Derived(*static_cast<Derived const*>(this));
+ return tmp;
+ }
+#endif
//--------------------------------------------------------------------------
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual void cache_deallocate() {
+ static_cast<Derived*>(this)->~Derived();
+ boost::stm::cache_deallocate(this);
+ }
+#else
+ virtual void cache_deallocate() {
+ delete this;
+ }
+#endif
+
+ //--------------------------------------------------------------------------
virtual void copy_state(base_transaction_object const * const rhs)
{
- boost::stm::cache_copy(static_cast<Derived const * const>(rhs), static_cast<Derived *>(this));
+ *static_cast<Derived *>(this) = *static_cast<Derived const * const>(rhs);
}
#if BUILD_MOVE_SEMANTICS
@@ -78,13 +99,30 @@
}
#endif
-#ifdef BOOST_STM_USE_MEMCOPY
- virtual void cache_deallocate() {
- boost::stm::cache_deallocate(this);
- }
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ void* operator new(size_t size, transaction* t)
+ {
+ return boost::stm::cache_allocate<Derived>(t);
+ }
+#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);
+ }
+#else
+ void* operator new(size_t size) throw ()
+ {
+ return ::operator new(size);
+ }
#endif
-
+#else
#if USE_STM_MEMORY_MANAGER
void* operator new(size_t size) throw ()
{
@@ -98,7 +136,7 @@
return_mem(mem, elemSize);
}
#endif
-
+#endif
};
template <typename T> class native_trans :
@@ -154,8 +192,7 @@
T value_;
};
-} // namespace core
-}
+}}
#endif // BOOST_STM_TRANSACTION_OBJECT__HPP
Modified: sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp 2009-10-12 02:32:37 EDT (Mon, 12 Oct 2009)
@@ -71,33 +71,64 @@
return *this;
}
- virtual base_transaction_object* clone() const {
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual base_transaction_object* clone(transaction* t) const {
+ //return cache_clone(*this);
+ return new(t) transactional_object<T>(*this);
+ }
+#else
+ virtual base_transaction_object* clone(transaction*) const {
+ //return cache_clone(*this);
return new transactional_object<T>(*this);
}
-
-#ifdef BOOST_STM_USE_MEMCOPY
+#endif
+
virtual void cache_deallocate() {
//boost::stm::cache_deallocate(this);
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);
+ //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(size_t size) throw ()
- {
- return retrieve_mem(size);
- }
-
- void operator delete(void* mem)
- {
- return_mem(mem, sizeof(transactional_object<T>));
- }
-#endif
+ #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ void* operator new(size_t size, transaction* t)
+ {
+ return cache_allocate<transactional_object<T> >(t);
+ }
+ #if USE_STM_MEMORY_MANAGER
+ void* operator new(size_t size) throw ()
+ {
+ return retrieve_mem(size);
+ }
+
+ void operator delete(void* mem)
+ {
+ return_mem(mem, sizeof(transactional_object<T>));
+ }
+ #else
+ void* operator new(size_t size) throw ()
+ {
+ return ::operator new(size);
+ }
+ #endif
+
+ #else
+
+ #if USE_STM_MEMORY_MANAGER
+ void* operator new(size_t size) throw ()
+ {
+ return retrieve_mem(size);
+ }
+
+ void operator delete(void* mem)
+ {
+ return_mem(mem, sizeof(transactional_object<T>));
+ }
+ #endif
+ #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