diff --git a/indra/llmessage/aicurlperhost.h b/indra/llmessage/aicurlperhost.h index 502fb3edb..457b2cccd 100644 --- a/indra/llmessage/aicurlperhost.h +++ b/indra/llmessage/aicurlperhost.h @@ -85,7 +85,7 @@ class AIPerHostRequestQueue { static threadsafe_instance_map_type sInstanceMap; // Map of AIPerHostRequestQueue instances with the hostname as key. friend class AIThreadSafeSimpleDC; //threadsafe_PerHostRequestQueue - AIPerHostRequestQueue(void) : mAdded(0) { } + AIPerHostRequestQueue(void) : mQueuedCommands(0), mAdded(0) { } public: typedef instance_map_type::iterator iterator; @@ -106,12 +106,15 @@ class AIPerHostRequestQueue { private: typedef std::deque queued_request_type; + int mQueuedCommands; // Number of add commands (minus remove commands) with this host in the command queue. int mAdded; // Number of active easy handles with this host. queued_request_type mQueuedRequests; // Waiting (throttled) requests. static LLAtomicS32 sTotalQueued; // The sum of mQueuedRequests.size() of all AIPerHostRequestQueue objects together. public: + void added_to_command_queue(void) { ++mQueuedCommands; } + void removed_from_command_queue(void) { --mQueuedCommands; llassert(mQueuedCommands >= 0); } void added_to_multi_handle(void); // Called when an easy handle for this host has been added to the multi handle. void removed_from_multi_handle(void); // Called when an easy handle for this host is removed again from the multi handle. bool throttled(void) const; // Returns true if the maximum number of allowed requests for this host have been added to the multi handle. @@ -123,6 +126,7 @@ class AIPerHostRequestQueue { // Add queued easy handle (if any) to the multi handle. The request is removed from the queue, // followed by either a call to added_to_multi_handle() or to queue() to add it back. + S32 queued_commands(void) const { return mQueuedCommands; } S32 host_queued_plus_added_size(void) const { return mQueuedRequests.size() + mAdded; } static S32 total_queued_size(void) { return sTotalQueued; } diff --git a/indra/llmessage/aicurlthread.cpp b/indra/llmessage/aicurlthread.cpp index 6ed1b19b7..62b76d8cb 100644 --- a/indra/llmessage/aicurlthread.cpp +++ b/indra/llmessage/aicurlthread.cpp @@ -1329,9 +1329,11 @@ void AICurlThread::process_commands(AICurlMultiHandle_wat const& multi_handle_w) case cmd_boost: // FIXME: future stuff break; case cmd_add: + PerHostRequestQueue_wat(*AICurlEasyRequest_wat(*command_being_processed_r->easy_request())->getPerHostPtr())->removed_from_command_queue(); multi_handle_w->add_easy_request(AICurlEasyRequest(command_being_processed_r->easy_request())); break; case cmd_remove: + PerHostRequestQueue_wat(*AICurlEasyRequest_wat(*command_being_processed_r->easy_request())->getPerHostPtr())->added_to_command_queue(); // Not really, but this has the same effect as 'removed a remove command'. multi_handle_w->remove_easy_request(AICurlEasyRequest(command_being_processed_r->easy_request()), true); break; } @@ -2386,7 +2388,9 @@ void AICurlEasyRequest::addRequest(void) // Add a command to add the new request to the multi session to the command queue. command_queue_w->commands.push_back(Command(*this, cmd_add)); command_queue_w->size++; - AICurlEasyRequest_wat(*get())->add_queued(); + AICurlEasyRequest_wat curl_easy_request_w(*get()); + PerHostRequestQueue_wat(*curl_easy_request_w->getPerHostPtr())->added_to_command_queue(); + curl_easy_request_w->add_queued(); } // Something was added to the queue, wake up the thread to get it. wakeUpCurlThread(); @@ -2448,8 +2452,10 @@ void AICurlEasyRequest::removeRequest(void) // Add a command to remove this request from the multi session to the command queue. command_queue_w->commands.push_back(Command(*this, cmd_remove)); command_queue_w->size--; + AICurlEasyRequest_wat curl_easy_request_w(*get()); + PerHostRequestQueue_wat(*curl_easy_request_w->getPerHostPtr())->removed_from_command_queue(); // Note really, but this has the same effect as 'added a remove command'. // Suppress warning that would otherwise happen if the callbacks are revoked before the curl thread removed the request. - AICurlEasyRequest_wat(*get())->remove_queued(); + curl_easy_request_w->remove_queued(); } // Something was added to the queue, wake up the thread to get it. wakeUpCurlThread();