Skip to content
Permalink
Browse files
Transition various Task/Function queues from std::function to Noncopy…
…ableFunction.

https://bugs.webkit.org/show_bug.cgi?id=158196

Reviewed by Chris Dumez.

No new tests (Refactor, no behavior change).

* dom/ActiveDOMCallbackMicrotask.cpp:
(WebCore::ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask):
* dom/ActiveDOMCallbackMicrotask.h:

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::layoutSizeChanged):

* page/FrameView.cpp:
(WebCore::FrameView::queuePostLayoutCallback):
(WebCore::FrameView::flushPostLayoutTasksQueue):
* page/FrameView.h:

* platform/GenericTaskQueue.cpp:
(WebCore::TaskDispatcher<Timer>::postTask):
(WebCore::TaskDispatcher<Timer>::dispatchOneTask):
* platform/GenericTaskQueue.h:
(WebCore::TaskDispatcher::postTask):
(WebCore::GenericTaskQueue::enqueueTask):

* style/StyleTreeResolver.cpp:
(WebCore::Style::postResolutionCallbackQueue):
(WebCore::Style::queuePostResolutionCallback):
(WebCore::Style::suspendMemoryCacheClientCalls):
* style/StyleTreeResolver.h:


Canonical link: https://commits.webkit.org/176297@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201497 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
beidson committed May 30, 2016
1 parent 00add3e commit 2d00daf1d7280271cc5c3409fc907d46d200264c
Showing 10 changed files with 73 additions and 51 deletions.
@@ -1,3 +1,37 @@
2016-05-29 Brady Eidson <beidson@apple.com>

Transition various Task/Function queues from std::function to NoncopyableFunction.
https://bugs.webkit.org/show_bug.cgi?id=158196

Reviewed by Chris Dumez.

No new tests (Refactor, no behavior change).

* dom/ActiveDOMCallbackMicrotask.cpp:
(WebCore::ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask):
* dom/ActiveDOMCallbackMicrotask.h:

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::layoutSizeChanged):

* page/FrameView.cpp:
(WebCore::FrameView::queuePostLayoutCallback):
(WebCore::FrameView::flushPostLayoutTasksQueue):
* page/FrameView.h:

* platform/GenericTaskQueue.cpp:
(WebCore::TaskDispatcher<Timer>::postTask):
(WebCore::TaskDispatcher<Timer>::dispatchOneTask):
* platform/GenericTaskQueue.h:
(WebCore::TaskDispatcher::postTask):
(WebCore::GenericTaskQueue::enqueueTask):

* style/StyleTreeResolver.cpp:
(WebCore::Style::postResolutionCallbackQueue):
(WebCore::Style::queuePostResolutionCallback):
(WebCore::Style::suspendMemoryCacheClientCalls):
* style/StyleTreeResolver.h:

2016-05-29 Brady Eidson <beidson@apple.com>

Make ScriptExecutionContext::Task work in terms of wtf::NoncopyableFunction instead of std::function.
@@ -28,7 +28,7 @@

