diff --git a/indra/llmessage/aicurl.cpp b/indra/llmessage/aicurl.cpp index 93153951a..06c7f0ab4 100644 --- a/indra/llmessage/aicurl.cpp +++ b/indra/llmessage/aicurl.cpp @@ -961,7 +961,7 @@ CurlEasyRequest::~CurlEasyRequest() revokeCallbacks(); if (mPerServicePtr) { - AIPerServiceRequestQueue::release(mPerServicePtr); + AIPerService::release(mPerServicePtr); } // This wasn't freed yet if the request never finished. curl_slist_free_all(mHeaders); @@ -1114,7 +1114,7 @@ void CurlEasyRequest::finalizeRequest(std::string const& url, AIHTTPTimeoutPolic setopt(CURLOPT_HTTPHEADER, mHeaders); setoptString(CURLOPT_URL, url); llassert(!mPerServicePtr); - mLowercaseServicename = AIPerServiceRequestQueue::extract_canonical_servicename(url); + mLowercaseServicename = AIPerService::extract_canonical_servicename(url); mTimeoutPolicy = &policy; state_machine->setTotalDelayTimeout(policy.getTotalDelay()); // The following line is a bit tricky: we store a pointer to the object without increasing its reference count. @@ -1236,14 +1236,14 @@ void CurlEasyRequest::queued_for_removal(AICurlEasyRequest_wat& curl_easy_reques } #endif -AIPerServiceRequestQueuePtr CurlEasyRequest::getPerServicePtr(void) +AIPerServicePtr CurlEasyRequest::getPerServicePtr(void) { if (!mPerServicePtr) { // mPerServicePtr is really just a speed-up cache. // The reason we can cache it is because mLowercaseServicename is only set // in finalizeRequest which may only be called once: it never changes. - mPerServicePtr = AIPerServiceRequestQueue::instance(mLowercaseServicename); + mPerServicePtr = AIPerService::instance(mLowercaseServicename); } return mPerServicePtr; } diff --git a/indra/llmessage/aicurl.h b/indra/llmessage/aicurl.h index 48fb38ac0..d15c72cd8 100644 --- a/indra/llmessage/aicurl.h +++ b/indra/llmessage/aicurl.h @@ -52,7 +52,7 @@ #include "stdtypes.h" // U16, S32, U32, F64 #include "llatomic.h" // LLAtomicU32 #include "aithreadsafe.h" -#include "aicurlperservice.h" // AIPerServiceRequestQueuePtr +#include "aicurlperservice.h" // AIPerServicePtr // Debug Settings. extern bool gNoVerifySSLCert; diff --git a/indra/llmessage/aicurlperservice.cpp b/indra/llmessage/aicurlperservice.cpp index 533111237..9e13f98c7 100644 --- a/indra/llmessage/aicurlperservice.cpp +++ b/indra/llmessage/aicurlperservice.cpp @@ -1,6 +1,6 @@ /** * @file aiperservice.cpp - * @brief Implementation of AIPerServiceRequestQueue + * @brief Implementation of AIPerService * * Copyright (c) 2012, 2013, Aleric Inglewood. * @@ -41,11 +41,11 @@ #include "aicurlthread.h" #include "llcontrol.h" -AIPerServiceRequestQueue::threadsafe_instance_map_type AIPerServiceRequestQueue::sInstanceMap; -LLAtomicS32 AIPerServiceRequestQueue::sTotalQueued; -bool AIPerServiceRequestQueue::sQueueEmpty; -bool AIPerServiceRequestQueue::sQueueFull; -bool AIPerServiceRequestQueue::sRequestStarvation; +AIPerService::threadsafe_instance_map_type AIPerService::sInstanceMap; +LLAtomicS32 AIPerService::sTotalQueued; +bool AIPerService::sQueueEmpty; +bool AIPerService::sQueueFull; +bool AIPerService::sRequestStarvation; #undef AICurlPrivate @@ -73,7 +73,7 @@ void intrusive_ptr_release(RefCountedThreadSafePerServiceRequestQueue* per_servi using namespace AICurlPrivate; -AIPerServiceRequestQueue::AIPerServiceRequestQueue(void) : +AIPerService::AIPerService(void) : mQueuedCommands(0), mAdded(0), mQueueEmpty(false), mQueueFull(false), mRequestStarvation(false), mHTTPBandwidth(25), // 25 = 1000 ms / 40 ms. mConcurrectConnections(CurlConcurrentConnectionsPerService), @@ -106,7 +106,7 @@ AIPerServiceRequestQueue::AIPerServiceRequestQueue(void) : // - port does not contain a ':', and if it exists is always prepended by a ':'. // //static -std::string AIPerServiceRequestQueue::extract_canonical_servicename(std::string const& url) +std::string AIPerService::extract_canonical_servicename(std::string const& url) { char const* p = url.data(); char const* const end = p + url.size(); @@ -178,21 +178,21 @@ std::string AIPerServiceRequestQueue::extract_canonical_servicename(std::string } //static -AIPerServiceRequestQueuePtr AIPerServiceRequestQueue::instance(std::string const& servicename) +AIPerServicePtr AIPerService::instance(std::string const& servicename) { llassert(!servicename.empty()); instance_map_wat instance_map_w(sInstanceMap); - AIPerServiceRequestQueue::iterator iter = instance_map_w->find(servicename); + AIPerService::iterator iter = instance_map_w->find(servicename); if (iter == instance_map_w->end()) { iter = instance_map_w->insert(instance_map_type::value_type(servicename, new RefCountedThreadSafePerServiceRequestQueue)).first; } - // Note: the creation of AIPerServiceRequestQueuePtr MUST be protected by the lock on sInstanceMap (see release()). + // Note: the creation of AIPerServicePtr MUST be protected by the lock on sInstanceMap (see release()). return iter->second; } //static -void AIPerServiceRequestQueue::release(AIPerServiceRequestQueuePtr& instance) +void AIPerService::release(AIPerServicePtr& instance) { if (instance->exactly_two_left()) // Being 'instance' and the one in sInstanceMap. { @@ -228,29 +228,29 @@ void AIPerServiceRequestQueue::release(AIPerServiceRequestQueuePtr& instance) instance.reset(); } -bool AIPerServiceRequestQueue::throttled() const +bool AIPerService::throttled() const { return mAdded >= mConcurrectConnections; } -void AIPerServiceRequestQueue::added_to_multi_handle(void) +void AIPerService::added_to_multi_handle(void) { ++mAdded; } -void AIPerServiceRequestQueue::removed_from_multi_handle(void) +void AIPerService::removed_from_multi_handle(void) { --mAdded; llassert(mAdded >= 0); } -void AIPerServiceRequestQueue::queue(AICurlEasyRequest const& easy_request) +void AIPerService::queue(AICurlEasyRequest const& easy_request) { mQueuedRequests.push_back(easy_request.get_ptr()); sTotalQueued++; } -bool AIPerServiceRequestQueue::cancel(AICurlEasyRequest const& easy_request) +bool AIPerService::cancel(AICurlEasyRequest const& easy_request) { queued_request_type::iterator const end = mQueuedRequests.end(); queued_request_type::iterator cur = std::find(mQueuedRequests.begin(), end, easy_request.get_ptr()); @@ -263,7 +263,7 @@ bool AIPerServiceRequestQueue::cancel(AICurlEasyRequest const& easy_request) // 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 AIPerServiceRequestQueue object. + // and the deque is protected by the lock on the AIPerService object. queued_request_type::iterator prev = cur; while (++cur != end) { @@ -276,7 +276,7 @@ bool AIPerServiceRequestQueue::cancel(AICurlEasyRequest const& easy_request) return true; } -void AIPerServiceRequestQueue::add_queued_to(curlthread::MultiHandle* multi_handle) +void AIPerService::add_queued_to(curlthread::MultiHandle* multi_handle) { if (!mQueuedRequests.empty()) { @@ -317,7 +317,7 @@ void AIPerServiceRequestQueue::add_queued_to(curlthread::MultiHandle* multi_hand } //static -void AIPerServiceRequestQueue::purge(void) +void AIPerService::purge(void) { instance_map_wat instance_map_w(sInstanceMap); for (iterator host = instance_map_w->begin(); host != instance_map_w->end(); ++host) @@ -332,10 +332,10 @@ void AIPerServiceRequestQueue::purge(void) } //static -void AIPerServiceRequestQueue::adjust_concurrent_connections(int increment) +void AIPerService::adjust_concurrent_connections(int increment) { instance_map_wat instance_map_w(sInstanceMap); - for (AIPerServiceRequestQueue::iterator iter = instance_map_w->begin(); iter != instance_map_w->end(); ++iter) + for (AIPerService::iterator iter = instance_map_w->begin(); iter != instance_map_w->end(); ++iter) { PerServiceRequestQueue_wat per_service_w(*iter->second); U32 old_concurrent_connections = per_service_w->mConcurrectConnections; diff --git a/indra/llmessage/aicurlperservice.h b/indra/llmessage/aicurlperservice.h index 839aa5125..a64d0d57f 100644 --- a/indra/llmessage/aicurlperservice.h +++ b/indra/llmessage/aicurlperservice.h @@ -1,6 +1,6 @@ /** * @file aicurlperservice.h - * @brief Definition of class AIPerServiceRequestQueue + * @brief Definition of class AIPerService * * Copyright (c) 2012, 2013, Aleric Inglewood. * @@ -48,7 +48,7 @@ #include "aiaverage.h" class AICurlEasyRequest; -class AIPerServiceRequestQueue; +class AIPerService; namespace AICurlPrivate { namespace curlthread { class MultiHandle; } @@ -59,38 +59,38 @@ class ThreadSafeBufferedCurlEasyRequest; // Forward declaration of BufferedCurlEasyRequestPtr (see aicurlprivate.h). typedef boost::intrusive_ptr BufferedCurlEasyRequestPtr; -// AIPerServiceRequestQueue objects are created by the curl thread and destructed by the main thread. +// AIPerService objects are created by the curl thread and destructed by the main thread. // We need locking. -typedef AIThreadSafeSimpleDC threadsafe_PerServiceRequestQueue; -typedef AIAccessConst PerServiceRequestQueue_crat; -typedef AIAccess PerServiceRequestQueue_rat; -typedef AIAccess PerServiceRequestQueue_wat; +typedef AIThreadSafeSimpleDC threadsafe_PerServiceRequestQueue; +typedef AIAccessConst PerServiceRequestQueue_crat; +typedef AIAccess PerServiceRequestQueue_rat; +typedef AIAccess PerServiceRequestQueue_wat; } // namespace AICurlPrivate // We can't put threadsafe_PerServiceRequestQueue in a std::map because you can't copy a mutex. // Therefore, use an intrusive pointer for the threadsafe type. -typedef boost::intrusive_ptr AIPerServiceRequestQueuePtr; +typedef boost::intrusive_ptr AIPerServicePtr; //----------------------------------------------------------------------------- -// AIPerServiceRequestQueue +// AIPerService // This class provides a static interface to create and maintain instances -// of AIPerServiceRequestQueue objects, so that at any moment there is at most +// of AIPerService objects, so that at any moment there is at most // one instance per hostname:port. Those instances then are used to queue curl // requests when the maximum number of connections for that host already // have been reached. -class AIPerServiceRequestQueue { +class AIPerService { private: - typedef std::map instance_map_type; + typedef std::map instance_map_type; typedef AIThreadSafeSimpleDC threadsafe_instance_map_type; typedef AIAccess instance_map_rat; typedef AIAccess instance_map_wat; - static threadsafe_instance_map_type sInstanceMap; // Map of AIPerServiceRequestQueue instances with the hostname as key. + static threadsafe_instance_map_type sInstanceMap; // Map of AIPerService instances with the hostname as key. - friend class AIThreadSafeSimpleDC; //threadsafe_PerServiceRequestQueue - AIPerServiceRequestQueue(void); + friend class AIThreadSafeSimpleDC; //threadsafe_PerServiceRequestQueue + AIPerService(void); public: typedef instance_map_type::iterator iterator; @@ -100,10 +100,10 @@ class AIPerServiceRequestQueue { static std::string extract_canonical_servicename(std::string const& url); // Return (possibly create) a unique instance for the given hostname. - static AIPerServiceRequestQueuePtr instance(std::string const& servicename); + static AIPerServicePtr instance(std::string const& servicename); // Release instance (object will be deleted if this was the last instance). - static void release(AIPerServiceRequestQueuePtr& instance); + static void release(AIPerServicePtr& instance); // Remove everything. Called upon viewer exit. static void purge(void); @@ -115,7 +115,7 @@ class AIPerServiceRequestQueue { 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 AIPerServiceRequestQueue objects together. + static LLAtomicS32 sTotalQueued; // The sum of mQueuedRequests.size() of all AIPerService objects together. bool mQueueEmpty; // Set to true when the queue becomes precisely empty. bool mQueueFull; // Set to true when the queue is popped and then still isn't empty; @@ -155,11 +155,11 @@ class AIPerServiceRequestQueue { // Returns true if curl can handle another request for this host. // Should return false if the maximum allowed HTTP bandwidth is reached, or when // the latency between request and actual delivery becomes too large. - static bool wantsMoreHTTPRequestsFor(AIPerServiceRequestQueuePtr const& per_service, F32 max_kbps, bool no_bandwidth_throttling); + static bool wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service, F32 max_kbps, bool no_bandwidth_throttling); private: // Disallow copying. - AIPerServiceRequestQueue(AIPerServiceRequestQueue const&) : mHTTPBandwidth(0) { } + AIPerService(AIPerService const&) : mHTTPBandwidth(0) { } }; namespace AICurlPrivate { @@ -170,7 +170,7 @@ class RefCountedThreadSafePerServiceRequestQueue : public threadsafe_PerServiceR bool exactly_two_left(void) const { return mReferenceCount == 2; } private: - // Used by AIPerServiceRequestQueuePtr. Object is deleted when reference count reaches zero. + // Used by AIPerServicePtr. Object is deleted when reference count reaches zero. LLAtomicU32 mReferenceCount; friend void intrusive_ptr_add_ref(RefCountedThreadSafePerServiceRequestQueue* p); diff --git a/indra/llmessage/aicurlprivate.h b/indra/llmessage/aicurlprivate.h index 5558e31a4..abdc978d4 100644 --- a/indra/llmessage/aicurlprivate.h +++ b/indra/llmessage/aicurlprivate.h @@ -305,7 +305,7 @@ class CurlEasyRequest : public CurlEasyHandle { AIHTTPTimeoutPolicy const* mTimeoutPolicy; std::string mLowercaseServicename; // Lowercase hostname:port (canonicalized) extracted from the url. - AIPerServiceRequestQueuePtr mPerServicePtr; // Pointer to the corresponding AIPerServiceRequestQueue. + AIPerServicePtr mPerServicePtr; // Pointer to the corresponding AIPerService. LLPointer mTimeout;// Timeout administration object associated with last created CurlSocketInfo. bool mTimeoutIsOrphan; // Set to true when mTimeout is not (yet) associated with a CurlSocketInfo. #if defined(CWDEBUG) || defined(DEBUG_CURLIO) @@ -349,8 +349,8 @@ class CurlEasyRequest : public CurlEasyHandle { inline ThreadSafeBufferedCurlEasyRequest const* get_lockobj(void) const; // PerService API. - AIPerServiceRequestQueuePtr getPerServicePtr(void); // (Optionally create and) return a pointer to the unique - // AIPerServiceRequestQueue corresponding to mLowercaseServicename. + AIPerServicePtr getPerServicePtr(void); // (Optionally create and) return a pointer to the unique + // AIPerService corresponding to mLowercaseServicename. bool removeFromPerServiceQueue(AICurlEasyRequest const&) const; // Remove this request from the per-host queue, if queued at all. // Returns true if it was queued. protected: diff --git a/indra/llmessage/aicurlthread.cpp b/indra/llmessage/aicurlthread.cpp index 9e9321e41..47a4d6d59 100644 --- a/indra/llmessage/aicurlthread.cpp +++ b/indra/llmessage/aicurlthread.cpp @@ -1579,7 +1579,7 @@ void AICurlThread::run(void) multi_handle_w->check_msg_queue(); } // Clear the queued requests. - AIPerServiceRequestQueue::purge(); + AIPerService::purge(); } AICurlMultiHandle::destroyInstance(); } @@ -1706,7 +1706,7 @@ static U32 curl_max_total_concurrent_connections = 32; // Initialized on st void MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request) { bool throttled = true; // Default. - AIPerServiceRequestQueuePtr per_service; + AIPerServicePtr per_service; { AICurlEasyRequest_wat curl_easy_request_w(*easy_request); per_service = curl_easy_request_w->getPerServicePtr(); @@ -1765,7 +1765,7 @@ CURLMcode MultiHandle::remove_easy_request(AICurlEasyRequest const& easy_request CURLMcode MultiHandle::remove_easy_request(addedEasyRequests_type::iterator const& iter, bool as_per_command) { CURLMcode res; - AIPerServiceRequestQueuePtr per_service; + AIPerServicePtr per_service; { AICurlEasyRequest_wat curl_easy_request_w(**iter); res = curl_easy_request_w->remove_handle_from_multi(curl_easy_request_w, mMultiHandle); @@ -2534,7 +2534,7 @@ bool handleCurlConcurrentConnectionsPerService(LLSD const& newvalue) using namespace AICurlPrivate; U32 new_concurrent_connections = newvalue.asInteger(); - AIPerServiceRequestQueue::adjust_concurrent_connections(new_concurrent_connections - CurlConcurrentConnectionsPerService); + AIPerService::adjust_concurrent_connections(new_concurrent_connections - CurlConcurrentConnectionsPerService); CurlConcurrentConnectionsPerService = new_concurrent_connections; llinfos << "CurlConcurrentConnectionsPerService set to " << CurlConcurrentConnectionsPerService << llendl; return true; @@ -2556,7 +2556,7 @@ U32 getNumHTTPCommands(void) U32 getNumHTTPQueued(void) { - return AIPerServiceRequestQueue::total_queued_size(); + return AIPerService::total_queued_size(); } U32 getNumHTTPAdded(void) @@ -2590,16 +2590,16 @@ size_t getHTTPBandwidth(void) // causes it to go through the states bs_reset, bs_initialize and then bs_multiplex with // run state AICurlEasyRequestStateMachine_addRequest. Finally, in this state, multiplex // calls AICurlEasyRequestStateMachine::multiplex_impl which then calls AICurlEasyRequest::addRequest -// which causes an increment of command_queue_w->size and AIPerServiceRequestQueue::mQueuedCommands. +// which causes an increment of command_queue_w->size and AIPerService::mQueuedCommands. // // It is therefore guaranteed that in one loop of LLTextureFetchWorker::doWork, // this size is incremented; stopping this function from returning true once we reached the // threshold of "pipelines" requests (the sum of requests in the command queue, the ones -// throttled and queued in AIPerServiceRequestQueue::mQueuedRequests and the already +// throttled and queued in AIPerService::mQueuedRequests and the already // running requests (in MultiHandle::mAddedEasyRequests)). // //static -bool AIPerServiceRequestQueue::wantsMoreHTTPRequestsFor(AIPerServiceRequestQueuePtr const& per_service, F32 max_kbps, bool no_bandwidth_throttling) +bool AIPerService::wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service, F32 max_kbps, bool no_bandwidth_throttling) { using namespace AICurlPrivate; using namespace AICurlPrivate::curlthread; @@ -2740,7 +2740,7 @@ bool AIPerServiceRequestQueue::wantsMoreHTTPRequestsFor(AIPerServiceRequestQueue // here instead. // The maximum number of requests that may be queued in command_queue is equal to the total number of requests - // that may exist in the pipeline minus the number of requests queued in AIPerServiceRequestQueue objects, minus + // that may exist in the pipeline minus the number of requests queued in AIPerService objects, minus // the number of already running requests. reject = pipelined_requests >= max_pipelined_requests_cache; equal = pipelined_requests == max_pipelined_requests_cache; diff --git a/indra/llmessage/aicurlthread.h b/indra/llmessage/aicurlthread.h index 44a4786af..9f71b015c 100644 --- a/indra/llmessage/aicurlthread.h +++ b/indra/llmessage/aicurlthread.h @@ -81,7 +81,7 @@ class MultiHandle : public CurlMultiHandle // Store result and trigger events for easy request. void finish_easy_request(AICurlEasyRequest const& easy_request, CURLcode result); // Remove easy request at iter (must exist). - // Note that it's possible that a new request from a AIPerServiceRequestQueue::mQueuedRequests is inserted before iter. + // Note that it's possible that a new request from a AIPerService::mQueuedRequests is inserted before iter. CURLMcode remove_easy_request(addedEasyRequests_type::iterator const& iter, bool as_per_command); static int socket_callback(CURL* easy, curl_socket_t s, int action, void* userp, void* socketp); diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp index cd9f44904..c7603dc26 100644 --- a/indra/newview/lltexturefetch.cpp +++ b/indra/newview/lltexturefetch.cpp @@ -254,7 +254,7 @@ private: LLUUID mID; LLHost mHost; std::string mUrl; - AIPerServiceRequestQueuePtr mPerServicePtr; // Pointer to the AIPerServiceRequestQueue corresponding to the host of mUrl. + AIPerServicePtr mPerServicePtr; // Pointer to the AIPerService corresponding to the host of mUrl. U8 mType; F32 mImagePriority; U32 mWorkPriority; @@ -800,11 +800,11 @@ LLTextureFetchWorker::LLTextureFetchWorker(LLTextureFetch* fetcher, if (!mCanUseNET) { // Probably a file://, but well; in that case servicename will be empty. - std::string servicename = AIPerServiceRequestQueue::extract_canonical_servicename(mUrl); + std::string servicename = AIPerService::extract_canonical_servicename(mUrl); if (!servicename.empty()) { // Make sure mPerServicePtr is up to date with mUrl. - mPerServicePtr = AIPerServiceRequestQueue::instance(servicename); + mPerServicePtr = AIPerService::instance(servicename); } } @@ -1163,7 +1163,7 @@ bool LLTextureFetchWorker::doWork(S32 param) { mUrl = http_url + "/?texture_id=" + mID.asString().c_str(); mWriteToCacheState = CAN_WRITE ; //because this texture has a fixed texture id. - mPerServicePtr = AIPerServiceRequestQueue::instance(AIPerServiceRequestQueue::extract_canonical_servicename(http_url)); + mPerServicePtr = AIPerService::instance(AIPerService::extract_canonical_servicename(http_url)); } else { @@ -1274,7 +1274,7 @@ bool LLTextureFetchWorker::doWork(S32 param) // Let AICurl decide if we can process more HTTP requests at the moment or not. static const LLCachedControl throttle_bandwidth("HTTPThrottleBandwidth", 2000); bool const no_bandwidth_throttling = gHippoGridManager->getConnectedGrid()->isAvination(); - if (!AIPerServiceRequestQueue::wantsMoreHTTPRequestsFor(mPerServicePtr, throttle_bandwidth, no_bandwidth_throttling)) + if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr, throttle_bandwidth, no_bandwidth_throttling)) { return false ; //wait. }