From bb8ea493d64a2a4ae9e7deffa0a545823118d906 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Mon, 15 Oct 2012 21:03:08 +0200 Subject: [PATCH] Fix top check in MultiHandle::check_run_count. This check isn't really needed at all, since curl_multi_info_read is fast enough, but well... The old check was flawed anyway. --- indra/aistatemachine/aicurlthread.cpp | 9 +++------ indra/aistatemachine/aicurlthread.h | 7 ++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/indra/aistatemachine/aicurlthread.cpp b/indra/aistatemachine/aicurlthread.cpp index bb0e4458d..a973e4260 100644 --- a/indra/aistatemachine/aicurlthread.cpp +++ b/indra/aistatemachine/aicurlthread.cpp @@ -1420,7 +1420,7 @@ void AICurlThread::run(void) //----------------------------------------------------------------------------- // MultiHandle -MultiHandle::MultiHandle(void) : mHandleAddedOrRemoved(false), mPrevRunningHandles(0), mRunningHandles(0), mTimeOut(-1), mReadPollSet(NULL), mWritePollSet(NULL) +MultiHandle::MultiHandle(void) : mRunningHandles(0), mTimeout(-1), mReadPollSet(NULL), mWritePollSet(NULL) { mReadPollSet = new PollSet; mWritePollSet = new PollSet; @@ -1543,7 +1543,6 @@ void MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request) } if (ret == CURLM_OK) { - mHandleAddedOrRemoved = true; std::pair res = mAddedEasyRequests.insert(easy_request); llassert(res.second); // May not have been added before. Dout(dc::curl, "MultiHandle::add_easy_request: Added AICurlEasyRequest " << (void*)easy_request.get_ptr().get() << "; now processing " << mAddedEasyRequests.size() << " easy handles."); @@ -1603,7 +1602,6 @@ CURLMcode MultiHandle::remove_easy_request(addedEasyRequests_type::iterator cons ThreadSafeCurlEasyRequest* lockobj = iter->get_ptr().get(); #endif mAddedEasyRequests.erase(iter); - mHandleAddedOrRemoved = true; Dout(dc::curl, "MultiHandle::remove_easy_request: Removed AICurlEasyRequest " << (void*)lockobj << "; now processing " << mAddedEasyRequests.size() << " easy handles."); // Attempt to add a queued request, if any. @@ -1618,7 +1616,8 @@ CURLMcode MultiHandle::remove_easy_request(addedEasyRequests_type::iterator cons void MultiHandle::check_run_count(void) { - if (mHandleAddedOrRemoved || mRunningHandles < mPrevRunningHandles) + llassert(mAddedEasyRequests.size() >= mRunningHandles); + if (mAddedEasyRequests.size() - mRunningHandles > 0) // There is no need to do this when all easy handles are accounted for. { CURLMsg const* msg; int msgs_left; @@ -1652,9 +1651,7 @@ void MultiHandle::check_run_count(void) // Destruction of easy_request at this point, causes the CurlEasyRequest to be deleted. } } - mHandleAddedOrRemoved = false; } - mPrevRunningHandles = mRunningHandles; } void MultiHandle::finish_easy_request(AICurlEasyRequest const& easy_request, CURLcode result) diff --git a/indra/aistatemachine/aicurlthread.h b/indra/aistatemachine/aicurlthread.h index 70657e443..1ca677990 100644 --- a/indra/aistatemachine/aicurlthread.h +++ b/indra/aistatemachine/aicurlthread.h @@ -74,11 +74,8 @@ class MultiHandle : public CurlMultiHandle private: typedef std::set addedEasyRequests_type; - addedEasyRequests_type mAddedEasyRequests; - - bool mHandleAddedOrRemoved; // Set when an easy handle was added or removed, reset in check_run_count(). - int mPrevRunningHandles; // The last value of mRunningHandles that check_run_count() was called with. - int mRunningHandles; // The last value returned by curl_multi_socket_action. + addedEasyRequests_type mAddedEasyRequests; // All easy requests currently added to the multi handle. + int mRunningHandles; // The last value returned by curl_multi_socket_action. long mTimeout; // The last timeout in ms as set by the callback CURLMOPT_TIMERFUNCTION. private: