]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Make pmr::synchronized_pool_resource work without libpthread (PR 94936)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 4 May 2020 12:34:23 +0000 (13:34 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 4 May 2020 12:37:31 +0000 (13:37 +0100)
commitec40967f1323069da3a5a45286f71fa4f80926df
tree6f9c1c6e4015570d63161c8aa85461487135bd5f
parentf9e1ea10e657af9fb02fafecf1a600740fd34409
libstdc++: Make pmr::synchronized_pool_resource work without libpthread (PR 94936)

I implicitly assumed that programs using pmr::synchronized_pool_resource
would also be using multiple threads, and so the weak symbols in
gthr-posix.h would be resolved by linking to libpthread. If that isn't
true then it crashes when trying to use pthread_key_create.

This commit makes the pool resource check __gthread_active_p() before
using thread-specific data, and just use a single set of memory pools
when there's only a single thread.

PR libstdc++/94936
* src/c++17/memory_resource.cc (synchronized_pool_resource::_TPools):
Add comment about single-threaded behaviour.
(synchronized_pool_resource::_TPools::move_nonempty_chunks()): Hoist
class member access out of loop.
(synchronized_pool_resource::synchronized_pool_resource())
(synchronized_pool_resource::~synchronized_pool_resource())
(synchronized_pool_resource::release()): Check __gthread_active_p
before creating and/or deleting the thread-specific data key.
(synchronized_pool_resource::_M_thread_specific_pools()): Adjust
assertions.
(synchronized_pool_resource::do_allocate(size_t, size_t)): Add fast
path for single-threaded case.
(synchronized_pool_resource::do_deallocate(void*, size_t, size_t)):
Likewise. Return if unable to find a pool that owns the allocation.
* testsuite/20_util/synchronized_pool_resource/allocate_single.cc:
New test.
* testsuite/20_util/synchronized_pool_resource/cons_single.cc: New
test.
* testsuite/20_util/synchronized_pool_resource/release_single.cc: New
test.
libstdc++-v3/ChangeLog
libstdc++-v3/src/c++17/memory_resource.cc
libstdc++-v3/testsuite/20_util/synchronized_pool_resource/allocate_single.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/synchronized_pool_resource/cons_single.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/synchronized_pool_resource/release_single.cc [new file with mode: 0644]
This page took 0.057047 seconds and 5 git commands to generate.