⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243979 in webkit


Ignore:
Timestamp:
Apr 8, 2019, 3:14:32 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r242266 - [ThreadedCompositor] Simply the compositing run loop worker thread
https://bugs.webkit.org/show_bug.cgi?id=195208

Patch by Carlos Garcia Campos <cgarcia@igalia.com> on 2019-03-01
Reviewed by Don Olmstead.

We can remove the WorkQueuePool, since we never really supported more than one thread, and now that single
process model non longer exists it doesn't even make sense. We can simply use a RunLoop instead of a WorkQueue
so that the implementation is not specific to the generic WorkQueue implementation.

  • Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:

(WebKit::createRunLoop): Helper function to create the RunLoop in a worker thread before m_updateTimer is initialized.
(WebKit::CompositingRunLoop::CompositingRunLoop): Use createRunLoop().
(WebKit::CompositingRunLoop::~CompositingRunLoop): Stop the worker thread run loop in the next main run loop iteration.
(WebKit::CompositingRunLoop::performTask): Use m_runLoop.
(WebKit::CompositingRunLoop::performTaskSync): Ditto.
(WebKit::WorkQueuePool::singleton): Deleted.
(WebKit::WorkQueuePool::dispatch): Deleted.
(WebKit::WorkQueuePool::runLoop): Deleted.
(WebKit::WorkQueuePool::invalidate): Deleted.
(WebKit::WorkQueuePool::WorkQueuePool): Deleted.
(WebKit::WorkQueuePool::getOrCreateWorkQueueForContext): Deleted.
(): Deleted.

  • Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h:
