|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59685 - in sandbox/stm/branches/vbe/boost/stm: . detail memory_managers non_tx/detail synch tx
From: vicente.botet_at_[hidden]
Date: 2010-02-14 19:15:45
Author: viboes
Date: 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
New Revision: 59685
URL: http://svn.boost.org/trac/boost/changeset/59685
Log:
Boost.STM/vbe:
* renaming for language-like macros
* multiple inheritance works now
* cleanup
Added:
sandbox/stm/branches/vbe/boost/stm/safe_downcast.hpp (contents, props changed)
Text files modified:
sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp | 7
sandbox/stm/branches/vbe/boost/stm/cache_fct.hpp | 4
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp | 3
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp | 3
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp | 6
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp | 3
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp | 3
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp | 9
sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp | 3
sandbox/stm/branches/vbe/boost/stm/language_like.hpp | 106 +++++++++++------
sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manager.hpp | 4
sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp | 2
sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp | 2
sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 245 +++++++++++++++++++++++++++++++++------
sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp | 48 ++++++-
sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp | 126 +++++++++++++++++--
sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp | 2
sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp | 59 +++++++-
sandbox/stm/branches/vbe/boost/stm/tx/smart_ptr.hpp | 77 ++++++++++++
sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp | 55 +++++++-
20 files changed, 619 insertions(+), 148 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 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -24,6 +24,7 @@
#include <boost/stm/detail/config.hpp>
//-----------------------------------------------------------------------------
#include <boost/stm/datatypes.hpp>
+#include <boost/stm/safe_downcast.hpp>
//-----------------------------------------------------------------------------
#include <boost/stm/detail/memory_pool.hpp>
@@ -54,9 +55,7 @@
struct make_cache_aux<static_poly> {
template <typename T>
static T* apply(T & rhs, transaction& t) {
- //return T::make_cache(static_cast<T const&>(rhs), t);
- return T::make_cache(rhs, t);
- //return static_cast<T*>(rhs.make_cache(t));
+ return T::make_cache(&rhs, t);
}
};
@@ -64,7 +63,7 @@
struct make_cache_aux<dyn_poly> {
template <typename T>
static T* apply(T & rhs, transaction& t) {
- return static_cast<T*>(rhs.make_cache(t));
+ return boost::safe_polymorphic_downcast<T*>(rhs.make_cache(t));
};
};
}
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 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -41,8 +41,8 @@
void cache_release(base_transaction_object* ptr);
-template <class T> T* cache_allocate(transaction&);
-template <class T> void cache_deallocate(T*);
+template <class T> T* cache_allocate(transaction& t);
+template <class T> void cache_deallocate(T* ptr);
} // namespace core
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -65,7 +65,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //transaction *t = (transaction*)*i;
+ transaction *t = *i;
if (!t->irrevocable() &&
cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -72,7 +72,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //transaction *t = (transaction*)*i;
+ transaction *t = *i;
if (!t->irrevocable() &&
cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -59,7 +59,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //transaction *t = (transaction*)*i;
+ transaction *t = *i;
// if this tx is part of this thread, skip it (it's an LiT)
if (t->threadId_ == this_thread::get_id()) continue;
@@ -85,7 +86,8 @@
for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
{
- transaction *t = (transaction*)*it;
+ //transaction *t = (transaction*)*it;
+ transaction *t = *it;
t->force_to_abort();
t->block();
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -67,7 +67,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //transaction *t = (transaction*)*i;
+ transaction *t = *i;
if (!t->irrevocable() &&
cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -74,7 +74,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //~ transaction *t = (transaction*)*i;
+ transaction *t = *i;
if (!t->irrevocable() &&
cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -61,7 +61,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //~ transaction *t = (transaction*)*i;
+ transaction *t = *i;
// if this tx is part of this thread, skip it (it's an LiT)
if (t->threadId_ == this_thread::get_id()) continue;
@@ -84,7 +85,8 @@
{
for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
{
- transaction *t = (transaction*)*it;
+ //~ transaction *t = (transaction*)*it;
+ transaction *t = *it;
t->force_to_abort();
t->block();
@@ -128,7 +130,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //~ transaction *t = (transaction*)*i;
+ transaction *t = *i;
if (t->get_tx_conflicting_locks().find(mutex) != t->get_tx_conflicting_locks().end())
{
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -484,7 +484,8 @@
for (InflightTxes::iterator i = transactionsInFlight_.begin();
i != transactionsInFlight_.end(); ++i)
{
- transaction *t = (transaction*)*i;
+ //~ transaction *t = (transaction*)*i;
+ transaction *t = *i;
//--------------------------------------------------------------------
// if this tx's thread is the same thread iterating through the in-flight
Modified: sandbox/stm/branches/vbe/boost/stm/language_like.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/language_like.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/language_like.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -18,11 +18,36 @@
#include <boost/stm/detail/config.hpp>
//-----------------------------------------------------------------------------
#include <boost/stm/transaction.hpp>
+#include <cstring>
+//---------------------------------------------------------------------------
+// helper function to implement macros
namespace boost { namespace stm { namespace detail {
- inline bool no_opt_false() {return false;}
+
+bool no_opt_false() {return false;}
+
+template <typename T>
+T commit_and_return(transaction&t, T expression) {
+ t.commit(); return expression;
+}
+
+bool commit_expr(transaction&t) {
+ t.commit(); return true;
+}
+
+int get_int(const char* s) {
+ return 1+strlen(s);
+}
+
+void commit(std::nothrow_t, transaction&t)
+{
+ try { t.commit(); }
+ catch (...) {}
+}
+
}}}
+
//---------------------------------------------------------------------------
// Transaction control constructs
//---------------------------------------------------------------------------
@@ -45,6 +70,7 @@
#define BOOST_STM_LABEL_CONTINUE(TX) BOOST_JOIN(__boost_stm_continue_, TX)
#define BOOST_STM_LABEL_BREAK(TX) BOOST_JOIN(__boost_stm_break_, TX)
+#define BOOST_STM_LABEL_TRICK(TX) BOOST_JOIN(__boost_stm_trick_, TX)
#define BOOST_STM_VAR_STOP __boost_stm_stop_
#define BOOST_STM_MANAGE_BREAK_CONTINUE(TX) \
@@ -53,50 +79,64 @@
continue; \
BOOST_STM_LABEL_BREAK(TX): \
break; \
+ BOOST_STM_LABEL_TRICK(TX): \
+ if(boost::stm::detail::get_int(#TX)%3==0) goto BOOST_STM_LABEL_CONTINUE(TX); \
+ if(boost::stm::detail::get_int(#TX)%3==1) goto BOOST_STM_LABEL_BREAK(TX); \
+ if(boost::stm::detail::get_int(#TX)%3==2) goto BOOST_STM_LABEL_TRICK(TX); \
} else
//---------------------------------------------------------------------------
// Usage
-// BOOST_STM_USE_ATOMIC(_) {
-// transactional block
-// }
+// BOOST_STM_OUTER_TRANSACTION(_) {
+// ...
+// BOOST_STM_INNER_TRANSACTION(_) {
+// transactional block
+// }
+// ...
+// } BOOST_STM_RETRY // or BOOST_STM_CACHE_BEFORE_RETRY(E)
+// // or BOOST_STM_BEFORE_RETRY
//---------------------------------------------------------------------------
-#define BOOST_STM_USE_ATOMIC(TX) \
- BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND \
+#define BOOST_STM_INNER_TRANSACTION(TX) \
+ if (bool BOOST_STM_VAR_STOP = boost::stm::detail::no_opt_false()) {} else \
for (boost::stm::transaction TX; \
- ! TX.committed() \
- && TX.restart(); \
- TX.end())
+ ! BOOST_STM_VAR_STOP; \
+ BOOST_STM_VAR_STOP=true, TX.end())
-#define BOOST_STM_USE_ATOMIC_IN_LOOP(TX) \
+#define BOOST_STM_INNER_TRANSACTION_IN_LOOP(TX) \
BOOST_STM_MANAGE_BREAK_CONTINUE(TX) \
for (boost::stm::transaction TX; \
- ! TX.committed() \
- && TX.restart(); \
- TX.end())
+ ! BOOST_STM_VAR_STOP; \
+ BOOST_STM_VAR_STOP=true, TX.end())
+
+
+#define BOOST_STM_USE_ATOMIC(TX) BOOST_STM_INNER_TRANSACTION(TX)
+#define BOOST_STM_USE_ATOMIC_IN_LOOP(TX) BOOST_STM_INNER_TRANSACTION_IN_LOOP(TX)
//---------------------------------------------------------------------------
// Usage
-// BOOST_STM_TRY_ATOMIC(_) {
+// BOOST_STM_OUTER_TRANSACTION(_) {
// transactional block
// } BOOST_STM_RETRY // or BOOST_STM_CACHE_BEFORE_RETRY(E)
// // or BOOST_STM_BEFORE_RETRY
//---------------------------------------------------------------------------
-#define BOOST_STM_TRY_ATOMIC(TX) \
+#define BOOST_STM_OUTER_TRANSACTION(TX) \
BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND \
for (boost::stm::transaction TX; \
! TX.committed() \
&& TX.restart(); \
TX.no_throw_end()) try
-#define BOOST_STM_TRY_ATOMIC_IN_LOOP(TX) \
+#define BOOST_STM_OUTER_TRANSACTION_IN_LOOP(TX) \
BOOST_STM_MANAGE_BREAK_CONTINUE(TX) \
for (boost::stm::transaction TX; \
! TX.committed() \
&& TX.restart(); \
- TX.no_throw_end()) try
+ BOOST_STM_VAR_STOP=true, TX.no_throw_end()) try
+
+#define BOOST_STM_TRY_ATOMIC(TX) BOOST_STM_TRY_TRANSACTION(TX)
+#define BOOST_STM_TRY_ATOMIC_IN_LOOP(TX) BOOST_STM_TRY_TRANSACTION_IN_LOOP(TX)
//---------------------------------------------------------------------------
// Usage
@@ -106,7 +146,7 @@
// // or BOOST_STM_BEFORE_RETRY
//---------------------------------------------------------------------------
-#define BOOST_STM_ATOMIC(TX) \
+#define BOOST_STM_TRANSACTION(TX) \
BOOST_STM_COMPILER_DONT_DESTROY_FOR_VARIABLES_WORKAROUND \
for (boost::stm::transaction TX; \
! TX.committed() \
@@ -114,14 +154,17 @@
&& TX.restart_if_not_inflight(); \
TX.no_throw_end()) try
-#define BOOST_STM_ATOMIC_IN_LOOP(TX) \
+#define BOOST_STM_TRANSACTION_IN_LOOP(TX) \
BOOST_STM_MANAGE_BREAK_CONTINUE(TX) \
for (boost::stm::transaction TX; \
! TX.committed() \
&& TX.check_throw_before_restart() \
&& TX.restart_if_not_inflight(); \
- TX.no_throw_end()) try
+ BOOST_STM_VAR_STOP=true, TX.no_throw_end()) try
+
+#define BOOST_STM_ATOMIC(TX) BOOST_STM_TRANSACTION(TX)
+#define BOOST_STM_ATOMIC_IN_LOOP(TX) BOOST_STM_TRANSACTION_IN_LOOP(TX)
//---------------------------------------------------------------------------
// Catch a named abort exception leting the user to do somethink before retry
@@ -142,12 +185,12 @@
//---------------------------------------------------------------------------
// Catch a named exception and re-throw it after commiting
//---------------------------------------------------------------------------
-#define BOOST_STM_RETHROW(TX, E) catch (E&) {(TX).commit(); throw;}
+#define BOOST_STM_RETHROW(TX, E) catch (E&) {boost::stm::detail::commit_expr(TX); throw;}
//---------------------------------------------------------------------------
// Catch any exception and re-throw it after commiting
//---------------------------------------------------------------------------
-#define BOOST_STM_RETHROW_ANY(TX) catch (...) {(TX).commit(); throw;}
+#define BOOST_STM_RETHROW_ANY(TX) catch (...) {boost::stm::detail::commit_expr(TX); throw;}
//---------------------------------------------------------------------------
// Catch a named exception and abort the transaction TX
@@ -163,24 +206,13 @@
catch (...) {(TX).force_to_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 TX
//---------------------------------------------------------------------------
#define BOOST_STM_TX_RETURN(TX, EXPRESSION) \
return boost::stm::detail::commit_and_return(TX, EXPRESSION)
#define BOOST_STM_TX_RETURN_NOTHING(TX) \
- if (!TX.commit());else return
+ if (!boost::stm::detail::commit_expr(TX));else return
//---------------------------------------------------------------------------
// return the expression EXPRESSION from inside a transaction TX
@@ -194,21 +226,21 @@
//---------------------------------------------------------------------------
#define BOOST_STM_BREAK(TX) \
- if (!TX.commit());else goto BOOST_STM_LABEL_BREAK(TX)
+ if (!boost::stm::detail::commit_expr(TX));else goto BOOST_STM_LABEL_BREAK(TX)
//---------------------------------------------------------------------------
// continue: exit from the transaction block associate to TX successfully
//---------------------------------------------------------------------------
#define BOOST_STM_CONTINUE(TX) \
- if (!TX.commit());else goto BOOST_STM_LABEL_CONTINUE(TX)
+ if (!boost::stm::detail::commit_expr(TX));else goto BOOST_STM_LABEL_CONTINUE(TX)
//---------------------------------------------------------------------------
// goto : exit from the transaction block associate to T successfully jumping to the named label LABEL
// Note that label must be outside the transaction block.
//---------------------------------------------------------------------------
#define BOOST_STM_TX_GOTO(TX, LABEL) \
- if (!TX.commit());else goto LABEL
+ if (!boost::stm::detail::commit_expr(TX));else goto LABEL
#define BOOST_STM_GOTO(LABEL) \
if (boost::stm::current_transaction()==0) goto LABEL; \
Modified: sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manager.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manager.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manager.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -39,7 +39,7 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// memory_manager mixin
-// Functions new and delete
+// Functions new and delete
// The parameter Base allows to mix memory_manager and polymorphism
// class B : memory_manager<B> {}
@@ -55,7 +55,7 @@
void* operator new(std::size_t size, const std::nothrow_t&) throw () {
return base_memory_manager::retrieve_mem(size);
}
-
+
void* operator new(std::size_t size) throw (std::bad_alloc) {
void* ptr= base_memory_manager::retrieve_mem(size);
if (ptr==0) throw std::bad_alloc();
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 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -203,7 +203,7 @@
res.reset(new cache<T>(const_cast<T*>(ptr)));
map_.insert(std::make_pair(const_cast<T*>(ptr), res.get()));
} else {
- if (typeid(it->second)==typeid(cache<T>*)) {
+ if (typeid(it->second)==typeid( cache<T>* )) {
res.reset(static_cast<cache<T>*>(it->second));
} else {
// When cached value do not corresponds to the type we need
Added: sandbox/stm/branches/vbe/boost/stm/safe_downcast.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/safe_downcast.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -0,0 +1,98 @@
+// boost cast.hpp header file ----------------------------------------------//
+
+// (C) Copyright Kevlin Henney and Dave Abrahams 1999.
+// 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/conversion for Documentation.
+
+
+#ifndef BOOST_SAFE_DOWNCAST__HPP
+#define BOOST_SAFE_DOWNCAST__HPP
+
+# include <boost/config.hpp>
+# include <boost/assert.hpp>
+# include <typeinfo>
+# include <boost/type.hpp>
+# include <boost/limits.hpp>
+# include <boost/detail/select_type.hpp>
+# include <boost/type_traits/is_virtual_base_of.hpp>
+# include <boost/type_traits/remove_pointer.hpp>
+# include <boost/mpl/or.hpp>
+
+# include <boost/cast.hpp>
+# include <boost/serialization/smart_cast.hpp>
+
+
+
+// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
+// time if you use a template function which has template parameters that don't
+// appear in the function's argument list.
+//
+// TODO: Add this to config.hpp?
+# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
+# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
+# else
+# define BOOST_EXPLICIT_DEFAULT_TARGET
+# endif
+
+namespace boost
+{
+
+// safe_polymorphic_downcast --------------------------------------------------------//
+
+// When the Base class is virtual inherited we need to use dynamic_cast to downcast.
+// Of course as most of the time the Derived class don't inherit virtualy from BASE a static_cast is enough
+
+ namespace detail {
+ template <typename IsVirtualBaseOf, class Target, class Source>
+ struct safe_polymorphic_downcast;
+
+ template <class Target, class Source>
+ struct safe_polymorphic_downcast<true_type, Target,Source> {
+ inline static Target apply(Source* x ) {
+ return dynamic_cast<Target>(x);
+ }
+ };
+ template <class Target, class Source>
+ struct safe_polymorphic_downcast<false_type, Target,Source> {
+ inline static Target apply(Source* x ) {
+ return static_cast<Target>(x);
+ //return polymorphic_downcast<Target>(x);
+ }
+ };
+
+ }
+ template <class Target, class Source>
+ inline Target safe_polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
+ {
+ #if 1
+ return serialization::smart_cast<Target, Source*>(x);
+ #else
+ typedef typename is_virtual_base_of<Source, typename remove_pointer<Target>::type >::type IsVirtualBaseOf;
+ return detail::safe_polymorphic_downcast<true_type,Target,Source>::apply(x);
+ #endif
+ }
+
+ template <class Target, class Inter, class Source>
+ inline Target safe_polymorphic_downcast_2(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
+ {
+ typedef typename is_virtual_base_of<Source, Inter >::type IsVirtualBaseOf;
+ return detail::safe_polymorphic_downcast<IsVirtualBaseOf,Target,Source>::apply(x);
+ }
+
+ template <class Target, class Inter1, class Inter2, class Source>
+ inline Target safe_polymorphic_downcast_3(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
+ {
+ typedef integral_constant<bool,
+ is_virtual_base_of<Source, Inter1>::type::value || is_virtual_base_of<Source, Inter2>::type::value
+ > IsVirtualBaseOf;
+ return detail::safe_polymorphic_downcast<IsVirtualBaseOf,Target,Source>::apply(x);
+ }
+
+# undef BOOST_EXPLICIT_DEFAULT_TARGET
+
+} // namespace boost
+
+#endif // BOOST_CAST_HPP
Modified: sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -158,8 +158,6 @@
void lock_for(chrono::duration<Rep, Period> const & rel_time)
{transaction::::lock_for(the_lock(), rel_time);}
-protected:
- //TimedLock& the_lock() {return *static_cast<TimedLock*>(&this->lock_);}
};
#endif
Modified: sandbox/stm/branches/vbe/boost/stm/transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -33,6 +33,7 @@
#ifdef BOOST_STM_USE_BOOST
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_base_of.hpp>
+#include <boost/fusion/include/is_sequence.hpp>
#endif
//-----------------------------------------------------------------------------
#include <boost/stm/base_transaction.hpp>
@@ -49,6 +50,7 @@
#include <boost/stm/detail/transactions_stack.hpp>
#include <boost/stm/detail/vector_map.hpp>
#include <boost/stm/detail/vector_set.hpp>
+#include <boost/stm/safe_downcast.hpp>
//-----------------------------------------------------------------------------
namespace boost { namespace stm {
@@ -416,13 +418,13 @@
if (1 == in.new_memory()) return in;
if (in.transaction_thread() == invalid_thread_id()) return in;
- base_transaction_object *inPtr = (base_transaction_object*)∈
+ //base_transaction_object *inPtr = (base_transaction_object*)∈
for (WriteContainer::iterator i = writeList().begin(); i != writeList().end(); ++i)
{
- if (i->second == (inPtr))
+ if (i->second == &in)
{
- return *static_cast<T*>(i->first);
+ return *boost::safe_polymorphic_downcast<T*>(i->first);
}
}
@@ -432,6 +434,34 @@
throw aborted_transaction_exception("original not found");
}
+ template <typename T>
+ T* find_original_ptr(T* ptr)
+ {
+ //-----------------------------------------------------------------------
+ // if transactionThread_ is not invalid it means this is the original, so
+ // we can return it. Otherwise, we need to search for the original in
+ // our write set
+ //-----------------------------------------------------------------------
+ if (1 == ptr->new_memory()) return ptr;
+ if (ptr->transaction_thread() == invalid_thread_id()) return ptr;
+
+ //base_transaction_object *inPtr = ptr;
+
+ for (WriteContainer::iterator i = writeList().begin(); i != writeList().end(); ++i)
+ {
+ if (i->second == ptr)
+ {
+ return boost::safe_polymorphic_downcast<T*>(i->first);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // if it's not in our original / new list, then we need to except
+ //-----------------------------------------------------------------------
+ throw aborted_transaction_exception("original not found");
+ }
+
+
//--------------------------------------------------------------------------
// The below methods change their behavior based on whether the transaction
// is direct or deferred:
@@ -471,15 +501,29 @@
{
if (direct_updating())
{
- if (in.transaction_thread() == threadId_) return (T*)(&in);
+ if (in.transaction_thread() == threadId_) return const_cast<T*>(&in);
else return 0;
}
else
{
- WriteContainer::iterator i = writeList().find
- ((base_transaction_object*)(&in));
+ WriteContainer::iterator i = writeList().find(const_cast<T*>(&in));
if (i == writeList().end()) return 0;
- else return static_cast<T*>(i->second);
+ else return boost::safe_polymorphic_downcast<T*>(i->second);
+ }
+ }
+ template <typename T>
+ T* get_written_ptr(T const * ptr)
+ {
+ if (direct_updating())
+ {
+ if (ptr->transaction_thread() == threadId_) return const_cast<T*>(ptr);
+ else return 0;
+ }
+ else
+ {
+ WriteContainer::iterator i = writeList().find(const_cast<T*>(ptr));
+ if (i == writeList().end()) return 0;
+ else return boost::safe_polymorphic_downcast<T*>(i->second);
}
}
@@ -488,8 +532,9 @@
inline bool has_been_read(T const & in)
{
#ifndef DISABLE_READ_SETS
- ReadContainer::iterator i = readList().find
- (static_cast<base_transaction_object*>(&in));
+ //~ ReadContainer::iterator i = readList().find
+ //~ (static_cast<base_transaction_object*>(&in));
+ ReadContainer::iterator i = readList().find(&in);
//----------------------------------------------------------------
// if this object is already in our read list, bail
//----------------------------------------------------------------
@@ -542,11 +587,11 @@
}
//--------------------------------------------------------------------------
- template <typename Poly, typename T>
+ template <typename Poly, typename T>
T* write_ptr_poly(T* in)
{
if (0 == in) return 0;
- return &write_poly<Poly>(*in);
+ return &write_poly<Poly>(*in);
}
template <typename Poly, typename T>
inline T& write_poly(T& in)
@@ -567,7 +612,7 @@
//--------------------------------------------------------------------------
template <typename T>
- inline void delete_memory(T &in)
+ inline void delete_memory(T const&in)
{
if (direct_updating())
{
@@ -759,7 +804,7 @@
#endif
//--------------------------------------------------------------------------
template <typename T>
- T* new_shared_memory(T*)
+ T* new_shared_memory(T*/*ptr*/)
{
throw_if_forced_to_abort_on_new();
make_irrevocable();
@@ -768,7 +813,7 @@
//--------------------------------------------------------------------------
template <typename T>
- T* new_memory(T*)
+ T* new_memory(T*/*ptr*/)
{
throw_if_forced_to_abort_on_new();
return as_new(new T());
@@ -793,8 +838,13 @@
}
void end();
- bool commit() {end(); return true;}
- void no_throw_end();
+ void commit() { end(); }
+ void commit(std::nothrow_t)
+ {
+ try { end(); }
+ catch (...) {}
+ }
+ void no_throw_end();
void force_to_abort()
{
@@ -809,7 +859,8 @@
for (InflightTxes::iterator j = transactionsInFlight_.begin();
j != transactionsInFlight_.end(); ++j)
{
- transaction *t = (transaction*)*j;
+ //~ transaction *t = (transaction*)*j;
+ transaction *t = *j;
// if this is a parent or child tx, it must abort too
if (t->threadId_ == this->threadId_) t->forced_to_abort_ref() = true;
@@ -890,7 +941,8 @@
// otherwise, see if its in our read list
//--------------------------------------------------------------------
#ifndef DISABLE_READ_SETS
- ReadContainer::iterator i = readList().find((base_transaction_object*)&in);
+ //~ ReadContainer::iterator i = readList().find((base_transaction_object*)&in);
+ ReadContainer::iterator i = readList().find(&in);
if (i != readList().end()) return in;
#endif
#if USE_BLOOM_FILTER
@@ -920,14 +972,16 @@
//stm::lock(m);
WriteContainer* c = write_lists(in.transaction_thread());
- WriteContainer::iterator readMem = c->find((base_transaction_object*)&in);
+ //~ WriteContainer::iterator readMem = c->find((base_transaction_object*)&in);
+ WriteContainer::iterator readMem = c->find(const_cast<T*>(&in));
if (readMem == c->end())
{
std::cout << "owner did not contain item in write list" << std::endl;
}
#ifndef DISABLE_READ_SETS
- readList().insert((base_transaction_object*)readMem->second);
+ //~ readList().insert((base_transaction_object*)readMem->second);
+ readList().insert(readMem->second);
#endif
#if USE_BLOOM_FILTER
bloom().insert((std::size_t)readMem->second);
@@ -935,12 +989,13 @@
//unlock_tx();
++reads_;
- return *static_cast<T*>(readMem->second);
+ return *boost::safe_polymorphic_downcast<T*>(readMem->second);
}
// already have locked us above - in both if / else
#ifndef DISABLE_READ_SETS
- readList().insert((base_transaction_object*)&in);
+ //~ readList().insert((base_transaction_object*)&in);
+ readList().insert(&in);
#endif
#if USE_BLOOM_FILTER
bloom().insert((std::size_t)&in);
@@ -965,7 +1020,8 @@
//lock_tx();
// already have locked us above - in both if / else
#ifndef DISABLE_READ_SETS
- readList().insert((base_transaction_object*)&in);
+ //~ readList().insert((base_transaction_object*)&in);
+ readList().insert(&in);
#endif
#if USE_BLOOM_FILTER
bloom().insert((std::size_t)&in);
@@ -1004,7 +1060,8 @@
}
in.transaction_thread(threadId_);
- writeList().insert(tx_pair((base_transaction_object*)&in, detail::make_cache_aux<Poly>::apply(in , *this)));
+ //~ writeList().insert(tx_pair((base_transaction_object*)&in, detail::make_cache_aux<Poly>::apply(in , *this)));
+ writeList().insert(tx_pair(&in, detail::make_cache_aux<Poly>::apply(in , *this)));
#if USE_BLOOM_FILTER
bloom().insert((std::size_t)&in);
#endif
@@ -1013,7 +1070,7 @@
//--------------------------------------------------------------------------
template <typename T>
- void direct_delete_memory(T &in)
+ void direct_delete_memory(T const&in)
{
if (in.transaction_thread() == threadId_)
{
@@ -1079,6 +1136,72 @@
//--------------------------------------------------------------------------
template <typename T>
+ typename boost::enable_if<fusion::traits::is_sequence<T>, bool>::type
+ all_members_in_this_thread(T const & in, dummy<0> = 0) {
+ // not yet implemented
+ return false;
+ }
+
+ template <typename T>
+ typename boost::disable_if<fusion::traits::is_sequence<T>, bool>::type
+ all_members_in_this_thread(T const & in, dummy<1> = 0) {
+ return true;
+ }
+
+ template <typename T>
+ typename boost::enable_if<is_base_of<base_transaction_object, T>, bool>::type
+ all_in_this_thread(T const & in, dummy<0> = 0) {
+ return (in.transaction_thread() != threadId_) && all_members_in_this_thread(in);
+ }
+
+ template <typename T>
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, bool>::type
+ all_in_this_thread(T const & in, dummy<1> = 0) {
+ return all_members_in_this_thread(in);
+ }
+
+ template <typename T>
+ bool all_in_this_thread(T const * const in, std::size_t size, dummy<0> = 0) {
+ for (int i=size-1; i>=0; --i) {
+ if (!all_in_this_thread(in[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ //--------------------------------------------------------------------------
+ template <typename T>
+ static typename boost::enable_if<is_base_of<base_transaction_object, T>, bool>::type
+ valid_thread(T const &in, dummy<0> = 0) {
+ return in.transaction_thread() != invalid_thread_id();
+ }
+
+ template <typename T>
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, bool>::type
+ static valid_thread(T const &in, dummy<1> = 0) {
+ // not yet implemented
+
+ return in.transaction_thread() != invalid_thread_id();
+ }
+
+ //--------------------------------------------------------------------------
+ template <typename T>
+ static typename boost::enable_if<is_base_of<base_transaction_object, T>, void>::type
+ set_thread(T & in, thread_id_t thread_id, dummy<0> = 0) {
+ in.transaction_thread() = thread_id;
+ }
+
+ template <typename T>
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, void>::type
+ static set_thread(T & in, thread_id_t thread_id, dummy<1> = 0) {
+ // not yet implemented
+ in.transaction_thread() = thread_id;
+ }
+
+ //--------------------------------------------------------------------------
+ template <typename T>
void direct_delete_tx_array(T *in, std::size_t size)
{
bool all_in_this_thread = true;
@@ -1150,14 +1273,15 @@
if (writeList().empty()) return insert_and_return_read_memory(in);
#endif
- WriteContainer::iterator i = writeList().find
- ((base_transaction_object*)(&in));
+ //~ WriteContainer::iterator i = writeList().find
+ //~ ((base_transaction_object*)(&in));
+ WriteContainer::iterator i = writeList().find(const_cast<T*>(&in));
//----------------------------------------------------------------
// always check to see if read memory is in write list since it is
// possible to have already written to memory being read now
//----------------------------------------------------------------
if (i == writeList().end()) return insert_and_return_read_memory(in);
- else return *static_cast<T*>(i->second);
+ else return *boost::safe_polymorphic_downcast<T*>(i->second);
}
public:
@@ -1166,8 +1290,9 @@
T& insert_and_return_read_memory(T& in)
{
#ifndef DISABLE_READ_SETS
- ReadContainer::iterator i = readList().find
- (static_cast<base_transaction_object*>(&in));
+ //~ ReadContainer::iterator i = readList().find
+ //~ (static_cast<base_transaction_object*>(&in));
+ ReadContainer::iterator i = readList().find(&in);
//----------------------------------------------------------------
// if this object is already in our read list, bail
//----------------------------------------------------------------
@@ -1179,9 +1304,11 @@
//lock_tx();
#ifndef DISABLE_READ_SETS
#if PERFORMING_VALIDATION
- readList()[(base_transaction_object*)&in] = in.version_;
+ //~ readList()[(base_transaction_object*)&in] = in.version_;
+ readList()[&in] = in.version_;
#else
- readList().insert((base_transaction_object*)&in);
+ //~ readList().insert((base_transaction_object*)&in);
+ readList().insert(&in);
#endif
#endif
#if USE_BLOOM_FILTER
@@ -1207,8 +1334,9 @@
//----------------------------------------------------------------
if (in.transaction_thread() != invalid_thread_id()) return in;
- WriteContainer::iterator i = writeList().find
- (static_cast<base_transaction_object*>(&in));
+ //~ WriteContainer::iterator i = writeList().find
+ //~ (static_cast<base_transaction_object*>(&in));
+ WriteContainer::iterator i = writeList().find(&in);
//----------------------------------------------------------------
// if !in write set, add. lock first, for version consistency
//----------------------------------------------------------------
@@ -1227,17 +1355,19 @@
#endif
base_transaction_object* returnValue = detail::make_cache_aux<Poly>::apply(in, *this);
returnValue->transaction_thread(threadId_);
- writeList().insert(tx_pair((base_transaction_object*)&in, returnValue));
- return *static_cast<T*>(returnValue);
+ //~ writeList().insert(tx_pair((base_transaction_object*)&in, returnValue));
+ writeList().insert(tx_pair(&in, returnValue));
+ //return *static_cast<T*>(returnValue);
+ return *boost::safe_polymorphic_downcast<T*>(returnValue);
}
else {
- return *static_cast<T*>(i->second);
+ return *boost::safe_polymorphic_downcast<T*>(i->second);
}
}
//--------------------------------------------------------------------------
template <typename T>
- void deferred_delete_memory(T &in)
+ void deferred_delete_memory(T const&in)
{
if (forced_to_abort())
{
@@ -1254,7 +1384,8 @@
synchro::lock_guard<Mutex> lock(*mutex());
bloom().insert((std::size_t)&in);
}
- writeList().insert(tx_pair((base_transaction_object*)&in, 0));
+ //~ writeList().insert(tx_pair((base_transaction_object*)&in, 0));
+ writeList().insert(tx_pair(const_cast<T*>(&in), 0));
}
//-----------------------------------------------------------------------
// this isn't real memory, it's transactional memory. But the good news is,
@@ -1271,7 +1402,8 @@
// second location. If it's there, it means we made a copy of a piece
for (WriteContainer::iterator j = writeList().begin(); writeList().end() != j; ++j)
{
- if (j->second == (base_transaction_object*)&in)
+ //~ if (j->second == (base_transaction_object*)&in)
+ if (j->second == &in)
{
writeList().insert(tx_pair(j->first, 0));
deletedMemoryList().push_back(detail::make(j->first));
@@ -1329,6 +1461,33 @@
deletedMemoryList().push_back(detail::make_non_tx(in));
}
+ //--------------------------------------------------------------------------
+ template <typename T>
+ typename boost::enable_if<is_base_of<base_transaction_object, T>, void>::type
+ writeList_insert(T & in, dummy<0> = 0) {
+ writeList().insert(tx_pair(&in, 0));
+ }
+
+ template <typename T>
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, void>::type
+ writeList_insert(T & in, dummy<1> = 0) {
+ // not yet implemented
+ writeList().insert(tx_pair(&in, 0));
+ }
+ //--------------------------------------------------------------------------
+ template <typename T>
+ typename boost::enable_if<is_base_of<base_transaction_object, T>, void>::type
+ bloom_insert(T & in, dummy<0> = 0) {
+ bloom().insert((std::size_t)(&in));
+ }
+
+ template <typename T>
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, void>::type
+ bloom_insert(T & in, dummy<1> = 0) {
+ // not yet implemented
+ bloom().insert((std::size_t)(&in));
+ }
+
//--------------------------------------------------------------------------
template <typename T>
void deferred_delete_tx_array(T *in, std::size_t size)
@@ -1357,7 +1516,8 @@
}
}
for (int i=size-1; i>=0; --i) {
- writeList().insert(tx_pair((base_transaction_object*)(&in[i]), 0));
+ //~ writeList().insert(tx_pair((base_transaction_object*)(&in[i]), 0));
+ writeList().insert(tx_pair(&in[i], 0));
}
}
//-----------------------------------------------------------------------
@@ -1378,7 +1538,8 @@
for (int i=size-1; i>=0; --i)
for (WriteContainer::iterator j = writeList().begin(); writeList().end() != j; ++j)
{
- if (j->second == (base_transaction_object*)(&in[i]))
+ //~ if (j->second == (base_transaction_object*)(&in[i]))
+ if (j->second == &in[i])
{
writeList().insert(tx_pair(j->first, 0));
deletedMemoryList().push_back(detail::make(j->first));
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 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -35,6 +35,11 @@
//-----------------------------------------------------------------------------
namespace boost { namespace stm {
+template <class B>
+struct virtually : virtual B {
+ // forward constructors
+};
+
namespace detail {
template <class Final, class Base,
bool hasShallowCopySemantics,
@@ -50,9 +55,28 @@
template <class F, class B>
class transaction_object_aux<F, B, false, true>:
public trivial_transaction_object<F, B> {};
-template <class F, typename B>
+template <class F, class B>
class transaction_object_aux<F, B, false, false>:
public deep_transaction_object<F, B> {};
+
+template <class Final, class Base1,class Base2,
+ bool hasShallowCopySemantics,
+ bool hasTrivialCopySemantics>
+class transaction_object2_aux;
+
+template <class F, class B1, class B2>
+class transaction_object2_aux<F, B1, B2, true, true>:
+ public trivial_transaction_object2<F, B1, B2> {};
+template <class F, class B1, class B2>
+class transaction_object2_aux<F, B1, B2, true, false>:
+ public shallow_transaction_object2<F, B1, B2> {};
+template <class F, class B1, class B2>
+class transaction_object2_aux<F, B1, B2, false, true>:
+ public trivial_transaction_object2<F, B1,B2> {};
+template <class F, class B1, class B2>
+class transaction_object2_aux<F, B1, B2, false, false>:
+ public deep_transaction_object2<F, B1, B2> {};
+
}
#if 1
@@ -65,6 +89,18 @@
has_trivial_copy_semantics<Final>::value
>
{};
+
+template <
+ class Final,
+ class Base1,
+ class Base2
+>
+class transaction_object2 : public detail::transaction_object2_aux<Final, Base1, Base2,
+ has_shallow_copy_semantics<Final>::value,
+ has_trivial_copy_semantics<Final>::value
+ >
+{};
+
#else
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -88,13 +124,7 @@
memory_manager<Final, Base>
#else
Base
-#endif
-{
-#ifdef USE_STM_MEMORY_MANAGER
- typedef memory_manager<Final, Base> base_type;
-#else
- typedef Base base_type;
-#endif
+#endif{
public:
typedef transaction_object<Final, Base> this_type;
@@ -109,7 +139,7 @@
return p;
}
#else
- virtual base_transaction_object* make_cache(transaction*) const {
+ virtual base_transaction_object* make_cache(transaction*/*t*/) const {
Final* tmp = new Final(*static_cast<Final const*>(this));
return tmp;
}
Modified: sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/deep_transaction_object.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -61,37 +61,128 @@
Base
#endif
{
-#ifdef USE_STM_MEMORY_MANAGER
- typedef memory_manager<Final, Base> base_type;
+ Final* final() { return static_cast<Final*>(this); }
+ const Final* final() const { return static_cast<Final const*>(this); }
+public:
+
+ //--------------------------------------------------------------------------
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ static Final* make_cache(Final const* rhs, transaction& t) {
+ Final* p = cache_allocate<Final>(t);
+ ::new (p) Final(*rhs);
+ return p;
+ }
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ return make_cache(final(), t);
+ }
+#else
+ static Final* make_cache(Final const* rhs, transaction& ) {
+ Final* tmp = new Final(*rhs);
+ return tmp;
+ }
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ //~ Final* tmp = new Final(*boost::safe_polymorphic_downcast<Final const*>(this));
+ //~ Final* tmp = new Final(*boost::safe_polymorphic_downcast_2<Final const*, Base const>(this));
+ Final* tmp = new Final(*final());
+ return tmp;
+ }
+#endif
+
+ //--------------------------------------------------------------------------
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual void delete_cache() {
+ final()->~Final();
+ boost::stm::cache_deallocate(this);
+ }
+#else
+ virtual void delete_cache() {
+ delete this;
+ }
+#endif
+
+ //--------------------------------------------------------------------------
+ virtual void copy_cache(base_transaction_object const & rhs)
+ {
+ *final() =
+ *boost::safe_polymorphic_downcast_2<Final const *, Base const>(&rhs);
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ virtual void move_state(base_transaction_object * rhs)
+ {
+ *final() = draco_move
+ (*(boost::safe_polymorphic_downcast_2<Final*, Base>(rhs)));
+ }
+#endif
+
+};
+
+#if 0
+
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+template <class Final, typename Base>
+Final*
+deep_transaction_object<Final,Base>::
+make_cache(Final const* rhs, transaction& t) {
+ Final* p = cache_allocate<Final>(t);
+ ::new (p) Final(*rhs);
+ return p;
+ }
+template <class Final, typename Base>
+base_transaction_object*
+deep_transaction_object<Final,Base>::
+make_cache(transaction& t) const {
+ Final const* f=boost::safe_polymorphic_downcast_2<Final const*, Base const>(this);
+ return make_cache(f, t);
+ }
#else
- typedef Base base_type;
+template <class Final, typename Base>
+Final*
+deep_transaction_object<Final,Base>::
+make_cache(Final const* rhs, transaction& ) {
+ Final* tmp = new Final(*rhs);
+ return tmp;
+ }
+template <class Final, typename Base>
+base_transaction_object*
+deep_transaction_object<Final,Base>::
+make_cache(transaction& t) const {
+ Final* tmp = new Final(*boost::safe_polymorphic_downcast_2<Final const*, Base const>(this));
+ return tmp;
+ }
#endif
+#endif
+
+
+
+template <class Final, class Base1, class Base2>
+class deep_transaction_object2 :
+#ifdef USE_STM_MEMORY_MANAGER
+ public memory_manager<Final, Base1>, public Base2
+#else
+ public Base1, public Base2
+#endif
+{
public:
//--------------------------------------------------------------------------
#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
static Final* make_cache(Final const& rhs, transaction& t) {
Final* p = cache_allocate<Final>(t);
- ::new (p) Final(*static_cast<Final const*>(&rhs));
+ ::new (p) Final(*boost::safe_polymorphic_downcast_3<Final const*, Base1 const, Base2 const>(&rhs));
return p;
};
virtual base_transaction_object* make_cache(transaction& t) const {
- Final const& f=*static_cast<Final const*>(this);
+ Final const& f=*boost::safe_polymorphic_downcast_3<Final const*, Base1 const, Base2 const>(this);
return make_cache(f, t);
- //~ return make_cache(*static_cast<Final const*>(this), t);
- //~ Final* p = cache_allocate<Final>(t);
- //~ ::new (p) Final(*static_cast<Final const*>(this));
- //~ return p;
}
#else
static Final* make_cache(Final const& rhs, transaction& ) {
- Final* tmp = new Final(*static_cast<Final const*>(&rhs));
+ Final* tmp = new Final(*boost::safe_polymorphic_downcast_3<Final const*, Base1 const, Base2 const>(&rhs));
return tmp;
};
virtual base_transaction_object* make_cache(transaction& t) const {
- //~ Final const& f=*static_cast<Final const*>(this);
- //~ return make_cache(f, t);
- Final* tmp = new Final(*static_cast<Final const*>(this));
+ Final* tmp = new Final(*boost::safe_polymorphic_downcast_3<Final const*, Base1 const, Base2 const>(this));
return tmp;
}
#endif
@@ -99,7 +190,7 @@
//--------------------------------------------------------------------------
#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
virtual void delete_cache() {
- static_cast<Final*>(this)->~Final();
+ boost::safe_polymorphic_downcast_3<Final*, Base1, Base2>(this)->~Final();
boost::stm::cache_deallocate(this);
}
#else
@@ -111,21 +202,20 @@
//--------------------------------------------------------------------------
virtual void copy_cache(base_transaction_object const & rhs)
{
- *static_cast<Final *>(this) = *static_cast<Final const *>(&rhs);
+ *boost::safe_polymorphic_downcast_3<Final *, Base1, Base2>(this) = *boost::safe_polymorphic_downcast_3<Final const *, Base1 const, Base2 const>(&rhs);
}
#if BUILD_MOVE_SEMANTICS
virtual void move_state(base_transaction_object * rhs)
{
- static_cast<Final &>(*this) = draco_move
- (*(static_cast<Final*>(rhs)));
+ *boost::safe_polymorphic_downcast_3<Final *, Base1, Base2>(this) = draco_move
+ (*(boost::safe_polymorphic_downcast_3<Final*, Base1, Base2>(rhs)));
}
#endif
};
-
}}
//-----------------------------------------------------------------------------
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 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -71,12 +71,14 @@
return *this->value();
}
+ #if 0
T* operator->() {
return this->ref();
}
T& operator*() {
return *this->ref();
}
+ #endif
};
Modified: sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/shallow_transaction_object.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -65,26 +65,62 @@
Base
#endif
{
+ Final* final() { return static_cast<Final*>(this); }
+ const Final* final() const { return static_cast<Final const*>(this); }
+public:
+
+ static Final* make_cache(Final const* rhs, transaction& t) {
+ Final* p = cache_allocate<Final>(t);
+ return ::new(p) Final(*rhs, shallow);
+ };
+
+
+ //--------------------------------------------------------------------------
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ return make_cache(final(), t);
+ }
+
+ //--------------------------------------------------------------------------
+ virtual void delete_cache() {
+ boost::stm::cache_deallocate(this);
+ }
+
+ //--------------------------------------------------------------------------
+ virtual void copy_cache(base_transaction_object const &rhs)
+ {
+ final()->shallow_assign(*boost::safe_polymorphic_downcast_2<Final const *, Base const>(&rhs));
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ virtual void move_state(base_transaction_object * rhs)
+ {
+ *final() = draco_move(*(boost::safe_polymorphic_downcast_2<Final*, Base>(rhs)));
+ }
+#endif
+
+};
+
+template <class Final, class Base1, class Base2>
+class shallow_transaction_object2 :
#ifdef USE_STM_MEMORY_MANAGER
- typedef memory_manager<Final, Base> base_type;
-#else
- typedef Base base_type;
+ public memory_manager<Final, Base1>, public Base2
+#else
+ public Base1, public Base2
#endif
- Final& final() { return *static_cast<Final*>(this); }
- const Final& final() const { return *static_cast<Final const*>(this); }
+{
+ Final* final() { return static_cast<Final*>(this); }
+ const Final* final() const { return static_cast<Final const*>(this); }
public:
- static Final* make_cache(Final const& rhs, transaction& t) {
+ static Final* make_cache(Final const* rhs, transaction& t) {
Final* p = cache_allocate<Final>(t);
- return ::new(p) Final(rhs, shallow);
+ return ::new(p) Final(*rhs, shallow);
};
//--------------------------------------------------------------------------
virtual base_transaction_object* make_cache(transaction& t) const {
return make_cache(final(), t);
- //~ Final* p = cache_allocate<Final>(t);
- //~ return ::new(p) Final(final(), shallow);
}
//--------------------------------------------------------------------------
@@ -95,19 +131,18 @@
//--------------------------------------------------------------------------
virtual void copy_cache(base_transaction_object const &rhs)
{
- final().shallow_assign(*static_cast<Final const *>(&rhs));
+ final()->shallow_assign(*boost::safe_polymorphic_downcast_3<Final const *, Base1 const , Base2 const>(&rhs));
}
#if BUILD_MOVE_SEMANTICS
virtual void move_state(base_transaction_object * rhs)
{
- final() = draco_move(*(static_cast<Final*>(rhs)));
+ *final() = draco_move(*(boost::safe_polymorphic_downcast_3<Final*, Base1, Base2>(rhs)));
}
#endif
};
-
}}
#endif // BOOST_STM_SHALLOW_TRANSACTION_OBJECT__HPP
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 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -16,6 +16,83 @@
//-----------------------------------------------------------------------------
#include <boost/stm/tx_ptr.hpp>
+namespace boost { namespace stm { namespace tx {
+
+namespace detail {
+ template <typename T, bool IsConst>
+ struct open;
+
+ template <typename T>
+ struct open<T, true> {
+ T* apply(transaction& tx, T * ptr) {
+ return tx.read_ptr(ptr);
+ }
+ };
+ template <typename T>
+ struct open<T, false> {
+ T* apply(transaction& tx, T * ptr) {
+ return tx.write_ptr(ptr);
+ }
+ };
+}
+template <typename T>
+class tx_ptr {
+public:
+ typedef tx_ptr<T> this_type;
+ T * ptr_;
+
+ tx_ptr() : ptr_(0) {}
+ template<class Y>
+ explicit tx_ptr(Y * ptr) : ptr_(ptr) {}
+
+ template<class Y>
+ tx_ptr(tx_ptr<Y> const& r) : ptr_(r.ptr_) {}// never throws
+
+ template<class Y>
+ tx_ptr & operator=(tx_ptr<Y> const & r) { // never throws
+ //this_type(r).swap(*this);
+ ptr_=r.ptr_;
+ return *this;
+ }
+ template<class Y>
+ tx_ptr& operator=(transactional_object<Y>* ptr) { // never throws
+ ptr_=ptr;
+ return *this;
+ }
+
+ //bool operator==(const tx_ptr<T>& rhs) const {
+ // return ptr_==rhs.ptr_ || this->get()==rhs.ptr_ || ptr_==rhs.get();
+ //}
+
+ T* operator->() const {
+ return this->get();
+ }
+ T& operator*() const {
+ return *this->get();
+ }
+ T* get() const {
+ if (0==ptr_) return 0;
+ transaction* tx=current_transaction();
+ if (tx!=0) {
+ if (tx->forced_to_abort()) {
+ tx->lock_and_abort();
+ throw aborted_transaction_exception("aborting transaction");
+ }
+ return detail::open<T>::apply(*tx,ptr_);
+ }
+ return ptr_;
+ }
+
+ typedef transactional_object<T>* this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const {
+ return ptr_ == 0? 0: &this_type::ptr_;
+ }
+ void swap(tx_ptr & other) { // never throws
+ std::swap(ptr_, other.ptr_);
+ }
+};
+}}}
//-----------------------------------------------------------------------------
#endif // BOOST_STM_TX_SMART_PTR__HPP
Modified: sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/trivial_transaction_object.hpp 2010-02-14 19:15:43 EST (Sun, 14 Feb 2010)
@@ -73,23 +73,61 @@
Base
#endif
{
+ Final* final() { return static_cast<Final*>(this); }
+ const Final* final() const { return static_cast<Final const*>(this); }
+public:
+ static Final* make_cache(Final const* rhs, transaction& t) {
+ Final* p = cache_allocate<Final>(t);
+ std::memcpy(p, rhs.final(), sizeof(Final));
+ return p;
+ };
+
+ //--------------------------------------------------------------------------
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ Final* p = cache_allocate<Final>(t);
+ std::memcpy(p, final(), sizeof(Final));
+ return p;
+ }
+
+ //--------------------------------------------------------------------------
+ virtual void delete_cache() {
+ boost::stm::cache_deallocate(this);
+ }
+
+ //--------------------------------------------------------------------------
+ virtual void copy_cache(base_transaction_object const &rhs)
+ {
+ std::memcpy(final(), boost::safe_polymorphic_downcast_2<Final const *, Base const>(&rhs), sizeof(Final));
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ virtual void move_state(base_transaction_object * rhs)
+ {
+ *final() = draco_move(*(boost::safe_polymorphic_downcast_2<Final*, Base>(rhs)));
+ }
+#endif
+
+};
+
+template <class Final, class Base1, class Base2>
+class trivial_transaction_object2 :
#ifdef USE_STM_MEMORY_MANAGER
- typedef memory_manager<Final, Base> base_type;
-#else
- typedef Base base_type;
+ public memory_manager<Final, Base1>, public Base2
+#else
+ public Base1, public Base2
#endif
+{
Final* final() { return static_cast<Final*>(this); }
const Final* final() const { return static_cast<Final const*>(this); }
public:
- static Final* make_cache(Final const& rhs, transaction& t) {
+ static Final* make_cache(Final const* rhs, transaction& t) {
Final* p = cache_allocate<Final>(t);
- std::memcpy(p, static_cast<Final const*>(&rhs), sizeof(Final));
+ std::memcpy(p, rhs.final(), sizeof(Final));
return p;
};
//--------------------------------------------------------------------------
virtual base_transaction_object* make_cache(transaction& t) const {
- //~ return make_cache(*final(), t);
Final* p = cache_allocate<Final>(t);
std::memcpy(p, final(), sizeof(Final));
return p;
@@ -103,19 +141,18 @@
//--------------------------------------------------------------------------
virtual void copy_cache(base_transaction_object const &rhs)
{
- std::memcpy(final(), static_cast<Final const *>(&rhs), sizeof(Final));
+ std::memcpy(final(), boost::safe_polymorphic_downcast_3<Final const *, Base1 const, Base2 const>(&rhs), sizeof(Final));
}
#if BUILD_MOVE_SEMANTICS
virtual void move_state(base_transaction_object * rhs)
{
- *final() = draco_move(*(static_cast<Final*>(rhs)));
+ *final() = draco_move(*(boost::safe_polymorphic_downcast_3<Final*, Base1, Base2>(rhs)));
}
#endif
};
-
}}
#endif // BOOST_STM_TX_TRIVIAL_TRANSACTION_OBJECT__HPP
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