Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56869 - in sandbox/stm/branches/vbe/boost/stm: . non_tx/detail
From: vicente.botet_at_[hidden]
Date: 2009-10-15 11:44:39


Author: viboes
Date: 2009-10-15 11:44:38 EDT (Thu, 15 Oct 2009)
New Revision: 56869
URL: http://svn.boost.org/trac/boost/changeset/56869

Log:
TBoost.STM vbe:
* Simplifying BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER: instead of using specific placement operator use standard placement and use the cache_allocate.
Text files modified:
   sandbox/stm/branches/vbe/boost/stm/base_transaction_object.hpp | 15 ++++----
   sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp | 49 +++++++++++-----------------
   sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp | 10 ++++-
   sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp | 47 ++++-----------------------
   sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp | 67 +++++++++++++++++----------------------
   5 files changed, 72 insertions(+), 116 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-15 11:44:38 EDT (Thu, 15 Oct 2009)
@@ -57,7 +57,7 @@
 {
 public:
 
- base_transaction_object()
+ base_transaction_object()
         : transactionThread_(kInvalidThread)
         , newMemory_(0)
 #if PERFORMING_VALIDATION
@@ -94,12 +94,6 @@
     void transaction_thread(size_t rhs) const { transactionThread_ = rhs; }
     size_t const & transaction_thread() const { return transactionThread_; }
 
-#if USE_STM_MEMORY_MANAGER
- static void alloc_size(size_t size) { memory_.alloc_size(size); }
-#else
- static void alloc_size(size_t size) { }
-#endif
-
     void new_memory(size_t rhs) const { newMemory_ = rhs; }
     size_t const & new_memory() const { return newMemory_; }
 
@@ -109,9 +103,14 @@
 
 #if BOOST_STM_ALLOWS_EMBEDEEDS
     std::list<base_transaction_object*>& embeddeds() {return embeddeds_;}
- void bind(base_transaction_object* bto) {embeddeds_.push_back(bto);}
+ void bind(base_transaction_object* bto) {embeddeds_.push_back(bto);}
 #endif
 
+#if USE_STM_MEMORY_MANAGER
+ static void alloc_size(size_t size) { memory_.alloc_size(size); }
+#else
+ static void alloc_size(size_t size) { }
+#endif
 //protected:
 
 #if USE_STM_MEMORY_MANAGER

Modified: sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/non_tx/detail/cache_map.hpp 2009-10-15 11:44:38 EDT (Thu, 15 Oct 2009)
@@ -61,15 +61,20 @@
 
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
     virtual base_transaction_object* clone(transaction* t) const {
- cache* tmp = new(t) cache<T>(*this);
+ cache<T>* p = cache_allocate<cache<T> >(t);
+ if (p==0) {
+ throw std::bad_alloc();
+ }
+ ::new (p) cache<T>(*static_cast<cache<T> const*>(this));
+ return p;
 #else
     virtual base_transaction_object* clone(transaction*) const {
- cache* tmp = new cache<T>(*this);
+ cache* p = new cache<T>(*this);
 #endif
- if (tmp->value_!=0) {
- tmp->ptr_ = new T(*value_);
+ if (p->value_!=0) {
+ p->ptr_ = new T(*value_);
         }
- return tmp;
+ return p;
     }
 
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
@@ -93,41 +98,25 @@
         ptr_=0;
     }
 
-#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- void* operator new(size_t size, transaction* t)
- {
- return boost::stm::cache_allocate<cache<T> >(t);
- }
 #if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
+ void* operator new(size_t size, const std::nothrow_t&) throw ()
    {
       return retrieve_mem(size);
    }
-
- void operator delete(void* mem)
- {
- return_mem(mem, sizeof(cache<T>));
- }
-#else
- void* operator new(size_t size) throw ()
+ void* operator new(size_t size) throw (std::bad_alloc)
     {
- return ::operator new(size);
+ void* ptr= retrieve_mem(size);
+ if (ptr==0) throw std::bad_alloc;
+ return ptr;
     }
-#endif
-#else
-
-#if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
- {
- return retrieve_mem(size);
- }
 
- void operator delete(void* mem)
+ void operator delete(void* mem) throw ()
    {
- return_mem(mem, sizeof(cache<T>));
+ static cache<T> elem;
+ static size_t elemSize = sizeof(elem);
+ return_mem(mem, elemSize);
    }
 #endif
-#endif
 
 
 private:

Modified: sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/shallow_transaction_object.hpp 2009-10-15 11:44:38 EDT (Thu, 15 Oct 2009)
@@ -87,12 +87,18 @@
 
 
 #if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
+ void* operator new(size_t size, const std::nothrow_t&) throw ()
    {
       return retrieve_mem(size);
    }
+ void* operator new(size_t size) throw (std::bad_alloc)
+ {
+ void* ptr= retrieve_mem(size);
+ if (ptr==0) throw std::bad_alloc;
+ return ptr;
+ }
 
- void operator delete(void* mem)
+ void operator delete(void* mem) throw ()
    {
       static Derived elem;
       static size_t elemSize = sizeof(elem);

Modified: sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction_object.hpp 2009-10-15 11:44:38 EDT (Thu, 15 Oct 2009)
@@ -19,6 +19,7 @@
 #include <pthread.h>
 //-----------------------------------------------------------------------------
 #include <list>
+#include <new>
 //-----------------------------------------------------------------------------
 #include <boost/stm/detail/config.hpp>
 //-----------------------------------------------------------------------------
@@ -63,8 +64,12 @@
     //--------------------------------------------------------------------------
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
     virtual base_transaction_object* clone(transaction* t) const {
- Derived* tmp = new(t) Derived(*static_cast<Derived const*>(this));
- return tmp;
+ Derived* p = cache_allocate<Derived>(t);
+ if (p==0) {
+ throw std::bad_alloc();
+ }
+ ::new (p) Derived(*static_cast<Derived const*>(this));
+ return p;
     }
 #else
     virtual base_transaction_object* clone(transaction*) const {
@@ -99,13 +104,8 @@
    }
 #endif
 
-#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- void* operator new(size_t size, transaction* t)
- {
- return boost::stm::cache_allocate<Derived>(t);
- }
 #if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size, const nothrow_t&) throw ()
+ void* operator new(size_t size, const std::nothrow_t&) throw ()
    {
       return retrieve_mem(size);
    }
@@ -122,37 +122,6 @@
       static size_t elemSize = sizeof(elem);
       return_mem(mem, elemSize);
    }
-#else
- void* operator new(size_t size, const nothrow_t& nt) throw ()
- {
- return ::operator new(size, nt);
- }
- void* operator new(size_t size) throw (std::bad_alloc)
- {
- return ::operator new(size);
- }
-#endif
-#else
-#if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size, const nothrow_t&) throw ()
- {
- return retrieve_mem(size);
- }
-
- void* operator new(size_t size) throw (std::bad_alloc)
- {
- void* ptr= retrieve_mem(size);
- if (ptr==0) throw std::bad_alloc;
- return ptr;
- }
-
- void operator delete(void* mem) throw ()
- {
- static Derived elem;
- static size_t elemSize = sizeof(elem);
- return_mem(mem, elemSize);
- }
-#endif
 #endif
 };
 

Modified: sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transactional_object.hpp 2009-10-15 11:44:38 EDT (Thu, 15 Oct 2009)
@@ -73,8 +73,12 @@
 
 #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
     virtual base_transaction_object* clone(transaction* t) const {
- //return cache_clone(*this);
- return new(t) transactional_object<T>(*this);
+ transactional_object<T>* p = cache_allocate<transactional_object<T> >(t);
+ if (p==0) {
+ throw std::bad_alloc();
+ }
+ ::new (p) transactional_object<T>(*static_cast<transactional_object<T> const*>(this));
+ return p;
     }
 #else
     virtual base_transaction_object* clone(transaction*) const {
@@ -83,51 +87,40 @@
     }
 #endif
 
+#if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
+ virtual void cache_deallocate() {
+ static_cast<transactional_object<T>*>(this)->~transactional_object<T>();
+ boost::stm::cache_deallocate(this);
+ }
+#else
     virtual void cache_deallocate() {
- //boost::stm::cache_deallocate(this);
         delete this;
     }
+#endif
 
     virtual void copy_state(base_transaction_object const * const rhs) {
         //cache_copy(static_cast<transactional_object<T> const * const>(rhs), this);
         *this=*static_cast<transactional_object<T> const * const>(rhs);
     }
 
- #if BOOST_STM_USE_SPECIFIC_TRANSACTION_MEMORY_MANAGER
- void* operator new(size_t size, transaction* t)
- {
- return cache_allocate<transactional_object<T> >(t);
- }
     #if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
- {
- return retrieve_mem(size);
- }
-
- void operator delete(void* mem)
- {
- return_mem(mem, sizeof(transactional_object<T>));
- }
- #else
- void* operator new(size_t size) throw ()
- {
- return ::operator new(size);
- }
- #endif
-
- #else
-
- #if USE_STM_MEMORY_MANAGER
- void* operator new(size_t size) throw ()
- {
- return retrieve_mem(size);
- }
-
- void operator delete(void* mem)
- {
- return_mem(mem, sizeof(transactional_object<T>));
- }
- #endif
+ void* operator new(size_t size, const std::nothrow_t&) throw ()
+ {
+ return retrieve_mem(size);
+ }
+ void* operator new(size_t size) throw (std::bad_alloc)
+ {
+ void* ptr= retrieve_mem(size);
+ if (ptr==0) throw std::bad_alloc;
+ return ptr;
+ }
+
+ void operator delete(void* mem) throw ()
+ {
+ static transactional_object<T> elem;
+ static size_t elemSize = sizeof(elem);
+ return_mem(mem, elemSize);
+ }
     #endif
 
 };


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