|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54229 - in branches/release: boost/flyweight boost/flyweight/detail libs/flyweight/doc libs/flyweight/doc/tutorial libs/flyweight/test
From: joaquin_at_[hidden]
Date: 2009-06-22 16:37:00
Author: joaquin
Date: 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
New Revision: 54229
URL: http://svn.boost.org/trac/boost/changeset/54229
Log:
merged up to [54228] from trunk
Removed:
branches/release/boost/flyweight/detail/handle_factory_adaptor.hpp
Binary files modified:
branches/release/libs/flyweight/doc/memory_gcc_344.png
branches/release/libs/flyweight/doc/memory_msvc_80.png
branches/release/libs/flyweight/doc/time_gcc_344.png
branches/release/libs/flyweight/doc/time_msvc_80.png
Text files modified:
branches/release/boost/flyweight/detail/flyweight_core.hpp | 48 ++++++++++++++++++---------------------
branches/release/boost/flyweight/flyweight.hpp | 4 +-
branches/release/boost/flyweight/intermodule_holder.hpp | 12 +++------
branches/release/boost/flyweight/refcounted.hpp | 47 ++++++++++++++-------------------------
branches/release/libs/flyweight/doc/acknowledgements.html | 4 +-
branches/release/libs/flyweight/doc/performance.html | 24 ++++++++++----------
branches/release/libs/flyweight/doc/release_notes.html | 11 ++++++++
branches/release/libs/flyweight/doc/tutorial/technical.html | 6 ++--
branches/release/libs/flyweight/test/heavy_objects.hpp | 23 +++++++++++++++++-
branches/release/libs/flyweight/test/test_basic_template.hpp | 17 +++++++++++++
10 files changed, 109 insertions(+), 87 deletions(-)
Modified: branches/release/boost/flyweight/detail/flyweight_core.hpp
==============================================================================
--- branches/release/boost/flyweight/detail/flyweight_core.hpp (original)
+++ branches/release/boost/flyweight/detail/flyweight_core.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -1,4 +1,4 @@
-/* Copyright 2006-2008 Joaquin M Lopez Munoz.
+/* Copyright 2006-2009 Joaquin M Lopez Munoz.
* 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)
@@ -16,7 +16,6 @@
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/detail/no_exceptions_support.hpp>
#include <boost/detail/workaround.hpp>
-#include <boost/flyweight/detail/handle_factory_adaptor.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
@@ -79,34 +78,31 @@
class flyweight_core
{
public:
- typedef typename ValuePolicy::key_type key_type;
- typedef typename ValuePolicy::value_type value_type;
- typedef typename ValuePolicy::rep_type rep_type;
+ typedef typename ValuePolicy::key_type key_type;
+ typedef typename ValuePolicy::value_type value_type;
+ typedef typename ValuePolicy::rep_type rep_type;
typedef typename mpl::apply2<
typename TrackingPolicy::entry_type,
rep_type,
key_type
- >::type entry_type;
+ >::type entry_type;
typedef typename mpl::apply2<
FactorySpecifier,
entry_type,
key_type
- >::type base_factory_type;
+ >::type factory_type;
+ typedef typename factory_type::handle_type base_handle_type;
typedef typename mpl::apply2<
typename TrackingPolicy::handle_type,
- typename base_factory_type::handle_type,
+ base_handle_type,
flyweight_core_tracking_helper<
ValuePolicy,Tag,TrackingPolicy,
FactorySpecifier,LockingPolicy,
HolderSpecifier
>
- >::type handle_type;
- typedef handle_factory_adaptor<
- base_factory_type,
- handle_type,entry_type
- > factory_type;
- typedef typename LockingPolicy::mutex_type mutex_type;
- typedef typename LockingPolicy::lock_type lock_type;
+ >::type handle_type;
+ typedef typename LockingPolicy::mutex_type mutex_type;
+ typedef typename LockingPolicy::lock_type lock_type;
static bool init()
{
@@ -132,7 +128,7 @@
static handle_type insert(const value_type& x){return insert_value(x);}
static handle_type insert(value_type& x){return insert_value(x);}
- static const entry_type& entry(const handle_type& h)
+ static const entry_type& entry(const base_handle_type& h)
{
return factory().entry(h);
}
@@ -158,7 +154,7 @@
}
private:
- struct holder_arg
+ struct holder_arg
{
factory_type factory;
mutex_type mutex;
@@ -166,14 +162,14 @@
typedef typename mpl::apply1<
HolderSpecifier,
holder_arg
- >::type holder_type;
+ >::type holder_type;
static handle_type insert_rep(const rep_type& x)
{
init();
- entry_type e(x);
- lock_type lock(mutex());
- handle_type h(factory().insert(e));
+ entry_type e(x);
+ lock_type lock(mutex());
+ base_handle_type h(factory().insert(e));
BOOST_TRY{
ValuePolicy::construct_value(
static_cast<const rep_type&>(entry(h)));
@@ -183,15 +179,15 @@
BOOST_RETHROW;
}
BOOST_CATCH_END
- return h;
+ return static_cast<handle_type>(h);
}
static handle_type insert_value(const value_type& x)
{
init();
- entry_type e=entry_type(rep_type(x));
- lock_type lock(mutex());
- handle_type h(factory().insert(e));
+ entry_type e((rep_type(x)));
+ lock_type lock(mutex());
+ base_handle_type h(factory().insert(e));
BOOST_TRY{
ValuePolicy::copy_value(
static_cast<const rep_type&>(entry(h)));
@@ -201,7 +197,7 @@
BOOST_RETHROW;
}
BOOST_CATCH_END
- return h;
+ return static_cast<handle_type>(h);
}
static bool static_initializer;
Deleted: branches/release/boost/flyweight/detail/handle_factory_adaptor.hpp
==============================================================================
--- branches/release/boost/flyweight/detail/handle_factory_adaptor.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
+++ (empty file)
@@ -1,48 +0,0 @@
-/* Copyright 2006-2008 Joaquin M Lopez Munoz.
- * 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)
- *
- * See http://www.boost.org/libs/flyweight for library home page.
- */
-
-#ifndef BOOST_FLYWEIGHT_DETAIL_HANDLE_FACTORY_ADAPTOR_HPP
-#define BOOST_FLYWEIGHT_DETAIL_HANDLE_FACTORY_ADAPTOR_HPP
-
-#if defined(_MSC_VER)&&(_MSC_VER>=1200)
-#pragma once
-#endif
-
-/* Given a Factory and a Handle type constructible from and implicitly
- * convertible to Factory::handle_type, handle_factory_adaptor
- * adapts Factory to present Handle as the associated handle_type.
- */
-
-namespace boost{
-
-namespace flyweights{
-
-namespace detail{
-
-template<typename Factory,typename Handle,typename Entry>
-struct handle_factory_adaptor:Factory
-{
-public:
- typedef Handle handle_type;
-
- handle_type insert(const Entry& x)
- {
- return static_cast<handle_type>(base().insert(x));
- }
-
-private:
- Factory& base(){return *this;}
-};
-
-} /* namespace flyweights::detail */
-
-} /* namespace flyweights */
-
-} /* namespace boost */
-
-#endif
Modified: branches/release/boost/flyweight/flyweight.hpp
==============================================================================
--- branches/release/boost/flyweight/flyweight.hpp (original)
+++ branches/release/boost/flyweight/flyweight.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -1,6 +1,6 @@
/* Flyweight class.
*
- * Copyright 2006-2008 Joaquin M Lopez Munoz.
+ * Copyright 2006-2009 Joaquin M Lopez Munoz.
* 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)
@@ -193,7 +193,7 @@
:h(core::insert(BOOST_PP_ENUM_PARAMS(n,t))){}
#include <boost/flyweight/detail/perfect_fwd.hpp>
- flyweight& operator=(const flyweight x){h=x.h;return *this;}
+ flyweight& operator=(const flyweight& x){h=x.h;return *this;}
flyweight& operator=(const value_type& x){return operator=(flyweight(x));}
/* convertibility to underlying type */
Modified: branches/release/boost/flyweight/intermodule_holder.hpp
==============================================================================
--- branches/release/boost/flyweight/intermodule_holder.hpp (original)
+++ branches/release/boost/flyweight/intermodule_holder.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -119,12 +119,10 @@
std::sprintf(
mutex_name,
"boost_flyweight_intermodule_holder_mutex_"
- "%ld_%u_%u_%u_%u",
+ "%ld_%u_%u",
(long)detail::process_id(),
(unsigned)compute_hash(typeid(C).name(),0),
- (unsigned)compute_hash(typeid(C).name(),1),
- (unsigned)compute_hash(typeid(C).name(),2),
- (unsigned)compute_hash(typeid(C).name(),3));
+ (unsigned)compute_hash(typeid(C).name(),1));
return mutex_name;
}
@@ -134,12 +132,10 @@
std::sprintf(
segment_name,
"boost_flyweight_intermodule_holder_segment_"
- "%ld_%u_%u_%u_%u",
+ "%ld_%u_%u",
(long)detail::process_id(),
(unsigned)compute_hash(typeid(C).name(),0),
- (unsigned)compute_hash(typeid(C).name(),1),
- (unsigned)compute_hash(typeid(C).name(),2),
- (unsigned)compute_hash(typeid(C).name(),3));
+ (unsigned)compute_hash(typeid(C).name(),1));
return segment_name;
}
Modified: branches/release/boost/flyweight/refcounted.hpp
==============================================================================
--- branches/release/boost/flyweight/refcounted.hpp (original)
+++ branches/release/boost/flyweight/refcounted.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -23,22 +23,20 @@
#include <boost/utility/swap.hpp>
/* Refcounting tracking policy.
- * The implementation deserves some explanation; values are equipped with a
- * reference count with the following semantics:
- * - 0: newly created value.
- * - n: (n-1) active references to the value.
- * When the number of references reaches zero, the value can be erased. The
- * exact protocol, however, is a little more complicated to avoid data races
- * like the following:
+ * The implementation deserves some explanation; values are equipped with two
+ * reference counts:
+ * - a regular count of active references
+ * - a deleter count
+ * It looks like a value can be erased when the number of references reaches
+ * zero, but this condition alone can lead to data races:
* - Thread A detaches the last reference to x and is preempted.
* - Thread B looks for x, finds it and attaches a reference to it.
* - Thread A resumes and proceeds with erasing x, leaving a dangling
* reference in thread B.
- * To cope with this, values are equipped with an additional count of threads
- * preempted during erasure. Such a preemption are detected by the preempting
- * thread by checking whether the reference count of the object is 1 (hence
- * the uncommon refcounting semantics distinguishing between a newly created
- * value and a value with no active references.
+ * Here is where the deleter count comes into play. This count is
+ * incremented when the reference count changes from 0 to 1, and decremented
+ * when a thread is about to check a value for erasure; it can be seen that a
+ * value is effectively erasable only when the deleter count goes down to 0.
*/
namespace boost{
@@ -61,13 +59,13 @@
~refcounted_value()
{
- /* count()>1 most likely indicates that the flyweight factory
+ /* count()!=0 most likely indicates that the flyweight factory
* has been destructed before some of the flyweight objects using
* it. Check for static initialization order problems with this
* flyweight type.
*/
- BOOST_ASSERT(count()<=1);
+ BOOST_ASSERT(count()==0);
}
refcounted_value& operator=(const refcounted_value& r)
@@ -86,11 +84,10 @@
long count()const{return ref;}
long add_ref()const{return ++ref;}
- bool release()const{return (--ref==1);}
+ bool release()const{return (--ref==0);}
- long count_deleters()const{return del_ref;}
void add_deleter()const{++del_ref;}
- void release_deleter()const{--del_ref;}
+ bool release_deleter()const{return (--del_ref==0);}
private:
Value x;
@@ -104,14 +101,8 @@
public:
explicit refcounted_handle(const Handle& h_):h(h_)
{
- switch(TrackingHelper::entry(*this).add_ref()){
- case 1: /* newly created object, make count()==2 (1 active reference) */
- TrackingHelper::entry(*this).add_ref();
- break;
- case 2: /* object was about to be erased, increment the deleter count */
- TrackingHelper::entry(*this).add_deleter();
- break;
- default:break;
+ if(TrackingHelper::entry(*this).add_ref()==1){
+ TrackingHelper::entry(*this).add_deleter();
}
}
@@ -143,11 +134,7 @@
private:
static bool check_erase(const refcounted_handle& x)
{
- if(TrackingHelper::entry(x).count_deleters()){
- TrackingHelper::entry(x).release_deleter();
- return false;
- }
- return true;
+ return TrackingHelper::entry(x).release_deleter();
}
Handle h;
Modified: branches/release/libs/flyweight/doc/acknowledgements.html
==============================================================================
--- branches/release/libs/flyweight/doc/acknowledgements.html (original)
+++ branches/release/libs/flyweight/doc/acknowledgements.html 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -66,7 +66,7 @@
<p>
Many thanks to Tim Blechmann for helping identify and solve a serious
-tread safety problem
+thread safety problem
and to Peter Dimov for kindly extending the interface of his
<code>boost::detail::atomic_count</code> utility to allow for the
implementation of the fix.
@@ -85,7 +85,7 @@
<br>
-<p>Revised April 18th 2009</p>
+<p>Revised April 25th 2009</p>
<p>© Copyright 2006-2009 Joaquín M López Muñoz.
Distributed under the Boost Software
Modified: branches/release/libs/flyweight/doc/memory_gcc_344.png
==============================================================================
Binary files. No diff available.
Modified: branches/release/libs/flyweight/doc/memory_msvc_80.png
==============================================================================
Binary files. No diff available.
Modified: branches/release/libs/flyweight/doc/performance.html
==============================================================================
--- branches/release/libs/flyweight/doc/performance.html (original)
+++ branches/release/libs/flyweight/doc/performance.html 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -171,7 +171,7 @@
<tr>
<td align="center" rowspan="2"> tracking mechanism </td>
<td align="center"> refcounted
</td>
- <td align="center"> 1<sup>(3)</sup> </td>
+ <td align="center"> 2<sup>(3)</sup> </td>
</tr>
<tr>
<td align="center"> no_tracking
</td>
@@ -180,13 +180,13 @@
</table>
<sup>(1)</sup> <small>Assuming that <code>sizeof(Key)<=sizeof(Value)</code>.</small><br>
<sup>(2)</sup> <small>For some implementations of <code>std::set</code> this overhead reduces to 3.</small><br>
-<sup>(3)</sup> <small>In some platforms this value can be 2.</small>
+<sup>(3)</sup> <small>In some platforms this value can be 3.</small>
</p>
<p>
For instance, for the default configuration parameters of <code>flyweight</code>,
-<i>overhead</i> is typically 2.5(<code>hashed_factory</code>) + 1(<code>refcounted</code>)
-= 3 words.
+<i>overhead</i> is typically 2.5(<code>hashed_factory</code>) + 2(<code>refcounted</code>)
+= 4.5 words.
</p>
<h3><a name="overall_memory">Overall memory consumption</a></h3>
@@ -339,7 +339,7 @@
<p align="center">
<img src="memory_msvc_80.png" alt="memory consumption (MB), MSVC++ 8.0"
-width="798" height="322"><br>
+width="798" height="323"><br>
<b>Fig. 2: Memory consumption, MSVC++ 8.0. Values in MB.</b>
</p>
@@ -362,7 +362,7 @@
<p align="center">
<img src="time_msvc_80.png" alt="execution time (s), MSVC++ 8.0"
-width="820" height="324"><br>
+width="820" height="325"><br>
<b>Fig. 3: Execution time, MSVC++ 8.0. Values in seconds.</b>
</p>
@@ -370,10 +370,10 @@
The figure displays execution times for the profiled scenarios in different
usage contexts. In accordance with our previous
<a href="#time">qualitative analysis</a>, initialization of <code>flyweight</code>s
-carries an important overhead with respect to the base case scenario (between 10% and 40%
+carries an important overhead with respect to the base case scenario (between 20% and 40%
of additional execution time), while the other usage contexts
(assignment, equality comparison and value access) have performance gains,
-with speedup factors of up to 14 in some cases. The use of a
+with speedup factors of more than 10 in some cases. The use of a
<a href="tutorial/configuration.html#refcounted"><code>refcounted</code></a>
tracking policy introduces penalties with respect to
<a href="tutorial/configuration.html#no_tracking"><code>no_tracking</code></a>
@@ -393,7 +393,7 @@
<p align="center">
<img src="memory_gcc_344.png" alt="memory consumption (MB), GCC 3.4.4"
-width="798" height="322"><br>
+width="798" height="323"><br>
<b>Fig. 4: Memory consumption, GCC 3.4.4. Values in MB.</b>
</p>
@@ -411,7 +411,7 @@
<p align="center">
<img src="time_gcc_344.png" alt="execution time (s), GCC 3.4.4"
-width="820" height="324"><br>
+width="820" height="325"><br>
<b>Fig. 5: Execution time, GCC 3.4.4. Values in seconds.</b>
</p>
@@ -459,9 +459,9 @@
<br>
-<p>Revised December 2nd 2008</p>
+<p>Revised June 22nd 2009</p>
-<p>© Copyright 2006-2008 Joaquín M López Muñoz.
+<p>© Copyright 2006-2009 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
Modified: branches/release/libs/flyweight/doc/release_notes.html
==============================================================================
--- branches/release/libs/flyweight/doc/release_notes.html (original)
+++ branches/release/libs/flyweight/doc/release_notes.html 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -31,10 +31,19 @@
<h2>Contents</h2>
<ul>
+ <li>Boost 1.40 release</li>
<li>Boost 1.39 release</li>
<li>Boost 1.38 release</li>
</ul>
+<h2><a name="boost_1_40">Boost 1.40 release</a></h2>
+
+<p>
+<ul>
+ <li>Maintenance fixes.</li>
+</ul>
+</p>
+
<h2><a name="boost_1_39">Boost 1.39 release</a></h2>
<p>
@@ -69,7 +78,7 @@
<br>
-<p>Revised April 7th 2009</p>
+<p>Revised April 25th 2009</p>
<p>© Copyright 2006-2009 Joaquín M López Muñoz.
Distributed under the Boost Software
Modified: branches/release/libs/flyweight/doc/time_gcc_344.png
==============================================================================
Binary files. No diff available.
Modified: branches/release/libs/flyweight/doc/time_msvc_80.png
==============================================================================
Binary files. No diff available.
Modified: branches/release/libs/flyweight/doc/tutorial/technical.html
==============================================================================
--- branches/release/libs/flyweight/doc/tutorial/technical.html (original)
+++ branches/release/libs/flyweight/doc/tutorial/technical.html 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -135,7 +135,7 @@
</p>
<blockquote><pre>
-Assertion failed: count()==0, file c:\boost\flyweight\refcounted.hpp, line 55
+Assertion failed: count()==0, file c:\boost\flyweight\refcounted.hpp, line 68
</pre></blockquote>
<p>
@@ -180,9 +180,9 @@
<br>
-<p>Revised August 11th 2008</p>
+<p>Revised June 22nd 2009</p>
-<p>© Copyright 2006-2008 Joaquín M López Muñoz.
+<p>© Copyright 2006-2009 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
Modified: branches/release/libs/flyweight/test/heavy_objects.hpp
==============================================================================
--- branches/release/libs/flyweight/test/heavy_objects.hpp (original)
+++ branches/release/libs/flyweight/test/heavy_objects.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -1,6 +1,6 @@
-/* Boost.Flyweight basic test template.
+/* Classes for Boost.Flyweight key-value tests.
*
- * Copyright 2006-2008 Joaquin M Lopez Munoz.
+ * Copyright 2006-2009 Joaquin M Lopez Munoz.
* 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)
@@ -15,6 +15,7 @@
#pragma once
#endif
+#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/noncopyable.hpp>
#include <iosfwd>
#include <string>
@@ -84,4 +85,22 @@
int n;
};
+#if !defined(BOOST_NO_EXCEPTIONS)
+struct throwing_value_exception{};
+
+struct throwing_value
+{
+ throwing_value():n(0){}
+ throwing_value(const throwing_value&){throw throwing_value_exception();}
+ throwing_value(int){throw throwing_value_exception();}
+
+ int n;
+};
+
+struct from_throwing_value_to_int
+{
+ const int& operator()(const throwing_value& x)const{return x.n;}
+};
+#endif
+
#endif
Modified: branches/release/libs/flyweight/test/test_basic_template.hpp
==============================================================================
--- branches/release/libs/flyweight/test/test_basic_template.hpp (original)
+++ branches/release/libs/flyweight/test/test_basic_template.hpp 2009-06-22 16:36:58 EDT (Mon, 22 Jun 2009)
@@ -1,6 +1,6 @@
/* Boost.Flyweight basic test template.
*
- * Copyright 2006-2008 Joaquin M Lopez Munoz.
+ * Copyright 2006-2009 Joaquin M Lopez Munoz.
* 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)
@@ -225,6 +225,21 @@
test_basic_comparison_template<texture_flyweight,texture_flyweight>(
&textures[0],&textures[0]+LENGTHOF(textures)-1,&textures[1]);
+
+#if !defined(BOOST_NO_EXCEPTIONS)
+ typedef typename boost::mpl::apply1<
+ FlyweightSpecifier,
+ boost::flyweights::key_value<int,throwing_value,from_throwing_value_to_int>
+ >::type throwing_flyweight;
+
+ try{
+ throwing_flyweight fw(0);
+ }catch(const throwing_value_exception&){}
+ try{
+ throwing_flyweight fw=throwing_flyweight(throwing_value());
+ }catch(const throwing_value_exception&){}
+#endif
+
}
#undef LENGTHOF
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