From 13a373d975a60d45b2dd6de4c3cc821296330e16 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Tue, 22 May 2007 09:50:45 +0000 Subject: Patch submitted to qpid-dev by ksmith@redhat.com. Fixes concurrency issues arising from previous move to use singleton apr pool. "My patch does three things: 1) Modifies the APRPool class to use alloc/free semantics for APR memory pools. Each time a caller calls APRPool::get() they'll their own pool reference. I've fixed up all the call sites I can find to also call APRPool::free() at the appropriate time. 2) Caches freed APR memory pools in a STL stack. This cuts down on the number of memory pools created overall. 3) As a result of doing #1 and #2 I've introduced a guard mutex around APRPool::get() and APRPool::free(). This is to prevent concurrent access to the memory pool cache. If it's too heavyweight, the mutex along with the caching mechanism could be removed entirely." git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@540511 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/lib/common/sys/apr/Socket.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cpp/lib/common/sys/apr/Socket.cpp') diff --git a/cpp/lib/common/sys/apr/Socket.cpp b/cpp/lib/common/sys/apr/Socket.cpp index 5a5dc2a615..ab98c07479 100644 --- a/cpp/lib/common/sys/apr/Socket.cpp +++ b/cpp/lib/common/sys/apr/Socket.cpp @@ -30,10 +30,12 @@ using namespace qpid::sys; Socket Socket::createTcp() { Socket s; + apr_pool_t* pool = APRPool::get(); CHECK_APR_SUCCESS( apr_socket_create( &s.socket, APR_INET, SOCK_STREAM, APR_PROTO_TCP, - APRPool::get())); + pool)); + APRPool::free(pool); return s; } @@ -47,11 +49,13 @@ void Socket::setTimeout(Time interval) { void Socket::connect(const std::string& host, int port) { apr_sockaddr_t* address; + apr_pool_t* pool = APRPool::get(); CHECK_APR_SUCCESS( apr_sockaddr_info_get( &address, host.c_str(), APR_UNSPEC, port, APR_IPV4_ADDR_OK, - APRPool::get())); + pool)); CHECK_APR_SUCCESS(apr_socket_connect(socket, address)); + APRPool::free(pool); } void Socket::close() { -- cgit v1.2.1