This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3 patch] Add std::tr1::shared_ptr


This adds <tr1/memory> which covers section 2.2 of TR1 - smart pointers.

The code was taken from Boost with permission of the authors. The
<tr1/memory> header contains code from several Boost headers in one
file, which currently has the copyright statements from all those files.
Someone should check I've done everything I need to in order to add this
code to GCC and that the copyrights are OK.

There are no tests for weak_ptr and incomplete tests for shared_ptr,
I'll add them eventually but don't have enough time to do it right now.

I have modified the relevant Boost tests to use the std::tr1::shared_ptr
instead of boost::shared_ptr and run them successfully, but only on a
single processor machine.  The threaded tests should be run on as many
exotic multiprocessor machines as possible, as one of the major changes
I made to the classes was to use GCC's atomic ops instead of the
Boost.Threads library.  I can't commit those tests but I'll make them
available to those who want them.

For the shared_ptr_timing_test my modified versions did better without
optimisation, but worse when optimisation was enabled.  I plan to
investigate that at some point.  It might be because the Boost.Threads
locks can be inlined whereas GCC's atomic ops will make a function call.
For the MT test my version was faster both with and without optimisation
(as expected, since my version uses atomic ops instead of locking.)

Timings for those tests on my uniprocessor x86_64 GNU/Linux box were:

Test name                  Version      -O0     -O1

shared_ptr_timing_test     Boost        2.47    0.62
shared_ptr_timing_test     GCC          2.02    0.92
shared_ptr_mt_test         Boost        6.500   3.450
shared_ptr_mt_test         GCC          4.780   2.270

As well as the names defined by TR1 this patch adds these non-uglified
names to the std::tr1 namespace:
checked_delete, checked_deleter, weak_count, shared_count,
shared_ptr_traits
This is worse name pollution than the boost versions, which put some of
these names in the boost::detail namespace.  The uglification and/or
namespace use should be made more consistent.

The major changes I made to the Boost code were

* Replacing Boost.Threads locks with GCC's atomic ops.
* Removing workarounds for older compilers such as public functions that
  can be private since member template friends and ADL work with GCC
  (so injected-names of friends functions will be found by ADL)

I expect there will be plenty of changes to come but this should
probably be committed now and improved later. OK for mainline?

2005-02-21  Jonathan Wakely

	* include/tr1/memory: New file.
	* include/Makefile.am, include/Makefile.in: Add new TR1 header.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/not_shared.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/shared.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/still_shared.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/assign.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/auto_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/auto_ptr_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/auto_ptr_rvalue_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/shared_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/shared_ptr_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/comparison/cmp.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/auto_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/auto_ptr_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/copy.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/default.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/pointer.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/weak_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/weak_ptr_expired.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/dest/dest.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/misc/io.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/misc/swap.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/reset.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/reset_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/swap.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/swap_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/bool_conv.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/get.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/unique.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/use_count.cc: New test.

jon


Attachment: shared_ptr.2.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]