Changeset 279993 in webkit


Ignore:
Timestamp:
Jul 16, 2021, 1:19:40 PM (4 years ago)
Author:
Fujii Hironori
Message:

[curl] Use curl_multi_poll and curl_multi_wakeup instead of select
https://bugs.webkit.org/show_bug.cgi?id=227966

Reviewed by Don Olmstead.

libcurl 7.68.0 added curl_multi_poll and curl_multi_wakeup.

  • platform/network/curl/CurlContext.cpp:

(WebCore::CurlMultiHandle::poll): Added.
(WebCore::CurlMultiHandle::wakeUp): Added.

  • platform/network/curl/CurlContext.h:
  • platform/network/curl/CurlRequestScheduler.cpp:

(WebCore::CurlRequestScheduler::add):
(WebCore::CurlRequestScheduler::callOnWorkerThread):
(WebCore::CurlRequestScheduler::startOrWakeUpThread):
(WebCore::CurlRequestScheduler::wakeUpThreadIfPossible): Added.
(WebCore::CurlRequestScheduler::stopThread):
(WebCore::CurlRequestScheduler::workerThread):
(WebCore::CurlRequestScheduler::startThreadIfNeeded): Deleted.

  • platform/network/curl/CurlRequestScheduler.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r279990 r279993  
     12021-07-16  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        [curl] Use curl_multi_poll and curl_multi_wakeup instead of select
     4        https://bugs.webkit.org/show_bug.cgi?id=227966
     5
     6        Reviewed by Don Olmstead.
     7
     8        libcurl 7.68.0 added curl_multi_poll and curl_multi_wakeup.
     9
     10        * platform/network/curl/CurlContext.cpp:
     11        (WebCore::CurlMultiHandle::poll): Added.
     12        (WebCore::CurlMultiHandle::wakeUp): Added.
     13        * platform/network/curl/CurlContext.h:
     14        * platform/network/curl/CurlRequestScheduler.cpp:
     15        (WebCore::CurlRequestScheduler::add):
     16        (WebCore::CurlRequestScheduler::callOnWorkerThread):
     17        (WebCore::CurlRequestScheduler::startOrWakeUpThread):
     18        (WebCore::CurlRequestScheduler::wakeUpThreadIfPossible): Added.
     19        (WebCore::CurlRequestScheduler::stopThread):
     20        (WebCore::CurlRequestScheduler::workerThread):
     21        (WebCore::CurlRequestScheduler::startThreadIfNeeded): Deleted.
     22        * platform/network/curl/CurlRequestScheduler.h:
     23
    1242021-07-16  Myles C. Maxfield  <mmaxfield@apple.com>
    225
  • trunk/Source/WebCore/platform/network/curl/CurlContext.cpp

    r279575 r279993  
    267267}
    268268
     269CURLMcode CurlMultiHandle::poll(const Vector<curl_waitfd>& extraFds, int timeoutMS)
     270{
     271    int numFds = 0;
     272    return curl_multi_poll(m_multiHandle, const_cast<curl_waitfd*>(extraFds.data()), extraFds.size(), timeoutMS, &numFds);
     273}
     274
     275CURLMcode CurlMultiHandle::wakeUp()
     276{
     277    return curl_multi_wakeup(m_multiHandle);
     278}
     279
    269280CURLMcode CurlMultiHandle::perform(int& runningHandles)
    270281{
  • trunk/Source/WebCore/platform/network/curl/CurlContext.h

    r278516 r279993  
    175175
    176176    CURLMcode getFdSet(fd_set&, fd_set&, fd_set&, int&);
     177    CURLMcode poll(const Vector<curl_waitfd>&, int);
     178    CURLMcode wakeUp();
    177179    CURLMcode perform(int&);
    178180    CURLMsg* readInfo(int&);
  • trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.cpp

    r277908 r279993  
    5050
    5151    startTransfer(client);
    52     startThreadIfNeeded();
     52    startOrWakeUpThread();
    5353
    5454    return true;
     
    7272    }
    7373
    74     startThreadIfNeeded();
    75 }
    76 
    77 void CurlRequestScheduler::startThreadIfNeeded()
     74    startOrWakeUpThread();
     75}
     76
     77void CurlRequestScheduler::startOrWakeUpThread()
    7878{
    7979    ASSERT(isMainThread());
     
    8181    {
    8282        Locker locker { m_mutex };
    83         if (m_runThread)
     83        if (m_runThread) {
     84            wakeUpThreadIfPossible();
    8485            return;
     86        }
    8587    }
    8688
     
    9597    m_thread = Thread::create("curlThread", [this] {
    9698        workerThread();
    97 
    98         Locker locker { m_mutex };
    99         m_runThread = false;
    10099    }, ThreadType::Network);
     100}
     101
     102void CurlRequestScheduler::wakeUpThreadIfPossible()
     103{
     104    Locker locker { m_multiHandleMutex };
     105    if (!m_curlMultiHandle)
     106        return;
     107
     108    m_curlMultiHandle->wakeUp();
    101109}
    102110
     
    120128
    121129    if (m_thread) {
     130        wakeUpThreadIfPossible();
    122131        m_thread->waitForCompletion();
    123132        m_thread = nullptr;
     
    144153    ASSERT(!isMainThread());
    145154
    146     m_curlMultiHandle = makeUnique<CurlMultiHandle>();
    147     m_curlMultiHandle->setMaxConnects(m_maxConnects);
    148     m_curlMultiHandle->setMaxTotalConnections(m_maxTotalConnections);
    149     m_curlMultiHandle->setMaxHostConnections(m_maxHostConnections);
     155    {
     156        Locker locker { m_multiHandleMutex };
     157        m_curlMultiHandle.emplace();
     158        m_curlMultiHandle->setMaxConnects(m_maxConnects);
     159        m_curlMultiHandle->setMaxTotalConnections(m_maxTotalConnections);
     160        m_curlMultiHandle->setMaxHostConnections(m_maxHostConnections);
     161    }
    150162
    151163    while (true) {
     
    158170        executeTasks();
    159171
    160         // Retry 'select' if it was interrupted by a process signal.
    161         int rc = 0;
    162         do {
    163             fd_set fdread;
    164             fd_set fdwrite;
    165             fd_set fdexcep;
    166             int maxfd = 0;
    167 
    168             const int selectTimeoutMS = 5;
    169 
    170             struct timeval timeout;
    171             timeout.tv_sec = 0;
    172             timeout.tv_usec = selectTimeoutMS * 1000; // select waits microseconds
    173 
    174             m_curlMultiHandle->getFdSet(fdread, fdwrite, fdexcep, maxfd);
    175 
    176             // When the 3 file descriptors are empty, winsock will return -1
    177             // and bail out, stopping the file download. So make sure we
    178             // have valid file descriptors before calling select.
    179             if (maxfd >= 0)
    180                 rc = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
    181         } while (rc == -1 && errno == EINTR);
     172        const int selectTimeoutMS = INT_MAX;
     173        m_curlMultiHandle->poll({ }, selectTimeoutMS);
    182174
    183175        int activeCount = 0;
     
    200192    }
    201193
    202     m_curlMultiHandle = nullptr;
     194    {
     195        Locker locker { m_multiHandleMutex };
     196        m_curlMultiHandle.reset();
     197    }
    203198}
    204199
  • trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.h

    r248762 r279993  
    5252
    5353private:
    54     void startThreadIfNeeded();
     54    void startOrWakeUpThread();
     55    void wakeUpThreadIfPossible();
    5556    void stopThreadIfNoMoreJobRunning();
    5657    void stopThread();
     
    7374    HashMap<CURL*, CurlRequestSchedulerClient*> m_clientMaps;
    7475
    75     std::unique_ptr<CurlMultiHandle> m_curlMultiHandle;
     76    Lock m_multiHandleMutex;
     77    std::optional<CurlMultiHandle> m_curlMultiHandle;
    7678
    7779    long m_maxConnects;
Note: See TracChangeset for help on using the changeset viewer.