namespace WebCore {

ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask(MicrotaskQueue& queue, ScriptExecutionContext& scriptExecutionContext, std::function<void()>&& task)
ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask(MicrotaskQueue& queue, ScriptExecutionContext& scriptExecutionContext, NoncopyableFunction<void()>&& task)
: ActiveDOMCallback(&scriptExecutionContext)
, m_queue(queue)
, m_task(WTFMove(task))
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
* Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,19 +23,18 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef ActiveDOMCallbackMicrotask_h
#define ActiveDOMCallbackMicrotask_h
#pragma once

#include "ActiveDOMCallback.h"
#include "Microtasks.h"
#include <functional>
#include <wtf/NoncopyableFunction.h>

namespace WebCore {

class ActiveDOMCallbackMicrotask final : public Microtask, public ActiveDOMCallback {
WTF_MAKE_FAST_ALLOCATED;
public:
WEBCORE_EXPORT ActiveDOMCallbackMicrotask(MicrotaskQueue&, ScriptExecutionContext&, std::function<void()>&&);
WEBCORE_EXPORT ActiveDOMCallbackMicrotask(MicrotaskQueue&, ScriptExecutionContext&, NoncopyableFunction<void()>&&);
WEBCORE_EXPORT virtual ~ActiveDOMCallbackMicrotask();

Result run() override;
@@ -47,9 +46,7 @@ class ActiveDOMCallbackMicrotask final : public Microtask, public ActiveDOMCallb
// be accessed via the ScriptExecutionContext, which should hold a reference to the relevent
// queue.
MicrotaskQueue& m_queue;
std::function<void()> m_task;
NoncopyableFunction<void()> m_task;
};

} // namespace WebCore

#endif // ActiveDOMCallbackMicrotask_h
@@ -3994,12 +3994,11 @@ void HTMLMediaElement::updateCaptionContainer()
void HTMLMediaElement::layoutSizeChanged()
{
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
RefPtr<HTMLMediaElement> strongThis = this;
std::function<void()> task = [strongThis] {
if (ShadowRoot* root = strongThis->userAgentShadowRoot())
auto task = [this, protectedThis = Ref<Element>(*this)] {
if (ShadowRoot* root = userAgentShadowRoot())
root->dispatchEvent(Event::create("resize", false, false));
};
m_resizeTaskQueue.enqueueTask(task);
m_resizeTaskQueue.enqueueTask(WTFMove(task));
#endif
}

@@ -3133,9 +3133,9 @@ void FrameView::flushAnyPendingPostLayoutTasks()
updateEmbeddedObjectsTimerFired();
}

void FrameView::queuePostLayoutCallback(std::function<void()> callback)
void FrameView::queuePostLayoutCallback(NoncopyableFunction<void()>&& callback)
{
m_postLayoutCallbackQueue.append(callback);
m_postLayoutCallbackQueue.append(WTFMove(callback));
}

void FrameView::flushPostLayoutTasksQueue()
@@ -3146,10 +3146,9 @@ void FrameView::flushPostLayoutTasksQueue()
if (!m_postLayoutCallbackQueue.size())
return;

const auto queue = m_postLayoutCallbackQueue;
m_postLayoutCallbackQueue.clear();
for (size_t i = 0; i < queue.size(); ++i)
queue[i]();
Vector<NoncopyableFunction<void()>> queue = WTFMove(m_postLayoutCallbackQueue);
for (auto& task : queue)
task();
}

void FrameView::performPostLayoutTasks()
@@ -4,7 +4,7 @@
(C) 1998, 1999 Torben Weis (weis@kde.org)
(C) 1999 Lars Knoll (knoll@kde.org)
(C) 1999 Antti Koivisto (koivisto@kde.org)
Copyright (C) 2004-2009, 2014-2015 Apple Inc. All rights reserved.
Copyright (C) 2004-2009, 2014-2016 Apple Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -22,8 +22,7 @@
Boston, MA 02110-1301, USA.
*/

#ifndef FrameView_h
#define FrameView_h
#pragma once

#include "AdjustViewSizeOrNot.h"
#include "Color.h"
@@ -38,6 +37,7 @@
#include <wtf/Forward.h>
#include <wtf/HashSet.h>
#include <wtf/ListHashSet.h>
#include <wtf/NoncopyableFunction.h>
#include <wtf/text/WTFString.h>

