Boost logo

Boost-Commit :

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


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

Log:
changed local<> to take a region tag

Text files modified:
   sandbox/monotonic/boost/monotonic/forward_declarations.hpp | 12 ++--
   sandbox/monotonic/boost/monotonic/local.hpp | 96 ++++++++++++++++++++--------------------
   sandbox/monotonic/boost/monotonic/static_storage.hpp | 15 +++++
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp | 38 +++++++-------
   4 files changed, 87 insertions(+), 74 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:47:40 EDT (Mon, 22 Jun 2009)
@@ -32,7 +32,12 @@
                         , class Al = std::allocator<char> >
                 struct storage;
 
- template <class Storage = storage<> >
+ /// tags for different storage regions
+ struct default_region_tag { };
+ struct shared_region_tag { };
+ struct thread_local_region_tag { };
+
+ template <class Region, class Storage = storage<> >
                 struct local;
 
                 /// thread-safe storage
@@ -42,11 +47,6 @@
                         , 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
                         , size_t MinHeapIncrement = DefaultSizes::MinHeapIncrement

Modified: sandbox/monotonic/boost/monotonic/local.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/local.hpp (original)
+++ sandbox/monotonic/boost/monotonic/local.hpp 2009-06-22 22:47:40 EDT (Mon, 22 Jun 2009)
@@ -14,70 +14,70 @@
         {
                 /// sets the global storage on construction, releases and returns to previous
                 /// storage on destruction
- template <class Storage>
- struct local : storage_base
+ template <class Region, class Storage>
+ struct local// : storage_base
                 {
                 private:
- Storage store;
+ //Storage store;
                         storage_base *old;
 
                 public:
                         local()
                         {
- old = set_storage(store);
+ old = set_storage(get_region_storage<Region>());
                         }
                         ~local()
                         {
- release();
+ release_storage();
                                 if (old)
                                         set_storage(*old);
                                 else
                                         default_storage();
                         }
 
- Storage &get_storage()
- {
- return store;
- }
- Storage const &get_storage() const
- {
- return store;
- }
- void reset()
- {
- store.reset();
- }
- void release()
- {
- store.release();
- }
-
- template <class T>
- allocator<T> make_allocator()
- {
- return allocator<T>(store);
- }
-
- // the number of bytes to allocate, and the alignment to use
- void *allocate(size_t num_bytes, size_t alignment)
- {
- return store.allocate(num_bytes, alignment);
- }
-
- size_t max_size() const
- {
- return store.max_size();
- }
-
- size_t used() const
- {
- return store.used();
- }
-
- size_t remaining() const
- {
- return store.remaining();
- }
+ //Storage &get_storage()
+ //{
+ // return store;
+ //}
+ //Storage const &get_storage() const
+ //{
+ // return store;
+ //}
+ static void reset()
+ {
+ get_region_storage<Region>().reset();
+ }
+ static void release()
+ {
+ get_region_storage<Region>().release();
+ }
+
+ //template <class T>
+ //allocator<T> make_allocator()
+ //{
+ // return allocator<T>(store);
+ //}
+
+ //// the number of bytes to allocate, and the alignment to use
+ //void *allocate(size_t num_bytes, size_t alignment)
+ //{
+ // return store.allocate(num_bytes, alignment);
+ //}
+
+ //size_t max_size() const
+ //{
+ // return store.max_size();
+ //}
+
+ //size_t used() const
+ //{
+ // return store.used();
+ //}
+
+ //size_t remaining() const
+ //{
+ // return store.remaining();
+ //}
                 };
 
         } // 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 22:47:40 EDT (Mon, 22 Jun 2009)
@@ -68,6 +68,7 @@
                 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()
                 {
@@ -86,9 +87,21 @@
                         return get_region_storage<Region>().release();
                 }
 
+ inline storage_base *set_storage(storage_base &store)
+ {
+ storage_base *old = current_storage;
+ current_storage = &store;
+ return old;
+ }
                 inline storage_base &get_storage()
                 {
- return get_region_storage<default_region_tag>();// ? *static_storage : default_static_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>());
                 }
 
                 inline void reset_storage()

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:47:40 EDT (Mon, 22 Jun 2009)
@@ -98,17 +98,18 @@
 
         if (types.Includes(Type::Monotonic))
         {
- //srand(42);
- //monotonic::local<monotonic::storage<100000> > 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();
+ srand(42);
+ struct local_tag {};
+ 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))
@@ -454,13 +455,12 @@
         return 0;
 }
 
-//namespace boost
-//{
-// namespace monotonic
-// {
-// static_storage_base<> default_static_storage;
-// storage_base *static_storage = &default_static_storage;
-// }
-//}
+namespace boost
+{
+ namespace monotonic
+ {
+ storage_base *current_storage = &get_region_storage<default_region_tag>();
+ }
+}
 
 //EOF


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