Location:
releases/WebKitGTK/webkit-2.24/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog

    r243973 r243979  
     12019-03-01  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [ThreadedCompositor] Simply the compositing run loop worker thread
     4        https://bugs.webkit.org/show_bug.cgi?id=195208
     5
     6        Reviewed by Don Olmstead.
     7
     8        We can remove the WorkQueuePool, since we never really supported more than one thread, and now that single
     9        process model non longer exists it doesn't even make sense. We can simply use a RunLoop instead of a WorkQueue
     10        so that the implementation is not specific to the generic WorkQueue implementation.
     11
     12        * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:
     13        (WebKit::createRunLoop): Helper function to create the RunLoop in a worker thread before m_updateTimer is initialized.
     14        (WebKit::CompositingRunLoop::CompositingRunLoop): Use createRunLoop().
     15        (WebKit::CompositingRunLoop::~CompositingRunLoop): Stop the worker thread run loop in the next main run loop iteration.
     16        (WebKit::CompositingRunLoop::performTask): Use m_runLoop.
     17        (WebKit::CompositingRunLoop::performTaskSync): Ditto.
     18        (WebKit::WorkQueuePool::singleton): Deleted.
     19        (WebKit::WorkQueuePool::dispatch): Deleted.
     20        (WebKit::WorkQueuePool::runLoop): Deleted.
     21        (WebKit::WorkQueuePool::invalidate): Deleted.
     22        (WebKit::WorkQueuePool::WorkQueuePool): Deleted.
     23        (WebKit::WorkQueuePool::getOrCreateWorkQueueForContext): Deleted.
     24        (): Deleted.
     25        * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h:
     26
    1272019-03-25  Carlos Garcia Campos  <cgarcia@igalia.com>
    228
  • releases/WebKitGTK/webkit-2.24/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp

    r229195 r243979  
    3131#include <wtf/HashMap.h>
    3232#include <wtf/MainThread.h>
    33 #include <wtf/NeverDestroyed.h>
    34 #include <wtf/WorkQueue.h>
     33#include <wtf/Threading.h>
     34#include <wtf/threads/BinarySemaphore.h>
    3535
    3636#if USE(GLIB_EVENT_LOOP)
     
    4040namespace WebKit {
    4141
    42 class WorkQueuePool {
    43     WTF_MAKE_NONCOPYABLE(WorkQueuePool);
    44     friend NeverDestroyed<WorkQueuePool>;
    45 public:
    46     static WorkQueuePool& singleton()
    47     {
    48         ASSERT(RunLoop::isMain());
    49         static NeverDestroyed<WorkQueuePool> workQueuePool;
    50         return workQueuePool;
    51     }
    52 
    53     void dispatch(void* context, Function<void ()>&& function)
    54     {
    55         ASSERT(RunLoop::isMain());
    56         getOrCreateWorkQueueForContext(context).dispatch(WTFMove(function));
    57     }
    58 
    59     RunLoop& runLoop(void* context)
    60     {
    61         return getOrCreateWorkQueueForContext(context).runLoop();
    62     }
    63 
    64     void invalidate(void* context)
    65     {
    66         auto workQueue = m_workQueueMap.take(context);
    67         ASSERT(workQueue);
    68         if (m_workQueueMap.isEmpty()) {
    69             m_sharedWorkQueue = nullptr;
    70             m_threadCount = 0;
    71         } else if (workQueue->hasOneRef())
    72             m_threadCount--;
    73     }
    74 
    75 private:
    76     WorkQueuePool()
    77     {
    78         // FIXME: This is a sane default limit, but it should be configurable somehow.
    79         m_threadCountLimit = 1;
    80     }
    81 
    82     WorkQueue& getOrCreateWorkQueueForContext(void* context)
    83     {
    84         auto addResult = m_workQueueMap.add(context, nullptr);
    85         if (addResult.isNewEntry) {
    86             // FIXME: This is OK for now, and it works for a single-thread limit. But for configurations where more (but not unlimited)
    87             // threads could be used, one option would be to use a HashSet here and disperse the contexts across the available threads.
    88             if (m_threadCount >= m_threadCountLimit) {
    89                 ASSERT(m_sharedWorkQueue);
    90                 addResult.iterator->value = m_sharedWorkQueue;
    91             } else {
    92                 addResult.iterator->value = WorkQueue::create("org.webkit.ThreadedCompositorWorkQueue");
    93                 if (!m_threadCount)
    94                     m_sharedWorkQueue = addResult.iterator->value;
    95                 m_threadCount++;
    96             }
    97         }
    98 
    99         return *addResult.iterator->value;
    100     }
    101 
    102     HashMap<void*, RefPtr<WorkQueue>> m_workQueueMap;
    103     RefPtr<WorkQueue> m_sharedWorkQueue;
    104     unsigned m_threadCount { 0 };
    105     unsigned m_threadCountLimit;
    106 };
     42static RunLoop* createRunLoop()
     43{
     44    RunLoop* runLoop = nullptr;
     45    BinarySemaphore semaphore;
     46    Thread::create("org.webkit.ThreadedCompositor", [&] {
     47        runLoop = &RunLoop::current();
     48        semaphore.signal();
     49        runLoop->run();
     50    })->detach();
     51    semaphore.wait();
     52
     53    return runLoop;
     54}
    10755
    10856CompositingRunLoop::CompositingRunLoop(Function<void ()>&& updateFunction)
    109     : m_updateTimer(WorkQueuePool::singleton().runLoop(this), this, &CompositingRunLoop::updateTimerFired)
     57    : m_runLoop(createRunLoop())
     58    , m_updateTimer(*m_runLoop, this, &CompositingRunLoop::updateTimerFired)
    11059    , m_updateFunction(WTFMove(updateFunction))
    11160{
     
    11968{
    12069    ASSERT(RunLoop::isMain());
    121     // Make sure the WorkQueue is deleted after the CompositingRunLoop, because m_updateTimer has a reference
    122     // of the WorkQueue run loop. Passing this is not a problem because the pointer will only be used as a
    123     // HashMap key by WorkQueuePool.
    124     RunLoop::main().dispatch([context = this] { WorkQueuePool::singleton().invalidate(context); });
     70    // Make sure the RunLoop is stopped after the CompositingRunLoop, because m_updateTimer has a reference.
     71    RunLoop::main().dispatch([runLoop = makeRef(*m_runLoop)] {
     72        runLoop->stop();
     73        runLoop->dispatch([] {
     74            RunLoop::current().stop();
     75        });
     76    });
    12577}
    12678
     
    12880{
    12981    ASSERT(RunLoop::isMain());
    130     WorkQueuePool::singleton().dispatch(this, WTFMove(function));
     82    m_runLoop->dispatch(WTFMove(function));
    13183}
    13284
     
    13587    ASSERT(RunLoop::isMain());
    13688    LockHolder locker(m_dispatchSyncConditionMutex);
    137     WorkQueuePool::singleton().dispatch(this, [this, function = WTFMove(function)] {
     89    m_runLoop->dispatch([this, function = WTFMove(function)] {
    13890        function();
    13991        LockHolder locker(m_dispatchSyncConditionMutex);
  • releases/WebKitGTK/webkit-2.24/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h

    r220672 r243979  
    7272    void updateTimerFired();
    7373
     74    RunLoop* m_runLoop { nullptr };
    7475    RunLoop::Timer<CompositingRunLoop> m_updateTimer;
    7576    Function<void ()> m_updateFunction;
    7677    Lock m_dispatchSyncConditionMutex;
    7778    Condition m_dispatchSyncCondition;
    78 
    7979
    8080    struct {
Note: See TracChangeset for help on using the changeset viewer.