This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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] __shared_ptr<T,_S_single> should never use atomic ops


This is something I've been meaning to change for years, see
http://gcc.gnu.org/ml/libstdc++/2007-10/msg00180.html for a prior
post. Currently __shared_ptr<T, _S_single> specializations still
dispatch through __gnu_cxx::__exchange_and_add_dispatch for ref-count
updates.  The attached patch means the _S_single policy is always
non-atomic, so that you can get a faster (but not threadsafe!) smart
pointer with:

template<typename T>
  using shared_ptr_unsynchronized
     = std::__shared_ptr<T, std::_S_single>;

This is something I've needed and I've seen others ask about it too e.g.
http://stackoverflow.com/q/15129263/981959
http://stackoverflow.com/q/9792668/981959

2013-11-18  Jonathan Wakely  <jwakely.gcc@gmail.com>

        * include/bits/shared_ptr_base.h (_Sp_counted_base<_S_single>): Use
        non-atomic operations.
        * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust line number.
        * testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.

Tested x86_64-linux, with --enable-threads and --disable-threads,
committed to trunk.

Attachment: patch.txt
Description: Text document


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