Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54149 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-21 17:53:28


Author: cschladetsch
Date: 2009-06-21 17:53:26 EDT (Sun, 21 Jun 2009)
New Revision: 54149
URL: http://svn.boost.org/trac/boost/changeset/54149

Log:
added monotonic::local_allocator<T> for thread-local storage

Added:
   sandbox/monotonic/boost/monotonic/local_allocator.hpp (contents, props changed)
   sandbox/monotonic/boost/monotonic/thread_local_storage.hpp (contents, props changed)
Text files modified:
   sandbox/monotonic/boost/monotonic/forward_declarations.hpp | 12 ++++++++++++
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp | 10 ++++++----
   sandbox/monotonic/libs/monotonic/test/monotonic.sln | 1 -
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 16 ++++++++++++++++
   4 files changed, 34 insertions(+), 5 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-21 17:53:26 EDT (Sun, 21 Jun 2009)
@@ -42,6 +42,13 @@
                         , class Al = std::allocator<char> >
                 struct shared_storage;
 
+ /// thread-local storage
+ 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
                         , size_t MinHeapIncrement = DefaultSizes::StaticMinHeapIncrement
@@ -64,6 +71,11 @@
                 template <class>
                 struct shared_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>
+ struct local_allocator;
+
         } // namespace monotonic
 
 } // namespace boost

Added: sandbox/monotonic/boost/monotonic/local_allocator.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/local_allocator.hpp 2009-06-21 17:53:26 EDT (Sun, 21 Jun 2009)
@@ -0,0 +1,75 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_MONOTONIC_SHARED_ALLOCATOR_H
+#define BOOST_MONOTONIC_SHARED_ALLOCATOR_H
+
+#include <boost/monotonic/allocator_base.hpp>
+#include <boost/monotonic/thread_local_storage.hpp>
+
+namespace boost
+{
+ namespace monotonic
+ {
+ template <>
+ struct local_allocator<void>
+ {
+ typedef void* pointer;
+ typedef const void* const_pointer;
+
+ typedef void value_type;
+ template <class U>
+ struct rebind
+ {
+ typedef local_allocator<U> other;
+ };
+ };
+
+ template <class T>
+ struct local_allocator : allocator_base<T, local_allocator<T> >
+ {
+ typedef allocator_base<T, local_allocator<T> > Parent;
+ using typename Parent::size_type;
+ using typename Parent::difference_type;
+ using typename Parent::pointer;
+ using typename Parent::const_pointer;
+ using typename Parent::reference;
+ using typename Parent::const_reference;
+ using typename Parent::value_type;
+
+ template <class U>
+ struct rebind
+ {
+ typedef local_allocator<U> other;
+ };
+
+ local_allocator() throw()
+ : Parent(static_thread_local_storage) { }
+
+ local_allocator(const local_allocator& alloc) throw()
+ : Parent(alloc) { }
+
+ template <class U>
+ local_allocator(const local_allocator<U> &alloc) throw()
+ : Parent(alloc) { }
+
+ friend bool operator==(local_allocator<T> const &A, local_allocator<T> const &B)
+ {
+ return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
+ }
+
+ friend bool operator!=(local_allocator<T> const &A, local_allocator<T> const &B)
+ {
+ return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
+ }
+ };
+
+ } // namespace monotonic
+
+} // namespace boost
+
+#endif // BOOST_MONOTONIC_ALLOCATOR_H
+
+//EOF

