diff options
Diffstat (limited to 'indra/llmessage/llexperiencecache.cpp')
| -rw-r--r-- | indra/llmessage/llexperiencecache.cpp | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index b5d0c93376..e4c7deb1c5 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -35,7 +35,6 @@ #include <set> #include <map> #include <boost/tokenizer.hpp> -#include <boost/concept_check.hpp> //========================================================================= namespace LLExperienceCacheImpl @@ -94,6 +93,8 @@ LLExperienceCache::LLExperienceCache() LLExperienceCache::~LLExperienceCache() { + // can exit without cleanup() + sShutdown = true; } void LLExperienceCache::initSingleton() @@ -108,11 +109,10 @@ void LLExperienceCache::initSingleton() cache_stream >> (*this); } - LLCoprocedureManager::instance().initializePool("ExpCache"); - - LLCoros::instance().launch("LLExperienceCache::idleCoro", - boost::bind(&LLExperienceCache::idleCoro, this)); + constexpr size_t CORO_QUEUE_SIZE = 2048; + LLCoprocedureManager::instance().initializePool("ExpCache", CORO_QUEUE_SIZE); + LLCoros::instance().launch("LLExperienceCache::idleCoro", LLExperienceCache::idleCoro); } void LLExperienceCache::cleanup() @@ -244,14 +244,22 @@ const LLExperienceCache::cache_t& LLExperienceCache::getCached() return mCache; } +// static because used by coroutine and can outlive the instance void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, std::string url, RequestQueue_t requests) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); //LL_INFOS("requestExperiencesCoro") << "url: " << url << LL_ENDL; LLSD result = httpAdapter->getAndSuspend(httpRequest, url); + if (sShutdown) + { + return; + } + + LLExperienceCache* self = LLExperienceCache::getInstance(); + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -263,7 +271,7 @@ void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdap // build dummy entries for the failed requests for (RequestQueue_t::const_iterator it = requests.begin(); it != requests.end(); ++it) { - LLSD exp = get(*it); + LLSD exp = self->get(*it); //leave the properties alone if we already have a cache entry for this xp if (exp.isUndefined()) { @@ -276,7 +284,7 @@ void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdap exp["error"] = (LLSD::Integer)status.getType(); exp[QUOTA] = DEFAULT_QUOTA; - processExperience(*it, exp); + self->processExperience(*it, exp); } return; } @@ -292,7 +300,7 @@ void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdap LL_DEBUGS("ExperienceCache") << "Received result for " << public_key << " display '" << row[LLExperienceCache::NAME].asString() << "'" << LL_ENDL; - processExperience(public_key, row); + self->processExperience(public_key, row); } LLSD error_ids = result["error_ids"]; @@ -308,7 +316,7 @@ void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdap exp[MISSING] = true; exp[QUOTA] = DEFAULT_QUOTA; - processExperience(id, exp); + self->processExperience(id, exp); LL_WARNS("ExperienceCache") << "LLExperienceResponder::result() error result for " << id << LL_ENDL; } @@ -317,7 +325,7 @@ void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdap void LLExperienceCache::requestExperiences() { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -359,7 +367,7 @@ void LLExperienceCache::requestExperiences() if (mRequestQueue.empty() || (ostr.tellp() > EXP_URL_SEND_THRESHOLD)) { // request is placed in the coprocedure pool for the ExpCache cache. Throttling is done by the pool itself. LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "RequestExperiences", - boost::bind(&LLExperienceCache::requestExperiencesCoro, this, _1, ostr.str(), requests) ); + boost::bind(&LLExperienceCache::requestExperiencesCoro, _1, ostr.str(), requests) ); ostr.str(std::string()); ostr << urlBase << "?page_size=" << PAGE_SIZE1; @@ -391,7 +399,7 @@ void LLExperienceCache::setCapabilityQuery(LLExperienceCache::CapabilityQuery_t mCapability = queryfn; } - +// static, because coro can outlive the instance void LLExperienceCache::idleCoro() { const F32 SECS_BETWEEN_REQUESTS = 0.5f; @@ -400,14 +408,15 @@ void LLExperienceCache::idleCoro() LL_INFOS("ExperienceCache") << "Launching Experience cache idle coro." << LL_ENDL; do { - if (mEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) + LLExperienceCache* self = LLExperienceCache::getInstance(); + if (self->mEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) { - eraseExpired(); + self->eraseExpired(); } - if (!mRequestQueue.empty()) + if (!self->mRequestQueue.empty()) { - requestExperiences(); + self->requestExperiences(); } llcoro::suspendUntilTimeout(SECS_BETWEEN_REQUESTS); @@ -524,7 +533,7 @@ void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::ExperienceGetF fetch(key); - signal_ptr signal = signal_ptr(new callback_signal_t()); + signal_ptr signal = std::make_shared<callback_signal_t>(); std::pair<signal_map_t::iterator, bool> result = mSignalMap.insert(signal_map_t::value_type(key, signal)); if (!result.second) @@ -535,7 +544,7 @@ void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::ExperienceGetF //========================================================================= void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const LLUUID& itemId, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -547,7 +556,7 @@ void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const LLUUID& itemId, std::string url, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -559,7 +568,7 @@ void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID objectId, LLUUID itemId, std::string url, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); if (url.empty()) { @@ -597,8 +606,10 @@ void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCorout failure["error"] = -1; failure["message"] = "no experience"; } - if (fn && !fn.empty()) + if (fn != nullptr) + { fn(failure); + } return; } @@ -609,7 +620,7 @@ void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCorout //------------------------------------------------------------------------- void LLExperienceCache::findExperienceByName(const std::string text, int page, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -621,7 +632,7 @@ void LLExperienceCache::findExperienceByName(const std::string text, int page, E void LLExperienceCache::findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, std::string text, int page, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); std::ostringstream url; @@ -652,7 +663,7 @@ void LLExperienceCache::findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAd //------------------------------------------------------------------------- void LLExperienceCache::getGroupExperiences(const LLUUID &groupId, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -664,7 +675,7 @@ void LLExperienceCache::getGroupExperiences(const LLUUID &groupId, ExperienceGet void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID groupId, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); // search for experiences owned by the current group std::string url = mCapability("GroupExperiences"); @@ -707,7 +718,7 @@ void LLExperienceCache::setRegionExperiences(CapabilityQuery_t regioncaps, const void LLExperienceCache::regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, CapabilityQuery_t regioncaps, bool update, LLSD experiences, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); // search for experiences owned by the current group std::string url = regioncaps("RegionExperiences"); @@ -740,7 +751,7 @@ void LLExperienceCache::regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapt //------------------------------------------------------------------------- void LLExperienceCache::getExperiencePermission(const LLUUID &experienceId, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -764,7 +775,7 @@ void LLExperienceCache::getExperiencePermission(const LLUUID &experienceId, Expe void LLExperienceCache::setExperiencePermission(const LLUUID &experienceId, const std::string &permission, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -794,7 +805,7 @@ void LLExperienceCache::setExperiencePermission(const LLUUID &experienceId, cons void LLExperienceCache::forgetExperiencePermission(const LLUUID &experienceId, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -819,7 +830,7 @@ void LLExperienceCache::forgetExperiencePermission(const LLUUID &experienceId, E void LLExperienceCache::experiencePermissionCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, permissionInvoker_fn invokerfn, std::string url, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); // search for experiences owned by the current group @@ -838,7 +849,7 @@ void LLExperienceCache::experiencePermissionCoro(LLCoreHttpUtil::HttpCoroutineAd //------------------------------------------------------------------------- void LLExperienceCache::getExperienceAdmin(const LLUUID &experienceId, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -850,7 +861,7 @@ void LLExperienceCache::getExperienceAdmin(const LLUUID &experienceId, Experienc void LLExperienceCache::getExperienceAdminCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID experienceId, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); std::string url = mCapability("IsExperienceAdmin"); if (url.empty()) @@ -870,7 +881,7 @@ void LLExperienceCache::getExperienceAdminCoro(LLCoreHttpUtil::HttpCoroutineAdap //------------------------------------------------------------------------- void LLExperienceCache::updateExperience(LLSD updateData, ExperienceGetFn_t fn) { - if (mCapability.empty()) + if (mCapability == nullptr) { LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; return; @@ -882,7 +893,7 @@ void LLExperienceCache::updateExperience(LLSD updateData, ExperienceGetFn_t fn) void LLExperienceCache::updateExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLSD updateData, ExperienceGetFn_t fn) { - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>(); std::string url = mCapability("UpdateExperience"); if (url.empty()) |
