Add PerHostRequestQueue::sTotalQueued
The new variable is updated to contain the sum of the size of PerHostRequestQueue::mQueuedRequests of every PerHostRequestQueue object, and thus the total number of queued requests for all hosts together. Also added PerHostRequestQueue::host_queued_plus_added_size() which returns the the sum of queued requests plus the requests already added to the multi handle for this particular hostname.
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
namespace AICurlPrivate {
|
||||
|
||||
PerHostRequestQueue::threadsafe_instance_map_type PerHostRequestQueue::sInstanceMap;
|
||||
LLAtomicS32 PerHostRequestQueue::sTotalQueued;
|
||||
U32 curl_concurrent_connections_per_host;
|
||||
|
||||
//static
|
||||
@@ -72,7 +73,7 @@ void PerHostRequestQueue::release(PerHostRequestQueuePtr& instance)
|
||||
return;
|
||||
}
|
||||
// The reference in the map is the last one; that means there can't be any curl easy requests queued for this host.
|
||||
llassert(PerHostRequestQueue_wat(*instance)->mQueuedRequests.empty());
|
||||
llassert(PerHostRequestQueue_rat(*instance)->mQueuedRequests.empty());
|
||||
// Find the host and erase it from the map.
|
||||
iterator const end = instance_map_w->end();
|
||||
for(iterator iter = instance_map_w->begin(); iter != end; ++iter)
|
||||
@@ -111,6 +112,7 @@ void PerHostRequestQueue::removed_from_multi_handle(void)
|
||||
void PerHostRequestQueue::queue(AICurlEasyRequest const& easy_request)
|
||||
{
|
||||
mQueuedRequests.push_back(easy_request.get_ptr());
|
||||
sTotalQueued++;
|
||||
}
|
||||
|
||||
bool PerHostRequestQueue::cancel(AICurlEasyRequest const& easy_request)
|
||||
@@ -134,6 +136,8 @@ bool PerHostRequestQueue::cancel(AICurlEasyRequest const& easy_request)
|
||||
prev = cur;
|
||||
}
|
||||
mQueuedRequests.pop_back(); // if this is safe.
|
||||
--sTotalQueued;
|
||||
llassert(sTotalQueued >= 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -143,6 +147,8 @@ void PerHostRequestQueue::add_queued_to(curlthread::MultiHandle* multi_handle)
|
||||
{
|
||||
multi_handle->add_easy_request(mQueuedRequests.front());
|
||||
mQueuedRequests.pop_front();
|
||||
--sTotalQueued;
|
||||
llassert(sTotalQueued >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +159,11 @@ void PerHostRequestQueue::purge(void)
|
||||
for (iterator host = instance_map_w->begin(); host != instance_map_w->end(); ++host)
|
||||
{
|
||||
Dout(dc::curl, "Purging queue of host \"" << host->first << "\".");
|
||||
PerHostRequestQueue_wat(*host->second)->mQueuedRequests.clear();
|
||||
PerHostRequestQueue_wat per_host_w(*host->second);
|
||||
size_t s = per_host_w->mQueuedRequests.size();
|
||||
per_host_w->mQueuedRequests.clear();
|
||||
sTotalQueued -= s;
|
||||
llassert(sTotalQueued >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,8 @@ class PerHostRequestQueue {
|
||||
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 PerHostRequestQueue objects together.
|
||||
|
||||
public:
|
||||
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.
|
||||
@@ -110,6 +112,10 @@ class PerHostRequestQueue {
|
||||
|
||||
void add_queued_to(curlthread::MultiHandle* mh); // 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 host_queued_plus_added_size(void) const { return mQueuedRequests.size() + mAdded; }
|
||||
static S32 total_queued_size(void) { return sTotalQueued; }
|
||||
|
||||
private:
|
||||
// Disallow copying.
|
||||
PerHostRequestQueue(PerHostRequestQueue const&) { }
|
||||
|
||||
Reference in New Issue
Block a user