[PATCH] Implement std::pmr::synchronized_pool_resource

Jonathan Wakely jwakely@redhat.com
Sat Nov 17 23:35:00 GMT 2018


On 08/11/18 18:02 +0000, Jonathan Wakely wrote:
>Define the thread-safe pool resource, using a shared_mutex to allow
>multiple threads to concurrently allocate from thread-specific pools.
>
>Define new weak symbols for the pthread_rwlock_t functions, to avoid
>making libstdc++.so depend on libpthread.so
>
>	* config/abi/pre/gnu.ver: Add new symbols.
>	* include/std/memory_resource [_GLIBCXX_HAS_GTHREADS]
>	(synchronized_pool_resource): New class.
>	* include/std/shared_mutex (__glibcxx_rwlock_rdlock)
>	(__glibcxx_rwlock_tryrdlock, __glibcxx_rwlock_wrlock)
>	(__glibcxx_rwlock_trywrlock, __glibcxx_rwlock_unlock)
>	(__glibcxx_rwlock_destroy, __glibcxx_rwlock_init)
>	(__glibcxx_rwlock_timedrdlock, __glibcxx_rwlock_timedwrlock): Define
>	weak symbols for POSIX rwlock functions.
>	(__shared_mutex_pthread): Use weak symbols.
>	* src/c++17/memory_resource.cc [_GLIBCXX_HAS_GTHREADS]
>	(synchronized_pool_resource::_TPools): New class.
>	(destroy_TPools): New function for pthread_key_create destructor.
>	(synchronized_pool_resource::synchronized_pool_resource)
>	(synchronized_pool_resource::~synchronized_pool_resource)
>	(synchronized_pool_resource::release)
>	(synchronized_pool_resource::do_allocate)
>	(synchronized_pool_resource::do_deallocate): Define public members.
>	(synchronized_pool_resource::_M_thread_specific_pools)
>	(synchronized_pool_resource::_M_alloc_tpools)
>	(synchronized_pool_resource::_M_alloc_shared_tpools): Define private
>	members.
>
>The performance of this implementation is ... not great. But it's
>better than simply adding a mutex to unsynchronized_pool_resource and
>locking that around every allocation and deallocation.
>
>I am not committing this yet, because I still need to test on non-GNU
>targets, where the new weak wrappers around the pthread_rwlock_t
>functions might not work properly.

Here's the updated patch I'm committing, which includes more
conformance tests, and also performance tests.

Tested x86_64-linux, powerpc64le-linux, x86_64-freebsd11.0,
x86_64-w64-mingw32 and powerpc-aix7.2.0.0, committed to trunk.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 57572 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20181117/34728484/attachment.bin>


More information about the Libstdc++ mailing list