Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54249 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-22 22:37:27


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

Log:
Regions are now based on tag-types rather than numbers

Text files modified:
   sandbox/monotonic/boost/monotonic/forward_declarations.hpp | 13 ++++++--
   sandbox/monotonic/boost/monotonic/region_allocator.hpp | 12 ++++----
   sandbox/monotonic/boost/monotonic/static_storage.hpp | 57 +++++++++++++++++++--------------------
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp | 16 +++++-----
   sandbox/monotonic/libs/monotonic/test/monotonic.sln | 1
   5 files changed, 51 insertions(+), 48 deletions(-)

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 22:37:26 EDT (Mon, 22 Jun 2009)
@@ -42,15 +42,20 @@
                         , class Al = std::allocator<char> >
                 struct shared_storage;
 
+ /// tags for different storage regions
+ struct default_region_tag { };
+ struct shared_region_tag { };
+ struct thread_local_region_tag { };
+
                 /// thread-local storage
- template <
- size_t InlineSize = DefaultSizes::InlineSize
+ template <size_t InlineSize = DefaultSizes::InlineSize
                         , size_t MinHeapIncrement = DefaultSizes::MinHeapIncrement
                         , class Al = std::allocator<char> >
                 struct thread_local_storage;
 
                 /// a globally available storage buffer
- template <size_t InlineSize = DefaultSizes::StaticInlineSize
+ template <class Region = default_region_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
@@ -68,7 +73,7 @@
 
                 /// a monotonic region allocator uses a specified storage. Each region uses independent
                 /// storage that may be used and reset.
- template <class T, size_t Region = 0>
+ 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

Modified: sandbox/monotonic/boost/monotonic/region_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/region_allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/region_allocator.hpp 2009-06-22 22:37:26 EDT (Mon, 22 Jun 2009)
@@ -12,8 +12,8 @@
 {
         namespace monotonic
         {
- template <size_t N>
- struct region_allocator<void, N>
+ template <class Region>
+ struct region_allocator<void, Region>
                 {
                         typedef void* pointer;
                         typedef const void* const_pointer;
@@ -22,12 +22,12 @@
                         template <class U>
                         struct rebind
                         {
- typedef region_allocator<U, N> other;
+ typedef region_allocator<U, Region> other;
                         };
                 };
 
                 /// each region is distinct from other regions
- template <class T, size_t Region>
+ template <class T, class Region>
                 struct region_allocator : allocator_base<T, region_allocator<T, Region> >
                 {
                         typedef allocator_base<T, region_allocator<T, Region> > Parent;
@@ -59,8 +59,8 @@
                         region_allocator(const region_allocator& alloc) throw()
                                 : Parent(alloc) { }
 
- template <class U, size_t N>
- region_allocator(const region_allocator<U,N> &alloc) throw()
+ template <class U, class OtherRegion>
+ region_allocator(const region_allocator<U,OtherRegion> &alloc) throw()
                                 : Parent(alloc) { }
 
                         friend bool operator==(region_allocator<T,Region> const &A, region_allocator<T,Region> const &B)

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 22:37:26 EDT (Mon, 22 Jun 2009)
@@ -12,14 +12,18 @@
 {
         namespace monotonic
         {
- template <size_t InlineSize, size_t MinHeapIncrement, class Al, template <size_t, size_t, class> class Storage>
- struct static_storage_base : storage_base
+ template <class Region
+ , size_t InlineSize
+ , size_t MinHeapIncrement
+ , class Al
+ , template <size_t, size_t, class> class Storage>
+ struct static_storage_base
                 {
                         typedef Al HeapAllocator;
                         typedef Storage<InlineSize, MinHeapIncrement, HeapAllocator> StorageType;
 
                 private:
- StorageType global;
+ static StorageType global;
 
                 public:
                         static_storage_base()
@@ -29,44 +33,45 @@
                                 : global(store)
                         {
                         }
- void reset()
+ static StorageType &get_storage()
+ {
+ return global;
+ }
+ static void reset()
                         {
                                 global.reset();
                         }
- void release()
+ static void release()
                         {
                                 global.release();
                         }
- void *allocate(size_t num_bytes, size_t alignment)
+ static void *allocate(size_t num_bytes, size_t alignment)
                         {
                                 return global.allocate(num_bytes, alignment);
                         }
- size_t max_size() const
+ static size_t max_size()
                         {
                                 return global.max_size();
                         }
- size_t used() const
+ static size_t used()
                         {
                                 return global.used();
                         }
- size_t remaining() const
+ static size_t remaining()
                         {
                                 return global.remaining();
                         }
                 };
 
- /// 'static_storage' will be used by a default-constructed monotonic::allocator
- extern static_storage_base<> default_static_storage;
- extern storage_base *static_storage;
-
- extern storage_base *static_storage;
+ /// 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 boost::array<storage<DefaultSizes::RegionInlineSize>, DefaultSizes::MaxRegions> static_region_storage;
-
- template <size_t Region>
+ template <class Region>
                 inline storage_base &get_region_storage()
                 {
- return static_region_storage[Region];
+ return static_storage_base<Region>::get_storage();
                 }
 
                 template <size_t Region>
@@ -83,24 +88,18 @@
 
                 inline storage_base &get_storage()
                 {
- return static_storage ? *static_storage : default_static_storage;
- }
- inline storage_base *set_storage(storage_base &store)
- {
- storage_base *old = static_storage;
- static_storage = &store;
- return old;
+ return get_region_storage<default_region_tag>();// ? *static_storage : default_static_storage;
                 }
+
                 inline void reset_storage()
                 {
                         get_storage().reset();
                 }
- inline void default_storage()
+
+ inline void release_storage()
                 {
- static_storage = &default_static_storage;
+ get_storage().release();
                 }
-
-
         } // namespace monotonic
 
 } // namespace boost

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 22:37:26 EDT (Mon, 22 Jun 2009)
@@ -454,13 +454,13 @@
         return 0;
 }
 
-namespace boost
-{
- namespace monotonic
- {
- static_storage_base<> default_static_storage;
- storage_base *static_storage = &default_static_storage;
- }
-}
+//namespace boost
+//{
+// namespace monotonic
+// {
+// static_storage_base<> default_static_storage;
+// storage_base *static_storage = &default_static_storage;
+// }
+//}
 
 //EOF

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.sln
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.sln (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.sln 2009-06-22 22:37:26 EDT (Mon, 22 Jun 2009)
@@ -26,7 +26,6 @@
                 {470832FD-33D6-4F31-AD06-BB7838371077}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
                 {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Debug|Win32.ActiveCfg = Debug|Win32
                 {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Release|Win32.ActiveCfg = Release|Win32
- {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Release|Win32.Build.0 = Release|Win32
                 {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.ActiveCfg = Release|Win32
                 {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.Build.0 = Release|Win32
         EndGlobalSection


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