|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52714 - sandbox/stm/boost/stm/detail
From: justin_at_[hidden]
Date: 2009-05-01 23:41:03
Author: jgottschlich
Date: 2009-05-01 23:41:02 EDT (Fri, 01 May 2009)
New Revision: 52714
URL: http://svn.boost.org/trac/boost/changeset/52714
Log:
changed read and write transaction pointer implementations. at least temporarily removed upgradable pointer until Vicente and I can discuss it in more detail.
Text files modified:
sandbox/stm/boost/stm/detail/tx_ptr.hpp | 82 +++++++++++++--------------------------
1 files changed, 27 insertions(+), 55 deletions(-)
Modified: sandbox/stm/boost/stm/detail/tx_ptr.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/tx_ptr.hpp (original)
+++ sandbox/stm/boost/stm/detail/tx_ptr.hpp 2009-05-01 23:41:02 EDT (Fri, 01 May 2009)
@@ -23,11 +23,11 @@
namespace boost { namespace stm {
template <typename T>
-class tx_rd_ptr
+class read_ptr
{
public:
- tx_rd_ptr(transaction &t, T const &tx_obj) :
+ read_ptr(transaction &t, T const &tx_obj) :
t_(t), tx_ptr_(&const_cast<T&>(t_.read(tx_obj))), written_(false)
{}
@@ -57,82 +57,54 @@
T const & operator*() const { return *get(); }
T const * operator->() const { return get(); }
-private:
-
- mutable transaction &t_;
- mutable T *tx_ptr_;
- mutable bool written_;
-};
-
-template <typename T>
-class tx_wr_ptr;
-
-template <typename T>
-class tx_upgrd_ptr
-{
-public:
-
- tx_upgrd_ptr(transaction &t, T & tx_obj) :
- t_(t), tx_obj_(const_cast<T&>(t_.read(tx_obj))), upgraded_(false)
- {}
+ transaction &trans() { return t_; }
- const T* get()
+ T* write_ptr()
{
if (t_.forced_to_abort())
{
t_.lock_and_abort();
throw aborted_transaction_exception("aborting transaction");
}
- if (!upgraded_) {
- T &new_tx_obj_=const_cast<T&>(t_.read(tx_obj_));
- if (&new_tx_obj_!=&tx_obj_) {
- tx_obj_=new_tx_obj_;
- upgraded_=true;
- }
- }
- return &tx_obj_;
- }
- const T& operator*()
- {
- return *get();
- }
-
- const T* operator->()
- {
- return get();
- }
+ // we are already holding the written object
+ if (written_) return tx_ptr_;
+ T* temp = t_.get_written(*tx_ptr_);
+
+ // if we found something, store this as the tx_ptr_
+ if (0 != temp)
+ {
+ tx_ptr_ = temp;
+ written_ = true;
+ }
+ else
+ {
+ tx_ptr_ = &t_.write(*tx_ptr_);
+ written_ = true;
+ }
- T& upgrade() {
- tx_obj_=t_.write(tx_obj_);
- upgraded_=true;
- return tx_obj_;
+ return tx_ptr_;
}
private:
- //template <typename TT>
- friend class tx_wr_ptr;
-
+
mutable transaction &t_;
- mutable T &tx_obj_;
- bool upgraded_;
+ mutable T *tx_ptr_;
+ mutable bool written_;
};
-
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
template <typename T>
-class tx_wr_ptr
+class write_ptr
{
public:
- tx_wr_ptr(transaction &t, T & tx_obj) :
+ write_ptr(transaction &t, T & tx_obj) :
t_(t), tx_obj_(t_.write(tx_obj))
{}
- tx_wr_ptr(tx_upgrd_ptr<T> &upgrd) :
- t_(upgrd.t_), tx_obj_(upgrd.upgrade())
- {}
-
T& operator*()
{
if (t_.forced_to_abort())
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