Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54254 - in sandbox/monotonic: boost/monotonic libs/monotonic/test libs/monotonic/test/Tests
From: christian.schladetsch_at_[hidden]
Date: 2009-06-22 23:55:57


Author: cschladetsch
Date: 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
New Revision: 54254
URL: http://svn.boost.org/trac/boost/changeset/54254

Log:
removed shared_allocator<T>, local_allocator<T> and replaced with allocator<T,Region,shared_access_tag> and allocator<T,Region,thread_local_access_tag>

Text files modified:
   sandbox/monotonic/boost/monotonic/allocator.hpp | 27 ++++++--------
   sandbox/monotonic/boost/monotonic/forward_declarations.hpp | 52 ++++++++++++++++------------
   sandbox/monotonic/boost/monotonic/local.hpp | 3 +
   sandbox/monotonic/boost/monotonic/shared_allocator.hpp | 31 +++++++---------
   sandbox/monotonic/boost/monotonic/shared_storage.hpp | 25 ++++++++++---
   sandbox/monotonic/boost/monotonic/static_storage.hpp | 71 ++++++++++++++++-----------------------
   sandbox/monotonic/boost/monotonic/thread_local_storage.hpp | 46 +++++++++++++++----------
   sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp | 13 +++++++
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp | 30 ++++++++--------
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 8 ----
   10 files changed, 161 insertions(+), 145 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/allocator.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -12,8 +12,8 @@
 {
         namespace monotonic
         {
- template <class Region>
- struct allocator<void, Region>
+ template <class Region, class Access>
+ struct allocator<void, Region, Access>
                 {
                         typedef void* pointer;
                         typedef const void* const_pointer;
@@ -22,14 +22,14 @@
                         template <class U>
                         struct rebind
                         {
- typedef allocator<U, Region> other;
+ typedef allocator<U, Region, Access> other;
                         };
                 };
 
- template <class T, class Region>
- struct allocator : allocator_base<T, allocator<T, Region> >
+ template <class T, class Region, class Access>
+ struct allocator : allocator_base<T, allocator<T, Region, Access> >
                 {
- typedef allocator_base<T, allocator<T, Region> > Parent;
+ typedef allocator_base<T, allocator<T, Region, Access> > Parent;
                         using typename Parent::size_type;
                         using typename Parent::difference_type;
                         using typename Parent::pointer;
@@ -41,16 +41,13 @@
                         template <class U>
                         struct rebind
                         {
- typedef allocator<U, Region> other;
+ typedef allocator<U, Region, Access> other;
                         };
 
                         allocator() throw()
- : Parent(boost::monotonic::get_storage()) { }
+ : Parent(boost::monotonic::get_storage<Region,Access>()) { }
 
                 public:
- //private:
- template <class Storage> struct local;
-
                         allocator(storage_base &store) throw()
                                 : Parent(store) { }
 
@@ -58,16 +55,16 @@
                         allocator(const allocator& alloc) throw()
                                 : Parent(alloc) { }
 
- template <class U, class OtherRegion>
- allocator(const allocator<U, OtherRegion> &alloc) throw()
+ template <class U>
+ allocator(const allocator<U, Region, Access> &alloc) throw()
                                 : Parent(alloc) { }
 
- friend bool operator==(allocator<T,Region> const &A, allocator<T,Region> const &B)
+ friend bool operator==(allocator<T,Region, Access> const &A, allocator<T,Region, Access> const &B)
                         {
                                 return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
                         }
 
- friend bool operator!=(allocator<T,Region> const &A, allocator<T,Region> const &B)
+ friend bool operator!=(allocator<T,Region, Access> const &A, allocator<T,Region, Access> const &B)
                         {
                                 return static_cast<Parent const &>(A) != static_cast<Parent const &>(B);
                         }

Modified: sandbox/monotonic/boost/monotonic/forward_declarations.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/forward_declarations.hpp (original)
+++ sandbox/monotonic/boost/monotonic/forward_declarations.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -34,16 +34,25 @@
 
                 /// tags for different storage regions
                 struct default_region_tag { };
- struct shared_region_tag { };
- struct thread_local_region_tag { };
 
+ /// tags for different access types
+ struct default_access_tag { };
+ struct shared_access_tag { };
+ struct thread_local_access_tag { };
+
+ /// selector to create a storage type given accessor
+ namespace detail
+ {
+ template <class Access>
+ struct storage_type;
+ }
+
                 /// a RIIA structure for setting and resetting the global storage pointer
- template <class Region, class Storage = storage<> >
+ template <class Region, class Access = default_access_tag, class Storage = storage<> >
                 struct local;
 
                 /// thread-safe storage
- template <
- size_t InlineSize = DefaultSizes::InlineSize
+ template <size_t InlineSize = DefaultSizes::InlineSize
                         , size_t MinHeapIncrement = DefaultSizes::MinHeapIncrement
                         , class Al = std::allocator<char> >
                 struct shared_storage;
@@ -56,11 +65,10 @@
 
                 /// a globally available storage buffer
                 template <class Region = default_region_tag
+ , class Access = default_access_tag
                         , size_t InlineSize = DefaultSizes::StaticInlineSize
                         , size_t MinHeapIncrement = DefaultSizes::StaticMinHeapIncrement
- , class Al = std::allocator<char>
- , template <size_t, size_t, class> class Storage = storage
- >
+ , class Al = std::allocator<char> >
                 struct static_storage_base;
 
                 /// common to other monotonic allocators for type T of type Derived
@@ -68,24 +76,22 @@
                 struct allocator_base;
 
                 /// a monotonic allocator has a storage buffer and a no-op deallocate() method
- /// default to use static_storage_base<..., storage>
- template <class T, class Region = default_region_tag>
+ ///
+ /// each region uses independent storage
+ ///
+ /// each region is also factored over which access to use: global, shared, or thread-local storage
+ template <class T, class Region = default_region_tag, class Access = default_access_tag>
                 struct allocator;
 
- ///// a monotonic region allocator uses a specified storage. Each region uses independent
- ///// storage that may be used and reset.
- //template <class T, class Region = default_region_tag>
- //struct region_allocator;
-
- /// a monotonic shared_allocator has a shared storage buffer and a no-op deallocate() method
- /// defaults to use static_storage_base<..., shared_storage>
- template <class T, class Region = shared_region_tag>
- struct shared_allocator;
+ ///// a monotonic shared_allocator has a shared storage buffer and a no-op deallocate() method
+ ///// defaults to use static_storage_base<..., shared_storage>
+ template <class T, class Region = default_region_tag>
+ struct shared_allocator;// : allocator<T, Region, shared_access_tag> { };
         
- /// a monotonic local_allocator has a shared storage buffer and a no-op deallocate() method
- /// defaults to use static_storage_base<..., thread_local_storage>
- template <class T, class Region = thread_local_region_tag>
- struct local_allocator;
+ ///// a monotonic local_allocator has a shared storage buffer and a no-op deallocate() method
+ ///// defaults to use static_storage_base<..., thread_local_storage>
+ //template <class T, class Region = thread_local_region_tag>
+ //struct local_allocator;
 
         } // namespace monotonic
 

Modified: sandbox/monotonic/boost/monotonic/local.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/local.hpp (original)
+++ sandbox/monotonic/boost/monotonic/local.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -12,6 +12,7 @@
 {
         namespace monotonic
         {
+ /*
                 /// sets the global storage on construction, releases and returns to previous
                 /// storage on destruction
                 template <class Region, class Storage>
@@ -79,7 +80,7 @@
                         // return store.remaining();
                         //}
                 };
-
+*/
         } // namespace monotonic
 
 } // namespace boost

Modified: sandbox/monotonic/boost/monotonic/shared_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/shared_allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/shared_allocator.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -12,11 +12,8 @@
 {
         namespace monotonic
         {
- template <class>
- struct shared_allocator;
-
- template <>
- struct shared_allocator<void>
+ template <class Region>
+ struct shared_allocator<void, Region>
                 {
                         typedef void* pointer;
                         typedef const void* const_pointer;
@@ -25,14 +22,14 @@
                         template <class U>
                         struct rebind
                         {
- typedef shared_allocator<U> other;
+ typedef shared_allocator<U, Region> other;
                         };
                 };
 
- template <class T>
- struct shared_allocator : allocator_base<T, shared_allocator<T> >
+ template <class T, class Region>
+ struct shared_allocator : allocator_base<T, shared_allocator<T, Region> >
                 {
- typedef allocator_base<T, shared_allocator<T> > Parent;
+ typedef allocator_base<T, shared_allocator<T, Region> > Parent;
                         using typename Parent::size_type;
                         using typename Parent::difference_type;
                         using typename Parent::pointer;
@@ -41,31 +38,31 @@
                         using typename Parent::const_reference;
                         using typename Parent::value_type;
 
+ //typedef storage<DefaultSizes::InlineSize, DefaultSizes::MinHeapIncrement, std::allocator<char>, shared_storage>
+ // StorageType;
+
                         template <class U>
                         struct rebind
                         {
- typedef shared_allocator<U> other;
+ typedef shared_allocator<U, Region> other;
                         };
 
                         shared_allocator() throw()
- : Parent(static_shared_storage) { }
-
- //shared_allocator(shared_storage_base &store) throw()
- // : Parent(store) { }
+ : Parent(get_region_storage<Region>()) { }
 
                         shared_allocator(const shared_allocator& alloc) throw()
                                 : Parent(alloc) { }
 
                         template <class U>
- shared_allocator(const shared_allocator<U> &alloc) throw()
+ shared_allocator(const shared_allocator<U, Region> &alloc) throw()
                                 : Parent(alloc) { }
 
- friend bool operator==(shared_allocator<T> const &A, shared_allocator<T> const &B)
+ friend bool operator==(shared_allocator<T,Region> const &A, shared_allocator<T,Region> const &B)
                         {
                                 return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
                         }
 
- friend bool operator!=(shared_allocator<T> const &A, shared_allocator<T> const &B)
+ friend bool operator!=(shared_allocator<T,Region> const &A, shared_allocator<T,Region> const &B)
                         {
                                 return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
                         }

Modified: sandbox/monotonic/boost/monotonic/shared_storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/shared_storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/shared_storage.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -14,6 +14,19 @@
 {
         namespace monotonic
         {
+ namespace detail
+ {
+ template <>
+ struct storage_type<shared_access_tag>
+ {
+ template <size_t N, size_t M, class Al>
+ struct storage
+ {
+ typedef shared_storage<N,M,Al> type;
+ };
+ };
+ }
+
                 /// thread-safe storage
                 template <size_t InlineSize, size_t MinHeapSize, class Al>
                 struct shared_storage : shared_storage_base
@@ -70,12 +83,12 @@
 
                 };
 
- extern static_storage_base<
- DefaultSizes::StaticInlineSize
- , DefaultSizes::StaticMinHeapIncrement
- , std::allocator<char>
- , shared_storage>
- static_shared_storage;
+ //extern static_storage_base<
+ // DefaultSizes::StaticInlineSize
+ // , DefaultSizes::StaticMinHeapIncrement
+ // , std::allocator<char>
+ // , shared_storage>
+ //static_shared_storage;
                 
         } // namespace monotonic
 

Modified: sandbox/monotonic/boost/monotonic/static_storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/static_storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/static_storage.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -12,15 +12,29 @@
 {
         namespace monotonic
         {
+ namespace detail
+ {
+ template <>
+ struct storage_type<default_access_tag>
+ {
+ template <size_t N, size_t M, class Al>
+ struct storage
+ {
+ typedef monotonic::storage<N,M,Al> type;
+ };
+ };
+ }
+
                 template <class Region
+ , class Access
                         , size_t InlineSize
                         , size_t MinHeapIncrement
- , class Al
- , template <size_t, size_t, class> class Storage>
+ , class Al>
                 struct static_storage_base
                 {
                         typedef Al HeapAllocator;
- typedef Storage<InlineSize, MinHeapIncrement, HeapAllocator> StorageType;
+ typedef detail::storage_type<Access> Selector;
+ typedef typename Selector::template storage<InlineSize, MinHeapIncrement, HeapAllocator>::type StorageType;
 
                 private:
                         static StorageType global;
@@ -59,56 +73,31 @@
                         }
                 };
 
- /// define the static storage member for all regions
- template <class Region, size_t InlineSize, size_t MinHeapIncrement, class Al, template <size_t, size_t, class> class Storage>
- typename static_storage_base<Region, InlineSize, MinHeapIncrement, Al, Storage>::StorageType
- static_storage_base<Region, InlineSize, MinHeapIncrement, Al, Storage>::global;
-
- extern storage_base *current_storage;
- template <class Region>
- inline storage_base &get_region_storage()
- {
- return static_storage_base<Region>::get_storage();
- }
-
- template <size_t Region>
- inline storage_base &reset_region()
- {
- return get_region_storage<Region>().reset();
- }
-
- template <size_t Region>
- inline storage_base &release_region()
- {
- return get_region_storage<Region>().release();
- }
+ /// define the static storage member for all regions with all access types
+ template <class Region
+ , class Access
+ , size_t InlineSize
+ , size_t MinHeapIncrement
+ , class Al>
+ typename static_storage_base<Region, Access, InlineSize, MinHeapIncrement, Al>::StorageType
+ static_storage_base<Region, Access, InlineSize, MinHeapIncrement, Al>::global;
 
- inline storage_base *set_storage(storage_base &store)
- {
- storage_base *old = current_storage;
- current_storage = &store;
- return old;
- }
+ template <class Region, class Access>
                 inline storage_base &get_storage()
                 {
- if (current_storage)
- return *current_storage;
- return get_region_storage<default_region_tag>();
- }
- inline void default_storage()
- {
- set_storage(get_region_storage<default_region_tag>());
+ return static_storage_base<Region,Access>::get_storage();
                 }
 
                 inline void reset_storage()
                 {
- get_storage().reset();
+ get_storage<default_region_tag, default_access_tag>().reset();
                 }
 
                 inline void release_storage()
                 {
- get_storage().release();
+ get_storage<default_region_tag, default_access_tag>().release();
                 }
+
         } // namespace monotonic
 
 } // namespace boost

Modified: sandbox/monotonic/boost/monotonic/thread_local_storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/thread_local_storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/thread_local_storage.hpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -14,60 +14,68 @@
 {
         namespace monotonic
         {
+ namespace detail
+ {
+ template <>
+ struct storage_type<thread_local_access_tag>
+ {
+ template <size_t N, size_t M, class Al>
+ struct storage
+ {
+ typedef thread_local_storage<N,M,Al> type;
+ };
+ };
+ }
+
                 /// thread-local storage
                 template <size_t InlineSize, size_t MinHeapSize, class Al>
                 struct thread_local_storage : shared_storage_base
                 {
- typedef storage<InlineSize, MinHeapSize, Al> AllocatorStorage;
- typedef boost::thread_specific_ptr<AllocatorStorage> Storage;
+ typedef storage<InlineSize, MinHeapSize, Al> Storage;
+ typedef boost::thread_specific_ptr<Storage> TLS_Storage;
                         typedef thread_local_storage<InlineSize, MinHeapSize, Al> This;
 
                 private:
- Storage store;
+ Storage storage;
+ TLS_Storage tls_store;
                         static void no_delete(Storage *) { }
 
                 public:
- thread_local_storage() : store(&This::no_delete)
+ thread_local_storage()
+ : tls_store(&This::no_delete)
                         {
- store.reset(&static_thread_local_storage);
+ tls_store.reset(&storage);
                         }
                         size_t used() const
                         {
- return store->used();
+ return tls_store->used();
                         }
                         void reset()
                         {
- store->reset();
+ tls_store->reset();
                         }
                         void release()
                         {
- store->release();
+ tls_store->release();
                         }
                         void *allocate(size_t num_bytes, size_t alignment)
                         {
- return store->allocate(num_bytes, alignment);
+ return tls_store->allocate(num_bytes, alignment);
                         }
                         size_t remaining() const
                         {
- return store->remaining();
+ return tls_store->remaining();
                         }
                         size_t fixed_remaining() const
                         {
- return store->fixed_remaining();
+ return tls_store->fixed_remaining();
                         }
                         size_t max_size() const
                         {
- return store->max_size();
+ return tls_store->max_size();
                         }
                 };
 
- extern static_storage_base<
- DefaultSizes::StaticInlineSize
- , DefaultSizes::StaticMinHeapIncrement
- , std::allocator<char>
- , thread_local_storage>
- static_thread_local_storage;
-
         } // namespace monotonic
 
 } // namespace boost

Modified: sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -7,6 +7,10 @@
 #include <boost/monotonic/extra/set.hpp>
 #include <boost/monotonic/extra/map.hpp>
 
+//#include <boost/monotonic/shared_allocator.hpp>
+#include <boost/monotonic/shared_storage.hpp>
+#include <boost/monotonic/thread_local_storage.hpp>
+
 #define BOOST_TEST_MODULE basic_test test
 #include <boost/test/unit_test.hpp>
 
@@ -22,6 +26,15 @@
 struct region0 {};
 struct region1 {};
 
+BOOST_AUTO_TEST_CASE(test_shared_allocation)
+{
+ typedef std::list<int, monotonic::allocator<int, region0, monotonic::shared_access_tag> > List0;
+ List0 list0;
+
+ typedef std::list<int, monotonic::allocator<int, region0, monotonic::thread_local_access_tag> > List1;
+ List1 list1;
+}
+
 BOOST_AUTO_TEST_CASE(test_regional_allocation)
 {
         typedef std::list<int, monotonic::allocator<int, region0> > List0;

Modified: sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -99,20 +99,20 @@
                 result.mono_elapsed = timer.elapsed();
         }
 
- if (types.Includes(Type::Monotonic))
- {
- srand(42);
- monotonic::local<local_tag> storage;
- boost::timer timer;
- for (size_t n = 0; n < count; ++n)
- {
- {
- fun.test(mono_alloc(), length);
- }
- storage.reset();
- }
- result.local_mono_elapsed = timer.elapsed();
- }
+ //if (types.Includes(Type::Monotonic))
+ //{
+ // srand(42);
+ // monotonic::local<local_tag> storage;
+ // boost::timer timer;
+ // for (size_t n = 0; n < count; ++n)
+ // {
+ // {
+ // fun.test(mono_alloc(), length);
+ // }
+ // storage.reset();
+ // }
+ // result.local_mono_elapsed = timer.elapsed();
+ //}
 
         if (types.Includes(Type::Standard))
         {
@@ -461,7 +461,7 @@
 {
         namespace monotonic
         {
- storage_base *current_storage = &get_region_storage<default_region_tag>();
+// storage_base *current_storage = &get_region_storage<default_region_tag>();
         }
 }
 

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-06-22 23:55:55 EDT (Mon, 22 Jun 2009)
@@ -287,14 +287,6 @@
>
                                 </File>
                                 <File
- RelativePath="..\..\..\boost\monotonic\local_allocator.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\boost\monotonic\shared_allocator.hpp"
- >
- </File>
- <File
                                         RelativePath="..\..\..\boost\monotonic\shared_storage.hpp"
>
                                 </File>


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