Changeset 181079 in webkit


Ignore:
Timestamp:
Mar 5, 2015 9:05:54 AM (9 years ago)
Author:
Antti Koivisto
Message:

Switch NetworkCacheStorage to WorkQueue abstraction
https://bugs.webkit.org/show_bug.cgi?id=142337

Reviewed by Anders Carlsson.

Don't use dispatch_async directly.

  • NetworkProcess/cache/NetworkCacheStorage.h:

(WebKit::NetworkCacheStorage::ioQueue):
(WebKit::NetworkCacheStorage::backgroundIOQueue):

  • NetworkProcess/cache/NetworkCacheStorageCocoa.mm:

(WebKit::NetworkCacheStorage::NetworkCacheStorage):
(WebKit::NetworkCacheStorage::initialize):
(WebKit::NetworkCacheStorage::removeEntry):
(WebKit::NetworkCacheStorage::dispatchReadOperation):
(WebKit::retrieveFromMemory):
(WebKit::NetworkCacheStorage::traverse):
(WebKit::NetworkCacheStorage::dispatchFullWriteOperation):
(WebKit::NetworkCacheStorage::dispatchHeaderWriteOperation):
(WebKit::NetworkCacheStorage::clear):
(WebKit::NetworkCacheStorage::shrinkIfNeeded):
(WebKit::NetworkCacheStorage::deleteOldVersions):

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181076 r181079  
     12015-03-05  Antti Koivisto  <antti@apple.com>
     2
     3        Switch NetworkCacheStorage to WorkQueue abstraction
     4        https://bugs.webkit.org/show_bug.cgi?id=142337
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Don't use dispatch_async directly.
     9
     10        * NetworkProcess/cache/NetworkCacheStorage.h:
     11        (WebKit::NetworkCacheStorage::ioQueue):
     12        (WebKit::NetworkCacheStorage::backgroundIOQueue):
     13        * NetworkProcess/cache/NetworkCacheStorageCocoa.mm:
     14        (WebKit::NetworkCacheStorage::NetworkCacheStorage):
     15        (WebKit::NetworkCacheStorage::initialize):
     16        (WebKit::NetworkCacheStorage::removeEntry):
     17        (WebKit::NetworkCacheStorage::dispatchReadOperation):
     18        (WebKit::retrieveFromMemory):
     19        (WebKit::NetworkCacheStorage::traverse):
     20        (WebKit::NetworkCacheStorage::dispatchFullWriteOperation):
     21        (WebKit::NetworkCacheStorage::dispatchHeaderWriteOperation):
     22        (WebKit::NetworkCacheStorage::clear):
     23        (WebKit::NetworkCacheStorage::shrinkIfNeeded):
     24        (WebKit::NetworkCacheStorage::deleteOldVersions):
     25
    1262015-03-05  Lukasz Bialek  <l.bialek@samsung.com>
    227
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r181020 r181079  
    3535#include <wtf/HashSet.h>
    3636#include <wtf/Optional.h>
     37#include <wtf/WorkQueue.h>
    3738#include <wtf/text/WTFString.h>
    3839
     
    103104    void dispatchPendingWriteOperations();
    104105
     106    WorkQueue& ioQueue() { return m_ioQueue.get(); }
     107    WorkQueue& backgroundIOQueue() { return m_backgroundIOQueue.get(); }
     108
    105109    const String m_baseDirectoryPath;
    106110    const String m_directoryPath;
     
    119123    HashSet<std::unique_ptr<const WriteOperation>> m_activeWriteOperations;
    120124
    121 #if PLATFORM(COCOA)
    122     mutable DispatchPtr<dispatch_queue_t> m_ioQueue;
    123     mutable DispatchPtr<dispatch_queue_t> m_backgroundIOQueue;
    124 #endif
     125    Ref<WorkQueue> m_ioQueue;
     126    Ref<WorkQueue> m_backgroundIOQueue;
    125127};
    126128
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorageCocoa.mm

    r181020 r181079  
    7070    : m_baseDirectoryPath(baseDirectoryPath)
    7171    , m_directoryPath(makeVersionedDirectoryPath(baseDirectoryPath))
    72     , m_ioQueue(adoptDispatch(dispatch_queue_create("com.apple.WebKit.Cache.Storage", DISPATCH_QUEUE_CONCURRENT)))
    73     , m_backgroundIOQueue(adoptDispatch(dispatch_queue_create("com.apple.WebKit.Cache.Storage.Background", DISPATCH_QUEUE_CONCURRENT)))
    74 {
    75     dispatch_set_target_queue(m_backgroundIOQueue.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
    76 
     72    , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
     73    , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
     74{
    7775    deleteOldVersions();
    7876    initialize();
     
    8583    StringCapture cachePathCapture(m_directoryPath);
    8684
    87     dispatch_async(m_backgroundIOQueue.get(), [this, cachePathCapture] {
     85    backgroundIOQueue().dispatch([this, cachePathCapture] {
    8886        String cachePath = cachePathCapture.string();
    8987        traverseCacheFiles(cachePath, [this](const String& fileName, const String& partitionPath) {
     
    9290                return;
    9391            unsigned shortHash = NetworkCacheKey::toShortHash(hash);
    94             dispatch_async(dispatch_get_main_queue(), [this, shortHash] {
     92            RunLoop::main().dispatch([this, shortHash] {
    9593                m_contentsFilter.add(shortHash);
    9694            });
     
    293291
    294292    StringCapture filePathCapture(filePathForKey(key, m_directoryPath));
    295     dispatch_async(m_backgroundIOQueue.get(), [this, filePathCapture] {
     293    backgroundIOQueue().dispatch([this, filePathCapture] {
    296294        WebCore::deleteFile(filePathCapture.string());
    297295    });
     
    304302
    305303    StringCapture cachePathCapture(m_directoryPath);
    306     dispatch_async(m_ioQueue.get(), [this, &read, cachePathCapture] {
     304    ioQueue().dispatch([this, &read, cachePathCapture] {
    307305        auto channel = openFileForKey(read.key, NetworkCacheIOChannel::Type::Read, cachePathCapture.string());
    308306        int fd = channel->fileDescriptor();
    309 
    310307        channel->read(0, std::numeric_limits<size_t>::max(), [this, &read, fd](NetworkCacheData& fileData, int error) {
    311308            if (error) {
     
    355352            LOG(NetworkCacheStorage, "(NetworkProcess) found write operation in progress");
    356353            auto entry = operation->entry;
    357             dispatch_async(dispatch_get_main_queue(), [entry, completionHandler] {
     354            RunLoop::main().dispatch([entry, completionHandler] {
    358355                completionHandler(std::make_unique<NetworkCacheStorage::Entry>(entry));
    359356            });
     
    426423{
    427424    StringCapture cachePathCapture(m_directoryPath);
    428     dispatch_async(m_ioQueue.get(), [this, cachePathCapture, traverseHandler] {
     425    ioQueue().dispatch([this, cachePathCapture, traverseHandler] {
    429426        String cachePath = cachePathCapture.string();
    430427        auto semaphore = adoptDispatch(dispatch_semaphore_create(0));
     
    444441            dispatch_semaphore_wait(semaphore.get(), DISPATCH_TIME_FOREVER);
    445442        });
    446         dispatch_async(dispatch_get_main_queue(), [this, traverseHandler] {
     443        RunLoop::main().dispatch([this, traverseHandler] {
    447444            traverseHandler(nullptr);
    448445        });
     
    482479
    483480    StringCapture cachePathCapture(m_directoryPath);
    484     dispatch_async(m_backgroundIOQueue.get(), [this, &write, cachePathCapture] {
     481    backgroundIOQueue().dispatch([this, &write, cachePathCapture] {
    485482        auto encodedHeader = encodeEntryHeader(write.entry);
    486483        auto headerAndBodyData = adoptDispatch(dispatch_data_create_concat(encodedHeader.dispatchData(), write.entry.body.dispatchData()));
     
    527524    // Try to update the header of an existing entry.
    528525    StringCapture cachePathCapture(m_directoryPath);
    529     dispatch_async(m_backgroundIOQueue.get(), [this, &write, cachePathCapture] {
     526    backgroundIOQueue().dispatch([this, &write, cachePathCapture] {
    530527        auto headerData = encodeEntryHeader(write.entry);
    531528        auto existingHeaderData = encodeEntryHeader(write.existingEntry.value());
     
    534531        if (pageRoundedHeaderSizeChanged) {
    535532            LOG(NetworkCacheStorage, "(NetworkProcess) page-rounded header size changed, storing full entry");
    536             dispatch_async(dispatch_get_main_queue(), [this, &write] {
     533            RunLoop::main().dispatch([this, &write] {
    537534                dispatchFullWriteOperation(write);
    538535            });
     
    574571    StringCapture directoryPathCapture(m_directoryPath);
    575572
    576     dispatch_async(m_ioQueue.get(), [directoryPathCapture] {
     573    ioQueue().dispatch([directoryPathCapture] {
    577574        String directoryPath = directoryPathCapture.string();
    578575        traverseDirectory(directoryPath, DT_DIR, [&directoryPath](const String& subdirName) {
     
    603600
    604601    StringCapture cachePathCapture(m_directoryPath);
    605     dispatch_async(m_backgroundIOQueue.get(), [this, cachePathCapture] {
     602    backgroundIOQueue().dispatch([this, cachePathCapture] {
    606603        String cachePath = cachePathCapture.string();
    607604        traverseCacheFiles(cachePath, [this](const String& fileName, const String& partitionPath) {
     
    621618                return;
    622619            unsigned shortHash = NetworkCacheKey::toShortHash(hash);
    623             dispatch_async(dispatch_get_main_queue(), [this, shortHash] {
     620            RunLoop::main().dispatch([this, shortHash] {
    624621                if (m_contentsFilter.mayContain(shortHash))
    625622                    m_contentsFilter.remove(shortHash);
     
    643640    // Delete V1 cache.
    644641    StringCapture cachePathCapture(m_baseDirectoryPath);
    645     dispatch_async(m_backgroundIOQueue.get(), [cachePathCapture] {
     642    backgroundIOQueue().dispatch([cachePathCapture] {
    646643        String cachePath = cachePathCapture.string();
    647644        traverseDirectory(cachePath, DT_DIR, [&cachePath](const String& subdirName) {
Note: See TracChangeset for help on using the changeset viewer.