Collect mutex and data protected by it in a single struct
Also use critical section instead of a mutex, as this is more efficient under MSW. Main purpose of this commit is to make it clear that this mutex/critical section is only used together with the data from the same struct. No real changes.
This commit is contained in:
@@ -145,8 +145,13 @@ private:
|
|||||||
wxMutex m_mutex;
|
wxMutex m_mutex;
|
||||||
wxCondition m_condition;
|
wxCondition m_condition;
|
||||||
bool m_shuttingDown;
|
bool m_shuttingDown;
|
||||||
wxMutex m_cancelledMutex;
|
|
||||||
wxVector< wxObjectDataPtr<wxWebRequestCURL> > m_cancelledRequests;
|
// MT-safe vector of requests for which Cancel() was called.
|
||||||
|
struct CancelledData
|
||||||
|
{
|
||||||
|
wxCriticalSection cs;
|
||||||
|
wxVector< wxObjectDataPtr<wxWebRequestCURL> > requests;
|
||||||
|
} m_cancelled;
|
||||||
|
|
||||||
static int ms_activeSessions;
|
static int ms_activeSessions;
|
||||||
|
|
||||||
|
@@ -448,11 +448,11 @@ wxThread::ExitCode wxWebSessionCURL::Entry()
|
|||||||
{
|
{
|
||||||
// Handle cancelled requests
|
// Handle cancelled requests
|
||||||
{
|
{
|
||||||
wxMutexLocker lock(m_cancelledMutex);
|
wxCriticalSectionLocker lock(m_cancelled.cs);
|
||||||
while ( !m_cancelledRequests.empty() )
|
while ( !m_cancelled.requests.empty() )
|
||||||
{
|
{
|
||||||
wxObjectDataPtr<wxWebRequestCURL> request(m_cancelledRequests.back());
|
wxObjectDataPtr<wxWebRequestCURL> request(m_cancelled.requests.back());
|
||||||
m_cancelledRequests.pop_back();
|
m_cancelled.requests.pop_back();
|
||||||
curl_multi_remove_handle(m_handle, request->GetHandle());
|
curl_multi_remove_handle(m_handle, request->GetHandle());
|
||||||
request->SetState(wxWebRequest::State_Cancelled);
|
request->SetState(wxWebRequest::State_Cancelled);
|
||||||
}
|
}
|
||||||
@@ -527,9 +527,9 @@ void wxWebSessionCURL::CancelRequest(wxWebRequestCURL* request)
|
|||||||
{
|
{
|
||||||
// Add the request to a list of threads that will be removed from the curl
|
// Add the request to a list of threads that will be removed from the curl
|
||||||
// multi handle in the worker thread
|
// multi handle in the worker thread
|
||||||
wxMutexLocker lock(m_cancelledMutex);
|
wxCriticalSectionLocker lock(m_cancelled.cs);
|
||||||
request->IncRef();
|
request->IncRef();
|
||||||
m_cancelledRequests.push_back(wxObjectDataPtr<wxWebRequestCURL>(request));
|
m_cancelled.requests.push_back(wxObjectDataPtr<wxWebRequestCURL>(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxVersionInfo wxWebSessionCURL::GetLibraryVersionInfo()
|
wxVersionInfo wxWebSessionCURL::GetLibraryVersionInfo()
|
||||||
|
Reference in New Issue
Block a user