|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56792 - in sandbox/stm/branches/vbe/boost/stm: . detail non_tx tx
From: vicente.botet_at_[hidden]
Date: 2009-10-13 13:07:15
Author: viboes
Date: 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
New Revision: 56792
URL: http://svn.boost.org/trac/boost/changeset/56792
Log:
TBoost.STM:
* Added Embedded references
* Added Deleters
* Added transaction::as_new_array
* Added stm::current_transaction
Added:
sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/stm/language_like.hpp (contents, props changed)
Text files modified:
sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp | 94 ++++++++++++++++++++++-----------------
sandbox/stm/branches/vbe/boost/stm/detail/config.hpp | 8 +++
sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 16 ++++--
sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp | 4
sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp | 4
sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 44 ++++++++++++++----
sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp | 4
sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp | 8 +-
sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp | 16 +++---
9 files changed, 123 insertions(+), 75 deletions(-)
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-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -15,7 +15,6 @@
#define BOOST_STM_BASE_TRANSACTION_OBJECT__HPP
//-----------------------------------------------------------------------------
-//#include <stdarg.h>
#include <pthread.h>
//-----------------------------------------------------------------------------
#include <list>
@@ -58,10 +57,14 @@
{
public:
- base_transaction_object() : transactionThread_(kInvalidThread),
- newMemory_(0)
+ base_transaction_object()
+ : transactionThread_(kInvalidThread)
+ , newMemory_(0)
#if PERFORMING_VALIDATION
- ,version_(0)
+ , version_(0)
+#endif
+#if BOOST_STM_ALLOWS_EMBEDEEDS
+ , embeddeds_()
#endif
{}
@@ -72,33 +75,41 @@
#if PERFORMING_VALIDATION
, version_(0)
#endif
- {}
+#if BOOST_STM_ALLOWS_EMBEDEEDS
+ , embeddeds_()
+#endif
+ {}
#endif
- virtual base_transaction_object* clone(transaction* t) const = 0;
- virtual void copy_state(base_transaction_object const * const rhs) = 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;
+ virtual void move_state(base_transaction_object * rhs) = 0;
#else
- virtual void move_state(base_transaction_object * rhs) {};
+ virtual void move_state(base_transaction_object * rhs) {};
#endif
- virtual ~base_transaction_object() {};
+ virtual ~base_transaction_object() {};
virtual void cache_deallocate()=0;
- void transaction_thread(size_t rhs) const { transactionThread_ = rhs; }
- size_t const & transaction_thread() const { return transactionThread_; }
+ 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); }
+ static void alloc_size(size_t size) { memory_.alloc_size(size); }
#else
- static void alloc_size(size_t size) { }
+ 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_; }
+ void new_memory(size_t rhs) const { newMemory_ = rhs; }
+ size_t const & new_memory() const { return newMemory_; }
#if PERFORMING_VALIDATION
- size_t version_;
+ size_t version_;
+#endif
+
+#if BOOST_STM_ALLOWS_EMBEDEEDS
+ std::list<base_transaction_object*>& embeddeds() {return embeddeds_;}
+ void bind(base_transaction_object* bto) {embeddeds_.push_back(bto);}
#endif
//protected:
@@ -107,17 +118,17 @@
static void return_mem(void *mem, size_t size)
{
#ifndef BOOST_STM_USE_BOOST_MUTEX
- lock(&transactionObjectMutex_);
+ lock(&transactionObjectMutex_);
memory_.returnChunk(mem, size);
- unlock(&transactionObjectMutex_);
+ unlock(&transactionObjectMutex_);
#else
boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
memory_.returnChunk(mem, size);
#endif
}
- static void* retrieve_mem(size_t size)
- {
+ static void* retrieve_mem(size_t size)
+ {
#ifndef BOOST_STM_USE_BOOST_MUTEX
lock(&transactionObjectMutex_);
void *mem = memory_.retrieveChunk(size);
@@ -128,31 +139,34 @@
#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_;
+ //--------------------------------------------------------------------------
+ // 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_;
+ mutable size_t newMemory_;
#if USE_STM_MEMORY_MANAGER
- static Mutex transactionObjectMutex_;
- static MemoryPool<base_transaction_object> memory_;
+ static Mutex transactionObjectMutex_;
+ static MemoryPool<base_transaction_object> memory_;
+#endif
+#if BOOST_STM_ALLOWS_EMBEDEEDS
+ std::list<base_transaction_object*> embeddeds_;
#endif
};
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-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -86,6 +86,14 @@
#define BOOST_STM_NO_PARTIAL_SPECIALIZATION 1
+///////////////////////////////////////////////////////////////////////////////
+// Define BOOST_STM_ALLOWS_EMBEDEEDS when you want embeed TO
+#define BOOST_STM_ALLOWS_EMBEDEEDS 1
+
+///////////////////////////////////////////////////////////////////////////////
+// Define BOOST_STM_ALLOWS_DELETERS when you want STM manage with others deleters than delete
+#define BOOST_STM_ALLOWS_DELETERS 1
+
#endif // BOOST_STM_DETAIL_CONFIG_H
Added: sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/detail/deleters.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,192 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_DETAIL_DELETERS__HPP
+#define BOOST_STM_DETAIL_DELETERS__HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/base_transaction.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/datatypes.hpp>
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm { namespace detail {
+struct deleter {
+ virtual void reset()=0;
+ virtual void release()=0;
+};
+
+template <typename T>
+struct base_transaction_object_deleter : deleter {
+ T* ptr_;
+ base_transaction_object_deleter(T* ptr) : ptr_(ptr) {}
+ virtual void reset() {
+ static_cast<base_transaction_object*>(ptr_)->transaction_thread(kInvalidThread);
+ };
+ virtual void release() {
+ delete ptr_;
+ };
+};
+
+template <typename T>
+struct base_transaction_object_array_deleter : deleter {
+ T* ptr_;
+ std::size_t size_;
+ base_transaction_object_array_deleter (T* ptr, std::size_t size) : ptr_(ptr), size_(size) {}
+ virtual void reset() {
+ for (int i =0; i< size_; ++i) {
+ static_cast<base_transaction_object*>(ptr_+i)->transaction_thread(kInvalidThread);
+ static_cast<base_transaction_object*>(ptr_+i)->new_memory(0);
+ }
+ };
+ virtual void release() {
+ delete [] ptr_;
+ };
+};
+
+template <typename T>
+struct non_transaction_object_deleter : deleter {
+ T* ptr_;
+ typedef typename T::binds_list binds_type;
+ typedef typename T::binds_list::iterator binds_iterator;
+
+ non_transaction_object_deleter(T* ptr) : ptr_(ptr){}
+ virtual void reset() {
+ binds_type& binds= ptr_->binds();
+ for (binds_iterator it =binds.begin(); it!= binds.end(); ++it) {
+ static_cast<base_transaction_object*>(*it)->transaction_thread(kInvalidThread);
+ static_cast<base_transaction_object*>(*it)->new_memory(0);
+ }
+ };
+ virtual void release() {
+ delete ptr_;
+ };
+};
+
+// For array of non transactional object types
+
+template <typename T>
+struct non_transaction_object_array_deleter : deleter {
+ T* ptr_;
+ std::size_t size_;
+ typedef typename T::binds_list binds_type;
+ typedef typename T::binds_list::iterator binds_iterator;
+
+ non_transaction_object_array_deleter(T* ptr, std::size_t size) : ptr_(ptr), size_(size) {}
+ virtual void reset() {
+ for (int i =0; i< size_; ++i) {
+ binds_type& binds= (ptr_+i)->binds();
+ for (binds_iterator it =binds.begin(); it!= binds.end(); ++it) {
+ static_cast<base_transaction_object*>(*it)->transaction_thread(kInvalidThread);
+ static_cast<base_transaction_object*>(*it)->new_memory(0);
+ }
+ }
+ };
+ virtual void release() {
+ delete [] ptr_;
+ };
+};
+
+
+#ifndef BOOST_STM_ALLOWS_DELETERS
+ typedef base_transaction_object deleter_type;
+ inline void reset(deleter_type* ptr) {
+ ptr->transaction_thread(kInvalidThread);
+ ptr->new_memory(0);
+ }
+ inline void release(deleter_type* ptr) {
+ delete ptr;
+ }
+
+ inline deleter_type* make(base_transaction_object* p) {
+ return p;
+ }
+ inline deleter_type* make(base_transaction_object& r) {
+ return &r;
+ }
+ inline deleter_type* make(base_transaction_object const* p) {
+ return const_cast<deleter_type*>(p);
+ }
+ inline deleter_type* make(base_transaction_object const & r) {
+ return const_cast<deleter_type*>(&r);
+ }
+
+ inline deleter_type* make_array(base_transaction_object* p, std::size_t size) {
+ return p;
+ }
+ inline deleter_type* make_array(base_transaction_object& r, std::size_t size) {
+ return &r;
+ }
+ inline deleter_type* make_array(base_transaction_object const* p, std::size_t size) {
+ return const_cast<deleter_type*>(p);
+ }
+ inline deleter_type* make_array(base_transaction_object const & r, std::size_t size) {
+ return const_cast<deleter_type*>(&r);
+ }
+
+#else
+ typedef detail::deleter deleter_type;
+ inline void reset(deleter_type* ptr) {
+ ptr->reset();
+ delete ptr;
+ }
+ inline void release(deleter_type* ptr) {
+ ptr->release();
+ delete ptr;
+ }
+
+ template <typename T>
+ inline deleter_type* make(T* p) {
+ return new base_transaction_object_deleter<T>(p);
+ }
+ template <typename T>
+ inline deleter_type* make(T& r) {
+ return new base_transaction_object_deleter<T>(&r);
+ }
+ template <typename T>
+ inline deleter_type* make(T const* p) {
+ return new base_transaction_object_deleter<T>(const_cast<T*>(p));
+ }
+ template <typename T>
+ inline deleter_type* make(T const& r) {
+ return new base_transaction_object_deleter<T>(const_cast<T*>(&r));
+ }
+
+ template <typename T>
+ inline deleter_type* make_array(T* p, std::size_t size) {
+ return new base_transaction_object_array_deleter<T>(p, size);
+ }
+ template <typename T>
+ inline deleter_type* make_array(T& r, std::size_t size) {
+ return new base_transaction_object_array_deleter<T>(&r, size);
+ }
+ template <typename T>
+ inline deleter_type* make_array(T const* p, std::size_t size) {
+ return new base_transaction_object_array_deleter<T>(const_cast<T*>(p), size);
+ }
+ template <typename T>
+ inline deleter_type* make_array(T const& r, std::size_t size) {
+ return new base_transaction_object_array_deleter<T>(const_cast<T*>(&r, size));
+ }
+
+#endif
+}}}
+///////////////////////////////////////////////////////////////////////////////
+#endif // BOOST_STM_DETAIL_DELETERS__HPP
+
+
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-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -1806,7 +1806,7 @@
for (MemoryContainerList::iterator j = deletedMemoryList().begin();
j != deletedMemoryList().end(); ++j)
{
- (*j)->transaction_thread(kInvalidThread);
+ detail::reset(*j);
}
deletedMemoryList().clear();
@@ -1860,7 +1860,8 @@
{
for (MemoryContainerList::iterator j = i->second.begin(); j != i->second.end(); ++j)
{
- delete *j;
+ detail::release(*j);
+ // delete *j;
}
deletionBuffer_.erase(i);
i = deletionBuffer_.begin();
@@ -1892,7 +1893,8 @@
for (MemoryContainerList::iterator i = deletedMemoryList().begin();
i != deletedMemoryList().end(); ++i)
{
- delete *i;
+ detail::release(*i);
+ //delete *i;
}
deletedMemoryList().clear();
@@ -1903,7 +1905,8 @@
{
for (MemoryContainerList::iterator i = newMemoryList().begin(); i != newMemoryList().end(); ++i)
{
- delete *i;
+ detail::release(*i);
+ //delete *i;
}
newMemoryList().clear();
@@ -1914,8 +1917,9 @@
{
for (MemoryContainerList::iterator i = newMemoryList().begin(); i != newMemoryList().end(); ++i)
{
- (*i)->transaction_thread(kInvalidThread);
- (*i)->new_memory(0);
+ detail::reset(*i);
+ //(*i)->transaction_thread(kInvalidThread);
+ //(*i)->new_memory(0);
}
newMemoryList().clear();
Added: sandbox/stm/branches/vbe/boost/stm/language_like.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/language_like.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,267 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_LANGUAGE_LIKE__HPP
+#define BOOST_STM_LANGUAGE_LIKE__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction.hpp>
+
+//---------------------------------------------------------------------------
+// Transaction control constructs
+//---------------------------------------------------------------------------
+
+//---------------------------------------------------------------------------
+// do not remove if (). It is necessary a necessary fix for compilers
+// that do not destroy index variables of for loops. In addition, the
+// rand()+1 check is necessarily complex so smart compilers can't
+// optimize the if away
+//---------------------------------------------------------------------------
+
+#ifdef BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES
+#define BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND if (0==rnd()+1) {} else
+#else
+#define BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND
+#endif
+
+//---------------------------------------------------------------------------
+// Usage
+// BOOST_STM_USE_ATOMIC(_) {
+// transactional block
+// }
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_USE_ATOMIC(TX) \
+ BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND \
+ for (boost::stm::transaction TX; \
+ !TX.committed() && TX.restart(); \
+ TX.end())
+
+//---------------------------------------------------------------------------
+// Usage
+// BOOST_STM_TRY_ATOMIC(_) {
+// transactional block
+// } BOOST_STM_RETRY // or BOOST_STM_CACHE_BEFORE_RETRY(E)
+// // or BOOST_STM_BEFORE_RETRY
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TRY_ATOMIC(TX) \
+ BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND \
+ for (boost::stm::transaction TX; \
+ ! TX.committed() \
+ && TX.restart(); \
+ TX.no_throw_end()) try
+
+//---------------------------------------------------------------------------
+// Usage
+// BOOST_STM_TRY_ATOMIC(_) {
+// transactional block
+// } BOOST_STM_RETRY // or BOOST_STM_CACHE_BEFORE_RETRY(E)
+// // or BOOST_STM_BEFORE_RETRY
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_ATOMIC(TX) \
+ BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND \
+ for (boost::stm::transaction TX; \
+ ! TX.committed() \
+ && TX.check_throw_before_restart() \
+ && TX.restart_if_not_inflight(); \
+ TX.no_throw_end()) try
+
+//---------------------------------------------------------------------------
+// Catch a named abort exception leting the user to do somethink before retry
+//---------------------------------------------------------------------------
+#define BOOST_STM_CACHE_BEFORE_RETRY(E) catch (boost::stm::aborted_tx &E)
+
+//---------------------------------------------------------------------------
+// Catch a unnamed abort exception leting the user to do somethink before retry
+//---------------------------------------------------------------------------
+#define BOOST_STM_BEFORE_RETRY catch (boost::stm::aborted_tx &)
+
+//---------------------------------------------------------------------------
+// Catch a unnamed abort exception and retry
+//---------------------------------------------------------------------------
+#define BOOST_STM_RETRY catch (boost::stm::aborted_tx &) {}
+#define BOOST_STM_END_ATOM BOOST_STM_RETRY
+
+//---------------------------------------------------------------------------
+// Catch a named exception and re-throw it after commiting
+//---------------------------------------------------------------------------
+#define BOOST_STM_RETHROW(TX, E) catch (E&) {(TX).commit(); throw;}
+
+//---------------------------------------------------------------------------
+// Catch any exception and re-throw it after commiting
+//---------------------------------------------------------------------------
+#define BOOST_STM_RETHROW_ANY(TX) catch (...) {(TX).commit(); throw;}
+
+//---------------------------------------------------------------------------
+// Catch a named exception and abort the transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TX_ABORT_ON_EXCEPTION(TX, E) \
+ catch (E&) {(TX).abort();}
+//---------------------------------------------------------------------------
+// Catch any exception and abort the transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TX_ABORT_ANY(TX) \
+ catch (...) {(TX).abort();}
+
+//---------------------------------------------------------------------------
+// helper function to implement BOOST_STM_RETURN
+namespace boost { namespace stm { namespace detail {
+
+template <typename T>
+T commit_and_return(transaction&t, T expression) {
+ t.commit(); return expression;
+}
+
+}}}
+
+//---------------------------------------------------------------------------
+// return the expression EXPRESSION from inside a transaction T
+//---------------------------------------------------------------------------
+#define BOOST_STM_TX_RETURN(TX, EXPRESSION) \
+ return boost::stm::detail::commit_and_return(TX, EXPRESSION)
+
+//---------------------------------------------------------------------------
+// return the expression EXPRESSION from inside a transaction T
+//---------------------------------------------------------------------------
+#define BOOST_STM_RETURN(EXPRESSION) \
+ if (boost::stm::current_transaction()==0) return EXPRESSION; \
+ else BOOST_STM_TX_RETURN(*boost::stm::current_transaction(), EXPRESSION)
+
+//---------------------------------------------------------------------------
+// break: exit from the transaction block associate to T successfully
+//---------------------------------------------------------------------------
+#define BOOST_STM_BREAK continue
+
+//---------------------------------------------------------------------------
+// continue: exit from the transaction block associate to T successfully
+//---------------------------------------------------------------------------
+#define BOOST_STM_CONTINUE continue
+
+//---------------------------------------------------------------------------
+// goto : exit from the transaction block associate to T successfully jumping to the named label LABEL
+// Note thta label must be outside the transaction block.
+//---------------------------------------------------------------------------
+#define BOOST_STM_TX_GOTO(TX, LABEL) \
+ if (!TX.commit());else goto LABEL
+
+#define BOOST_STM_GOTO(LABEL) \
+ if (boost::stm::current_transaction()==0) goto LABEL; \
+ else BOOST_STM_TX_GOTO(*boost::stm::current_transaction(), LABEL)
+
+//---------------------------------------------------------------------------
+// aborts the transaction TX
+//---------------------------------------------------------------------------
+#define BOOST_STM_TX_ABORT(TX) TX.abort()
+
+//---------------------------------------------------------------------------
+// aborts the current transaction
+//---------------------------------------------------------------------------
+#define BOOST_STM_ABORT \
+ if (boost::stm::current_transaction()==0) ; \
+ else BOOST_STM_TX_ABORT(*boost::stm::current_transaction())
+
+//---------------------------------------------------------------------------
+// aborts the transaction TX
+//---------------------------------------------------------------------------
+#define BOOST_STM_TX_ABORT_ALL(TX) TX.abort()
+
+//---------------------------------------------------------------------------
+// aborts the current transaction
+//---------------------------------------------------------------------------
+#define BOOST_STM_ABORT_ALL \
+ if (boost::stm::current_transaction()==0) ; \
+ else BOOST_STM_ABORT_ALL(*boost::stm::current_transaction())
+
+//---------------------------------------------------------------------------
+// Memory management
+//---------------------------------------------------------------------------
+
+//---------------------------------------------------------------------------
+// creates a new allocated object on transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TX_NEW_PTR(TX, T_PARAMS) \
+ ((TX).throw_if_forced_to_abort_on_new(), \
+ (TX).as_new(new T_PARAMS))
+
+//---------------------------------------------------------------------------
+// creates a new array of object of type T on transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TX_NEW_ARRAY(TX, SIZE, T) \
+ ((TX).throw_if_forced_to_abort_on_new(), \
+ (TX).as_new_array(new T[SIZE], SIZE))
+
+
+//---------------------------------------------------------------------------
+// creates a new allocated object on the current transaction
+//---------------------------------------------------------------------------
+#define BOOST_STM_NEW_PTR(T_PARAMS) \
+ ((boost::stm::current_transaction()!=0) \
+ ? BOOST_STM_TX_NEW_PTR(*boost::stm::current_transaction() \
+ , T_PARAMS) \
+ : new T_PARAMS)
+
+//---------------------------------------------------------------------------
+// creates a new array of objects of type T on the current transaction
+//---------------------------------------------------------------------------
+#define BOOST_STM_NEW_ARRAY(SIZE, T) \
+ ((boost::stm::current_transaction()!=0) \
+ ? BOOST_STM_TX_NEW_ARRAY(*boost::stm::current_transaction() \
+ , SIZE, T) \
+ : new T[SIZE])
+
+//---------------------------------------------------------------------------
+// deletes the allocated object on transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TX_DELETE_PTR(TX, PTR) \
+ (TX).delete_tx_ptr(PTR);
+
+//---------------------------------------------------------------------------
+// deletes the allocated object on transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_TX_DELETE_ARRAY(TX, PTR) \
+ (TX).delete_tx_array(PTR);
+
+//---------------------------------------------------------------------------
+// deletes the allocated object on transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_DELETE_PTR(PTR) \
+ if (boost::stm::current_transaction()!=0) \
+ BOOST_STM_TX_DELETE_PTR(*boost::stm::current_transaction(), \
+ PTR) \
+ else delete PTR
+
+//---------------------------------------------------------------------------
+// deletes the allocated object on transaction TX
+//---------------------------------------------------------------------------
+
+#define BOOST_STM_DELETE_ARRAY(PTR) \
+ if (boost::stm::current_transaction()!=0) \
+ BOOST_STM_TX_DELETE_ARRAY(*boost::stm::current_transaction(), \
+ PTR) \
+ else delete [] PTR
+
+///////////////////////////////////////////////////////////////////////////////
+#endif // BOOST_STM_LANGUAGE_LIKE__HPP
+
+
Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/numeric.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -51,7 +51,7 @@
operator T&() { return ref(); }
T& ref() {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -65,7 +65,7 @@
}
T value() const {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/smart_ptr.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -107,14 +107,14 @@
template <typename T>
inline rd_ptr<T> make_rd_ptr(T* ptr) {
- transaction* tx = transaction::current_transaction();
+ transaction* tx = current_transaction();
assert(tx==0);
return rd_ptr<T>(*tx, ptr);
}
template <typename T>
inline rd_ptr<T> make_rd_ptr(T& ref) {
- transaction* tx = transaction::current_transaction();
+ transaction* tx = current_transaction();
assert(tx==0);
return rd_ptr<T>(*tx, ref);
}
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-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -32,6 +32,7 @@
#include <boost/stm/transaction_bookkeeping.hpp>
//-----------------------------------------------------------------------------
#include <boost/stm/detail/datatypes.hpp>
+#include <boost/stm/detail/deleters.hpp>
#include <boost/stm/detail/bloom_filter.hpp>
#include <boost/stm/detail/vector_map.hpp>
#include <boost/stm/detail/vector_set.hpp>
@@ -124,9 +125,9 @@
#endif
#ifndef MAP_NEW_CONTAINER
- typedef vector_set<base_transaction_object*> MemoryContainerList;
+ typedef vector_set<detail::deleter_type*> MemoryContainerList;
#else
- typedef std::list<base_transaction_object*> MemoryContainerList;
+ typedef std::list<detail::deleter_type*> MemoryContainerList;
#endif
@@ -733,7 +734,18 @@
{
newNode->transaction_thread(threadId_);
newNode->new_memory(1);
- newMemoryList().push_back(newNode);
+ newMemoryList().push_back(detail::make(newNode));
+
+ return newNode;
+ }
+
+ //--------------------------------------------------------------------------
+ template <typename T>
+ T* as_new_array(T *newNode, std::size_t size)
+ {
+ //newNode->transaction_thread(threadId_);
+ //newNode->new_memory(1);
+ newMemoryList().push_back(detail::make_array(newNode, size));
return newNode;
}
@@ -1000,8 +1012,7 @@
{
if (in.transaction_thread() == threadId_)
{
- //deletedMemoryList().push_back(&(T)in);
- deletedMemoryList().push_back((base_transaction_object*)&in);
+ deletedMemoryList().push_back(detail::make(in));
return;
}
@@ -1025,7 +1036,7 @@
// doesn't actually save any time for anything
//writeList()[(base_transaction_object*)&in] = 0;
- deletedMemoryList().push_back((base_transaction_object*)&in);
+ deletedMemoryList().push_back(detail::make(in));
}
}
#endif
@@ -1179,12 +1190,12 @@
if (j->second == (base_transaction_object*)&in)
{
writeList().insert(tx_pair(j->first, 0));
- deletedMemoryList().push_back(j->first);
+ deletedMemoryList().push_back(detail::make(j->first));
}
}
}
- deletedMemoryList().push_back((base_transaction_object *)&in);
+ deletedMemoryList().push_back(detail::make(in));
}
//--------------------------------------------------------------------------
@@ -1253,7 +1264,16 @@
void deferredCommitTransactionNewMemory();
void directAbortTransactionDeletedMemory() throw();
- void deferredAbortTransactionDeletedMemory() throw() { deletedMemoryList().clear(); }
+ void deferredAbortTransactionDeletedMemory() throw() {
+#ifdef BOOST_STM_ALLOWS_DELETERS
+ for (MemoryContainerList::iterator i = deletedMemoryList().begin();
+ i != deletedMemoryList().end(); ++i)
+ {
+ delete *i;
+ }
+#endif
+ deletedMemoryList().clear();
+ }
void directAbortTransactionNewMemory() throw() { deferredAbortTransactionNewMemory(); }
void deferredAbortTransactionNewMemory() throw();
@@ -1934,6 +1954,8 @@
};
+inline transaction* current_transaction() {return transaction::current_transaction();}
+
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)));
@@ -2119,7 +2141,7 @@
(T).as_new(new P))
#define BOOST_STM_NEW_1(P) \
- ((boost::stm::transaction::current_transaction()!=0)?BOOST_STM_NEW(*boost::stm::transaction::current_transaction(), P):new P)
+ ((boost::stm::current_transaction()!=0)?BOOST_STM_NEW(*boost::stm::current_transaction(), P):new P)
} // stm namespace
} // boost namespace
@@ -2136,6 +2158,6 @@
#endif
///////////////////////////////////////////////////////////////////////////////
-#endif // TRANSACTION_H
+#endif // BOOST_STM_TRANSACTION__HPP
Modified: sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -53,7 +53,7 @@
operator T&() { return ref(); }
T& ref() {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -66,7 +66,7 @@
}
T value() const {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
Modified: sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -51,7 +51,7 @@
operator T*&() { return get(); }
T*& get() {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -64,7 +64,7 @@
}
T const * get() const {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -111,7 +111,7 @@
operator R C::*&() { return get(); }
R C::*& get() {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -124,7 +124,7 @@
}
R C::* const * get() const {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
Modified: sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp 2009-10-13 13:07:14 EDT (Tue, 13 Oct 2009)
@@ -83,7 +83,7 @@
return &this->ref();
}
T& ref() {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -95,7 +95,7 @@
}
const T& ref() const {
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -214,7 +214,7 @@
}
T* get() const {
if (0==ptr_) return 0;
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx!=0) {
if (tx->forced_to_abort()) {
tx->lock_and_abort();
@@ -265,7 +265,7 @@
template <typename T>
void delete_ptr(tx_ptr<T> ptr) {
if (ptr.ptr_==0) return;
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx==0) delete ptr.ptr_;
tx->delete_tx_ptr(ptr.ptr_);
}
@@ -361,14 +361,14 @@
template <typename T>
rd_ptr<T> make_rd_ptr(tx_ptr<T> ptr) {
- transaction* tx = transaction::current_transaction();
+ transaction* tx = current_transaction();
assert(tx==0);
return rd_ptr<T>(*tx, ptr);
}
template <typename T>
rd_ptr<T> make_rd_ptr(tx_obj<T> const & ref) {
- transaction* tx = transaction::current_transaction();
+ transaction* tx = current_transaction();
assert(tx==0);
return rd_ptr<T>(*tx, ref);
}
@@ -418,7 +418,7 @@
template<class Y>
upgrd_ptr & operator=(tx_ptr<Y> const& r) { // never throws
//this_type(r).swap(*this);
- transaction* tx=transaction::current_transaction();
+ transaction* tx=current_transaction();
if (tx==0) throw "error";
tx_=tx;
ptr_=r.ptr_;
@@ -558,7 +558,7 @@
template <typename T>
inline wr_ptr<T> make_wr_ptr(tx_ptr<T>& ptr) {
- transaction* tx = transaction::current_transaction();
+ transaction* tx = current_transaction();
return wr_ptr<T>(*tx, ptr);
}
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