Changeset 161157 in webkit


Ignore:
Timestamp:
Dec 30, 2013 3:46:31 PM (10 years ago)
Author:
andersca@apple.com
Message:

Move more of Connection over to STL threading primitives
https://bugs.webkit.org/show_bug.cgi?id=126308

Reviewed by Andreas Kling.

  • Platform/IPC/Connection.cpp:

(IPC::BinarySemaphore::BinarySemaphore):
(IPC::BinarySemaphore::~BinarySemaphore):
(IPC::BinarySemaphore::signal):
(IPC::BinarySemaphore::wait):
Add a new BinarySemaphore class that uses STL threading primitives.

(IPC::Connection::SyncMessageState::wait):
Change this to take a std::chrono::steady_clock::time_point.

(IPC::absoluteTimeoutTime):
Add a new helper function that returns a time point from the a given timeout duration,
correctly handling the max duration.

(IPC::Connection::sendSyncMessageFromSecondaryThread):
Pass a time point to SyncMessageState::wait.

(IPC::Connection::waitForSyncReply):
Ditto.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r161156 r161157  
     12013-12-30  Anders Carlsson  <andersca@apple.com>
     2
     3        Move more of Connection over to STL threading primitives
     4        https://bugs.webkit.org/show_bug.cgi?id=126308
     5
     6        Reviewed by Andreas Kling.
     7
     8        * Platform/IPC/Connection.cpp:
     9        (IPC::BinarySemaphore::BinarySemaphore):
     10        (IPC::BinarySemaphore::~BinarySemaphore):
     11        (IPC::BinarySemaphore::signal):
     12        (IPC::BinarySemaphore::wait):
     13        Add a new BinarySemaphore class that uses STL threading primitives.
     14
     15        (IPC::Connection::SyncMessageState::wait):
     16        Change this to take a std::chrono::steady_clock::time_point.
     17
     18        (IPC::absoluteTimeoutTime):
     19        Add a new helper function that returns a time point from the a given timeout duration,
     20        correctly handling the max duration.
     21
     22        (IPC::Connection::sendSyncMessageFromSecondaryThread):
     23        Pass a time point to SyncMessageState::wait.
     24
     25        (IPC::Connection::waitForSyncReply):
     26        Ditto.
     27
    1282013-12-30  Ryuan Choi  <ryuan.choi@samsung.com>
    229
  • trunk/Source/WebKit2/Platform/IPC/Connection.cpp

    r161152 r161157  
    3232#include <wtf/RunLoop.h>
    3333#include <wtf/text/WTFString.h>
    34 #include <wtf/threads/BinarySemaphore.h>
    3534
    3635namespace IPC {
     36
     37class BinarySemaphore {
     38public:
     39    BinarySemaphore()
     40        : m_isSet(false)
     41    {
     42    }
     43   
     44    ~BinarySemaphore()
     45    {
     46    }
     47
     48    void signal()
     49    {
     50        std::lock_guard<std::mutex> lock(m_mutex);
     51   
     52        m_isSet = true;
     53        m_conditionVariable.notify_all();
     54    }
     55   
     56    bool wait(std::chrono::steady_clock::time_point absoluteTime)
     57    {
     58        std::unique_lock<std::mutex> lock(m_mutex);
     59   
     60        bool value = m_conditionVariable.wait_until(lock, absoluteTime, [this] { return m_isSet; });
     61       
     62        return value;
     63    }
     64
     65private:
     66    bool m_isSet;
     67   
     68    std::mutex m_mutex;
     69    std::condition_variable m_conditionVariable;
     70};
    3771
    3872class Connection::SyncMessageState : public ThreadSafeRefCounted<Connection::SyncMessageState> {
     
    4680    }
    4781
    48     bool wait(double absoluteTime)
     82    bool wait(std::chrono::steady_clock::time_point absoluteTime)
    4983    {
    5084        return m_waitForSyncReplySemaphore.wait(absoluteTime);
     
    377411}
    378412
     413static std::chrono::steady_clock::time_point absoluteTimeoutTime(std::chrono::milliseconds timeout)
     414{
     415    // We use std::chrono::milliseconds::max() to mean no timeout.
     416    if (timeout == std::chrono::milliseconds::max())
     417        return std::chrono::steady_clock::time_point::max();
     418   
     419    return std::chrono::steady_clock::now() + timeout;
     420}
     421   
    379422std::unique_ptr<MessageDecoder> Connection::waitForMessage(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, std::chrono::milliseconds timeout)
    380423{
     
    501544    sendMessage(std::move(encoder), 0);
    502545
    503     pendingReply.semaphore.wait(currentTime() + (timeout.count() / 1000.0));
     546    auto timeoutTime = absoluteTimeoutTime(timeout);
     547    pendingReply.semaphore.wait(timeoutTime);
    504548
    505549    // Finally, pop the pending sync reply information.
     
    515559std::unique_ptr<MessageDecoder> Connection::waitForSyncReply(uint64_t syncRequestID, std::chrono::milliseconds timeout, unsigned syncSendFlags)
    516560{
    517     double absoluteTime = currentTime() + (timeout.count() / 1000.0);
     561    auto timeoutTime = absoluteTimeoutTime(timeout);
    518562
    519563    bool timedOut = false;
     
    551595            // account for a timeout value passed in. Timeout is always NoTimeout in these cases, but that could change.
    552596            RunLoop::current()->runForDuration(1e10);
    553             timedOut = currentTime() >= absoluteTime;
     597            timedOut = std::chrono::steady_clock::now() >= timeoutTime;
    554598#endif
    555599        } else
    556             timedOut = !m_syncMessageState->wait(absoluteTime);
     600            timedOut = !m_syncMessageState->wait(timeoutTime);
    557601       
    558602    }
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r161148 r161157  
    822822    // second timeout. That way, even if the parent decides not to add it, we'll only be
    823823    // incorrect for a little while.
    824     m_plugInAutoStartOriginHashes.set(plugInOriginHash, currentTime() + 30 * 1000);
     824    m_plugInAutoStartOriginHashes.set(plugIn    OriginHash, currentTime() + 30 * 1000);
    825825
    826826    parentProcessConnection()->send(Messages::WebContext::AddPlugInAutoStartOriginHash(pageOrigin, plugInOriginHash), 0);
Note: See TracChangeset for help on using the changeset viewer.