namespace WebCore {
@@ -111,7 +111,7 @@ class FrameView final : public ScrollView {
void scheduleRelayout();
void scheduleRelayoutOfSubtree(RenderElement&);
void unscheduleRelayout();
void queuePostLayoutCallback(std::function<void()>);
void queuePostLayoutCallback(NoncopyableFunction<void()>&&);
bool layoutPending() const;
bool isInLayout() const { return m_layoutPhase != OutsideLayout; }
bool isInRenderTreeLayout() const { return m_layoutPhase == InRenderTreeLayout; }
@@ -828,7 +828,7 @@ class FrameView final : public ScrollView {
ScrollPinningBehavior m_scrollPinningBehavior;

IntRect* m_cachedWindowClipRect { nullptr };
Vector<std::function<void()>> m_postLayoutCallbackQueue;
Vector<NoncopyableFunction<void()>> m_postLayoutCallbackQueue;
};

inline void FrameView::incrementVisuallyNonEmptyCharacterCount(unsigned count)
@@ -854,5 +854,3 @@ inline void FrameView::incrementVisuallyNonEmptyPixelCount(const IntSize& size)
} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_WIDGET(FrameView, isFrameView())

#endif // FrameView_h
@@ -36,7 +36,7 @@ TaskDispatcher<Timer>::TaskDispatcher()
{
}

void TaskDispatcher<Timer>::postTask(std::function<void()> function)
void TaskDispatcher<Timer>::postTask(NoncopyableFunction<void()>&& function)
{
m_pendingTasks.append(WTFMove(function));
pendingDispatchers().append(m_weakPtrFactory.createWeakPtr());
@@ -77,7 +77,7 @@ Deque<WeakPtr<TaskDispatcher<Timer>>>& TaskDispatcher<Timer>::pendingDispatchers
void TaskDispatcher<Timer>::dispatchOneTask()
{
ASSERT(!m_pendingTasks.isEmpty());
std::function<void()> task = m_pendingTasks.takeFirst();
auto task = m_pendingTasks.takeFirst();
task();
}

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
* Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,11 +23,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GenericTaskQueue_h
#define GenericTaskQueue_h
#pragma once

#include "Timer.h"
#include <wtf/Deque.h>
#include <wtf/NoncopyableFunction.h>
#include <wtf/WeakPtr.h>

namespace WebCore {
@@ -40,9 +40,9 @@ class TaskDispatcher {
{
}

void postTask(std::function<void()> f)
void postTask(NoncopyableFunction<void()>&& f)
{
m_context.postTask(f);
m_context.postTask(WTFMove(f));
}

private:
@@ -53,7 +53,7 @@ template<>
class TaskDispatcher<Timer> {
public:
TaskDispatcher();
void postTask(std::function<void()>);
void postTask(NoncopyableFunction<void()>&&);

private:
static Timer& sharedTimer();
@@ -63,7 +63,7 @@ class TaskDispatcher<Timer> {
void dispatchOneTask();

WeakPtrFactory<TaskDispatcher> m_weakPtrFactory;
Deque<std::function<void()>> m_pendingTasks;
Deque<NoncopyableFunction<void()>> m_pendingTasks;
};

template <typename T>
@@ -81,16 +81,16 @@ class GenericTaskQueue {
{
}

typedef std::function<void()> TaskFunction;
typedef NoncopyableFunction<void()> TaskFunction;

void enqueueTask(TaskFunction task)
void enqueueTask(TaskFunction&& task)
{
if (m_isClosed)
return;

++m_pendingTasks;
auto weakThis = m_weakPtrFactory.createWeakPtr();
m_dispatcher.postTask([weakThis, task] {
m_dispatcher.postTask([weakThis, task = WTFMove(task)] {
if (!weakThis)
return;
ASSERT(weakThis->m_pendingTasks);
@@ -120,5 +120,3 @@ class GenericTaskQueue {
};

}

#endif
@@ -521,15 +521,15 @@ std::unique_ptr<Update> TreeResolver::resolve(Change change)
return WTFMove(m_update);
}

static Vector<std::function<void ()>>& postResolutionCallbackQueue()
static Vector<NoncopyableFunction<void ()>>& postResolutionCallbackQueue()
{
static NeverDestroyed<Vector<std::function<void ()>>> vector;
static NeverDestroyed<Vector<NoncopyableFunction<void ()>>> vector;
return vector;
}

void queuePostResolutionCallback(std::function<void ()> callback)
void queuePostResolutionCallback(NoncopyableFunction<void ()>&& callback)
{
postResolutionCallbackQueue().append(callback);
postResolutionCallbackQueue().append(WTFMove(callback));
}

static void suspendMemoryCacheClientCalls(Document& document)
@@ -540,8 +540,7 @@ static void suspendMemoryCacheClientCalls(Document& document)

page->setMemoryCacheClientCallsEnabled(false);

RefPtr<MainFrame> protectedMainFrame = &page->mainFrame();
postResolutionCallbackQueue().append([protectedMainFrame]{
postResolutionCallbackQueue().append([protectedMainFrame = Ref<MainFrame>(page->mainFrame())] {
if (Page* page = protectedMainFrame->page())
page->setMemoryCacheClientCallsEnabled(true);
});
@@ -23,8 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef StyleTreeResolver_h
#define StyleTreeResolver_h
#pragma once

#include "RenderStyleConstants.h"
#include "RenderTreePosition.h"
@@ -35,6 +34,7 @@
#include "StyleUpdate.h"
#include <functional>
#include <wtf/HashMap.h>
#include <wtf/NoncopyableFunction.h>
#include <wtf/RefPtr.h>

namespace WebCore {
@@ -110,7 +110,7 @@ class TreeResolver {
std::unique_ptr<Update> m_update;
};

void queuePostResolutionCallback(std::function<void ()>);
void queuePostResolutionCallback(NoncopyableFunction<void ()>&&);
bool postResolutionCallbacksAreSuspended();

bool isPlaceholderStyle(const RenderStyle&);
@@ -124,5 +124,3 @@ class PostResolutionCallbackDisabler {
}

}

#endif

0 comments on commit 2d00daf

Please sign in to comment.