|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73193 - in sandbox/guild/pool: boost/pool libs/pool/test
From: john_at_[hidden]
Date: 2011-07-17 13:56:59
Author: johnmaddock
Date: 2011-07-17 13:56:58 EDT (Sun, 17 Jul 2011)
New Revision: 73193
URL: http://svn.boost.org/trac/boost/changeset/73193
Log:
Fix some more compiler warnings.
Add threading stress test.
Added:
sandbox/guild/pool/libs/pool/test/test_threading.cpp (contents, props changed)
Text files modified:
sandbox/guild/pool/boost/pool/pool.hpp | 43 +++++++++++++++++++++++----------------
sandbox/guild/pool/libs/pool/test/Jamfile.v2 | 3 ++
sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp | 7 ++++++
sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp | 7 ++++++
4 files changed, 42 insertions(+), 18 deletions(-)
Modified: sandbox/guild/pool/boost/pool/pool.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/pool.hpp (original)
+++ sandbox/guild/pool/boost/pool/pool.hpp 2011-07-17 13:56:58 EDT (Sun, 17 Jul 2011)
@@ -211,7 +211,7 @@
}
size_type element_size() const
{ //! \returns size of element pointer area.
- return (sz - sizeof(size_type) -
+ return static_cast<size_type>(sz - sizeof(size_type) -
math::static_lcm<sizeof(size_type), sizeof(void *)>::value);
}
@@ -284,9 +284,9 @@
typedef typename UserAllocator::difference_type difference_type; //!< A signed integral type that can represent the difference of any two pointers.
private:
- BOOST_STATIC_CONSTANT(unsigned, min_alloc_size =
+ BOOST_STATIC_CONSTANT(size_type, min_alloc_size =
(::boost::math::static_lcm<sizeof(void *), sizeof(size_type)>::value) );
- BOOST_STATIC_CONSTANT(unsigned, min_align =
+ BOOST_STATIC_CONSTANT(size_type, min_align =
(::boost::math::static_lcm< ::boost::alignment_of<void *>::value, ::boost::alignment_of<size_type>::value>::value) );
//! \returns 0 if out-of-memory.
@@ -346,8 +346,8 @@
// For alignment reasons, this used to be defined to be lcm(requested_size, sizeof(void *), sizeof(size_type)),
// but is now more parsimonious: just rounding up to the minimum required alignment of our housekeeping data
// when required. This works provided all alignments are powers of two.
- unsigned s = (std::max)(requested_size, static_cast<unsigned>(min_alloc_size));
- unsigned rem = s % min_align;
+ size_type s = (std::max)(requested_size, min_alloc_size);
+ size_type rem = s % min_align;
if(rem)
s += min_align - rem;
BOOST_ASSERT(s >= min_alloc_size);
@@ -517,6 +517,13 @@
}
};
+#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
+template <typename UserAllocator>
+typename pool<UserAllocator>::size_type const pool<UserAllocator>::min_alloc_size;
+template <typename UserAllocator>
+typename pool<UserAllocator>::size_type const pool<UserAllocator>::min_align;
+#endif
+
template <typename UserAllocator>
bool pool<UserAllocator>::release_memory()
{ //! pool must be ordered. Frees every memory block that doesn't have any allocated chunks.
@@ -681,8 +688,8 @@
//! Allocates chunk in newly malloc aftert resize.
//! \returns pointer to chunk.
size_type partition_size = alloc_size();
- size_type POD_size = next_size * partition_size +
- math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ size_type POD_size = static_cast<size_type>(next_size * partition_size +
+ math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type));
char * ptr = (UserAllocator::malloc)(POD_size);
if (ptr == 0)
{
@@ -690,8 +697,8 @@
{
next_size >>= 1;
partition_size = alloc_size();
- POD_size = next_size * partition_size +
- math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ POD_size = static_cast<size_type>(next_size * partition_size +
+ math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type));
ptr = (UserAllocator::malloc)(POD_size);
}
if(ptr == 0)
@@ -721,8 +728,8 @@
{ //! No memory in any of our storages; make a new storage,
//! \returns pointer to new chunk.
size_type partition_size = alloc_size();
- size_type POD_size = next_size * partition_size +
- math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ size_type POD_size = static_cast<size_type>(next_size * partition_size +
+ math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type));
char * ptr = (UserAllocator::malloc)(POD_size);
if (ptr == 0)
{
@@ -730,8 +737,8 @@
{
next_size >>= 1;
partition_size = alloc_size();
- POD_size = next_size * partition_size +
- math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ POD_size = static_cast<size_type>(next_size * partition_size +
+ math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type));
ptr = (UserAllocator::malloc)(POD_size);
}
if(ptr == 0)
@@ -806,8 +813,8 @@
// Not enough memory in our storages; make a new storage,
BOOST_USING_STD_MAX();
next_size = max BOOST_PREVENT_MACRO_SUBSTITUTION(next_size, num_chunks);
- size_type POD_size = next_size * partition_size +
- math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ size_type POD_size = static_cast<size_type>(next_size * partition_size +
+ math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type));
char * ptr = (UserAllocator::malloc)(POD_size);
if (ptr == 0)
{
@@ -817,8 +824,8 @@
// allocated last time:
next_size >>= 1;
next_size = max BOOST_PREVENT_MACRO_SUBSTITUTION(next_size, num_chunks);
- POD_size = next_size * partition_size +
- math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ POD_size = static_cast<size_type>(next_size * partition_size +
+ math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type));
ptr = (UserAllocator::malloc)(POD_size);
}
if(ptr == 0)
@@ -1001,7 +1008,7 @@
}
protected:
- unsigned chunk_size, max_alloc_size;
+ size_type chunk_size, max_alloc_size;
std::set<void*> free_list, used_list;
};
Modified: sandbox/guild/pool/libs/pool/test/Jamfile.v2
==============================================================================
--- sandbox/guild/pool/libs/pool/test/Jamfile.v2 (original)
+++ sandbox/guild/pool/libs/pool/test/Jamfile.v2 2011-07-17 13:56:58 EDT (Sun, 17 Jul 2011)
@@ -34,6 +34,7 @@
[ run test_bug_1252.cpp ]
[ run test_bug_2696.cpp ]
[ run test_bug_5526.cpp ]
+ [ run test_threading.cpp : : : <library>/boost/thread//boost_thread <toolset>gcc:<cxxflags>-Wno-attributes <toolset>gcc:<cxxflags>-Wno-missing-field-initializers ]
[ run ../example/time_pool_alloc.cpp ]
[ compile test_poisoned_macros.cpp ]
@@ -50,6 +51,7 @@
[ run test_bug_1252.cpp : : : [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_bug_1252_valgrind ]
[ run test_bug_2696.cpp : : : [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_bug_2696_valgrind ]
[ run test_bug_5526.cpp : : : [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_bug_5526_valgrind ]
+ [ run test_threading.cpp : : : <library>/boost/thread//boost_thread <toolset>gcc:<cxxflags>-Wno-attributes <toolset>gcc:<cxxflags>-Wno-missing-field-initializers [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_threading_valgrind ]
#
# The following tests test Boost.Pool's code with valgrind if it's available, and in any case with BOOST_POOL_VALGRIND defined
@@ -65,6 +67,7 @@
[ run test_bug_1252.cpp : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_bug_1252_valgrind_2 ]
[ run test_bug_2696.cpp : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_bug_2696_valgrind_2 ]
[ run test_bug_5526.cpp : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_bug_5526_valgrind_2 ]
+ [ run test_threading.cpp : : : <library>/boost/thread//boost_thread <define>BOOST_POOL_VALGRIND=1 <toolset>gcc:<cxxflags>-Wno-attributes <toolset>gcc:<cxxflags>-Wno-missing-field-initializers [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] : test_threading_valgrind_2 ]
[ run-fail test_valgrind_fail_1.cpp : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] ]
[ run-fail test_valgrind_fail_2.cpp : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no ] ]
;
Modified: sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp 2011-07-17 13:56:58 EDT (Sun, 17 Jul 2011)
@@ -10,9 +10,16 @@
#include <boost/cstdint.hpp>
#include <boost/limits.hpp>
#include <boost/math/common_factor.hpp>
+#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
+#pragma warning(push)
+#pragma warning(disable:4244)
+#endif
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
+#if defined(BOOST_MSVC) && (BOOST_MSVC == 1310)
+#pragma warning(pop)
+#endif
#include <boost/detail/lightweight_test.hpp>
Modified: sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp 2011-07-17 13:56:58 EDT (Sun, 17 Jul 2011)
@@ -11,9 +11,16 @@
#include <boost/pool/simple_segregated_storage.hpp>
#include <boost/assert.hpp>
#include <boost/math/common_factor_ct.hpp>
+#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
+#pragma warning(push)
+#pragma warning(disable:4244)
+#endif
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
+#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
+#pragma warning(pop)
+#endif
#include <boost/detail/lightweight_test.hpp>
Added: sandbox/guild/pool/libs/pool/test/test_threading.cpp
==============================================================================
--- (empty file)
+++ sandbox/guild/pool/libs/pool/test/test_threading.cpp 2011-07-17 13:56:58 EDT (Sun, 17 Jul 2011)
@@ -0,0 +1,71 @@
+/* Copyright (C) 2011 John Maddock
+*
+* Use, modification and distribution is subject to the
+* Boost Software License, Version 1.0. (See accompanying
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+#include <boost/pool/pool_alloc.hpp>
+#include <boost/thread.hpp>
+#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
+#pragma warning(push)
+#pragma warning(disable:4244)
+#endif
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
+#pragma warning(pop)
+#endif
+
+void run_tests()
+{
+ boost::random::mt19937 gen;
+ boost::random::uniform_int_distribution<> dist(-10, 10);
+ std::list<int, boost::fast_pool_allocator<int> > l;
+
+ for(int i = 0; i < 100; ++i)
+ l.push_back(i);
+
+ for(int i = 0; i < 100000; ++i)
+ {
+ int val = dist(gen);
+ if(val < 0)
+ {
+ while(val && l.size())
+ {
+ l.pop_back();
+ ++i;
+ }
+ }
+ else
+ {
+ while(val)
+ {
+ l.push_back(val);
+ --val;
+ }
+ }
+ }
+}
+
+int main()
+{
+ std::list<boost::shared_ptr<boost::thread> > threads;
+ for(int i = 0; i < 10; ++i)
+ {
+ try{
+ threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests)));
+ }
+ catch(const std::exception& e)
+ {
+ std::cerr << "<note>Thread creation failed with message: " << e.what() << "</note>" << std::endl;
+ }
+ }
+ std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end());
+ while(a != b)
+ {
+ (*a)->join();
+ ++a;
+ }
+ return 0;
+}
\ No newline at end of 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