Added AIPerHostRequestQueue::queued_commands()

Returns the number of add commands minus the number of remove commands
in the command_queue for this host.
This commit is contained in:
Aleric Inglewood
2013-04-07 05:54:07 +02:00
parent d26241c0f2
commit c20e33c7f4
2 changed files with 13 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ class AIPerHostRequestQueue {
static threadsafe_instance_map_type sInstanceMap; // Map of AIPerHostRequestQueue instances with the hostname as key.
friend class AIThreadSafeSimpleDC<AIPerHostRequestQueue>; //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<AICurlPrivate::BufferedCurlEasyRequestPtr> 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; }

View File

@@ -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();