From 155cc56632d402c3970e4662ebb792d699f24495 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Mon, 12 Nov 2012 18:42:55 +0100 Subject: [PATCH] Do not put AICurlEasyRequest in a container. --- indra/llmessage/aicurlperhost.cpp | 21 ++++++++++----------- indra/llmessage/aicurlperhost.h | 6 +++++- indra/llmessage/aicurlprivate.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/indra/llmessage/aicurlperhost.cpp b/indra/llmessage/aicurlperhost.cpp index d2494283b..724d5bccd 100644 --- a/indra/llmessage/aicurlperhost.cpp +++ b/indra/llmessage/aicurlperhost.cpp @@ -105,25 +105,24 @@ void PerHostRequestQueue::removed_from_multi_handle(void) void PerHostRequestQueue::queue(AICurlEasyRequest const& easy_request) { - mQueuedRequests.push_back(easy_request); + mQueuedRequests.push_back(easy_request.get_ptr()); } bool PerHostRequestQueue::cancel(AICurlEasyRequest const& easy_request) { - std::deque::iterator const end = mQueuedRequests.end(); - std::deque::iterator cur = std::find(mQueuedRequests.begin(), end, easy_request); + queued_request_type::iterator const end = mQueuedRequests.end(); + queued_request_type::iterator cur = std::find(mQueuedRequests.begin(), end, easy_request.get_ptr()); if (cur == end) return false; // Not found. - // We can't use erase because that uses assignment to move elements, which is - // private because it isn't thread-safe for AICurlEasyRequest. Therefore, move - // the element that we found to the back with swap (could just swap with the - // end immediately, but I don't want to break the order in which requests where - // added). Swap is also not thread-safe, but OK here because it only touches the - // AICurlEasyRequest objects in the deque, and the deque is protected by the - // lock on the PerHostRequestQueue object. - std::deque::iterator prev = cur; + // We can't use erase because that uses assignment to move elements, + // because it isn't thread-safe. Therefore, move the element that we found to + // the back with swap (could just swap with the end immediately, but I don't + // want to break the order in which requests where added). Swap is also not + // thread-safe, but OK here because it only touches the objects in the deque, + // and the deque is protected by the lock on the PerHostRequestQueue object. + queued_request_type::iterator prev = cur; while (++cur != end) { prev->swap(*cur); // This is safe, diff --git a/indra/llmessage/aicurlperhost.h b/indra/llmessage/aicurlperhost.h index 196f46ea9..dac9d70c0 100644 --- a/indra/llmessage/aicurlperhost.h +++ b/indra/llmessage/aicurlperhost.h @@ -45,6 +45,10 @@ namespace curlthread { class MultiHandle; } class PerHostRequestQueue; class RefCountedThreadSafePerHostRequestQueue; +class ThreadSafeBufferedCurlEasyRequest; + +// Forward declaration of BufferedCurlEasyRequestPtr (see aicurlprivate.h). +typedef boost::intrusive_ptr BufferedCurlEasyRequestPtr; // PerHostRequestQueue objects are created by the curl thread and destructed by the main thread. // We need locking. @@ -91,7 +95,7 @@ class PerHostRequestQueue { static void purge(void); private: - typedef std::deque queued_request_type; + typedef std::deque queued_request_type; int mAdded; // Number of active easy handles with this host. queued_request_type mQueuedRequests; // Waiting (throttled) requests. diff --git a/indra/llmessage/aicurlprivate.h b/indra/llmessage/aicurlprivate.h index d6bc5ee9c..3ecdae2b0 100644 --- a/indra/llmessage/aicurlprivate.h +++ b/indra/llmessage/aicurlprivate.h @@ -521,7 +521,7 @@ class ThreadSafeBufferedCurlEasyRequest : public AIThreadSafeSimple BufferedCurlEasyRequestPtr; +typedef boost::intrusive_ptr BufferedCurlEasyRequestPtr; // This class wraps CURLM*'s. // It guarantees that a pointer is cleaned up when no longer needed, as required by libcurl.