Added: sandbox/monotonic/boost/monotonic/thread_local_storage.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/thread_local_storage.hpp 2009-06-21 17:53:26 EDT (Sun, 21 Jun 2009)
@@ -0,0 +1,75 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_MONOTONIC_THREAD_LOCAL_STORAGE_HPP
+#define BOOST_MONOTONIC_THREAD_LOCAL_STORAGE_HPP
+
+#include <boost/monotonic/storage.hpp>
+#include <boost/monotonic/static_storage.hpp>
+#include <boost/thread.hpp>
+
+namespace boost
+{
+ namespace monotonic
+ {
+ /// 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;
+
+ private:
+ Storage store;
+
+ public:
+ thread_local_storage()
+ {
+ }
+ size_t used() const
+ {
+ return store->used();
+ }
+ void reset()
+ {
+ store->reset();
+ }
+ void release()
+ {
+ store->release();
+ }
+ void *allocate(size_t num_bytes, size_t alignment)
+ {
+ return store->allocate(num_bytes, alignment);
+ }
+ size_t remaining() const
+ {
+ return store->remaining();
+ }
+ size_t fixed_remaining() const
+ {
+ return store->fixed_remaining();
+ }
+ size_t max_size() const
+ {
+ return 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
+
+#endif // BOOST_MONOTONIC_SHARED_STORAGE_H
+
+//EOF
+

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-21 17:53:26 EDT (Sun, 21 Jun 2009)
@@ -22,6 +22,8 @@
 #include <boost/timer.hpp>
 #include <boost/monotonic/local.hpp>
 
+#include <boost/monotonic/local_allocator.hpp>
+
 #include "./AllocatorTypes.h"
 
 using namespace std;
@@ -187,7 +189,7 @@
 };
 
 template <class Ty>
-struct test_sort_vector
+struct test_vector_sort
 {
         template <class Alloc>
         int test(Alloc, size_t count) const
@@ -360,7 +362,7 @@
         if (run_large)
         {
                 print(run_tests(10, 10000, 10, "list_create<int>", test_list_create<int>()));
- print(run_tests(20, 1000000, 10, "vector_sort<int>", test_sort_vector<int>()));
+ print(run_tests(20, 1000000, 10, "vector_sort<int>", test_vector_sort<int>()));
                 print(run_tests(5, 100000, 10, "list_sort<int>", test_list_sort<int>()));
 
 #ifndef WIN32
@@ -385,7 +387,7 @@
         {
                 print(run_tests(5000, 100, 10, "list_sort<int>", test_list_sort<int>()));
                 print(run_tests(5000, 100, 10, "list_create<int>", test_list_create<int>()));
- print(run_tests(200000, 100, 10, "sort_vector<int>", test_sort_vector<int>()));
+ print(run_tests(200000, 100, 10, "sort_vector<int>", test_vector_sort<int>()));
 
 #ifndef WIN32
                 print(run_tests(1000000, 100, 10, "dupe_vector", test_dupe_vector()));
@@ -409,7 +411,7 @@
         {
                 print(run_tests(1000, 1000, 10, "list_create<int>", test_list_create<int>()));
                 print(run_tests(5000, 1000, 10, "list_sort<int>", test_list_sort<int>()));
- print(run_tests(20000, 1000, 10, "sort_vector<int>", test_sort_vector<int>()));
+ print(run_tests(20000, 1000, 10, "sort_vector<int>", test_vector_sort<int>()));
 
 #ifndef WIN32
                 print(run_tests(1000000, 10000, 10, "dupe_vector", test_dupe_vector()));

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-21 17:53:26 EDT (Sun, 21 Jun 2009)
@@ -21,7 +21,6 @@
                 {470832FD-33D6-4F31-AD06-BB7838371077}.Debug|Win32.ActiveCfg = Debug|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.Debug|Win32.Build.0 = Debug|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.Release|Win32.ActiveCfg = Release|Win32
- {470832FD-33D6-4F31-AD06-BB7838371077}.Release|Win32.Build.0 = Release|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.ReleaseSym|Win32.ActiveCfg = ReleaseSym|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
         EndGlobalSection

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-21 17:53:26 EDT (Sun, 21 Jun 2009)
@@ -303,6 +303,10 @@
>
                                 </File>
                                 <File
+ RelativePath="..\..\..\boost\monotonic\local_allocator.hpp"
+ >
+ </File>
+ <File
                                         RelativePath="..\..\..\boost\monotonic\map.hpp"
>
                                 </File>
@@ -339,9 +343,21 @@
>
                                 </File>
                                 <File
+ RelativePath="..\..\..\boost\monotonic\thread_local_storage.hpp"
+ >
+ </File>
+ <File
                                         RelativePath="..\..\..\boost\monotonic\vector.hpp"
>
                                 </File>
+ <Filter
+ Name="extra"
+ >
+ </Filter>
+ <Filter
+ Name="detail"
+ >
+ </Filter>
                         </Filter>
                         <Filter
                                 Name="utility"


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