Commit c253c446 authored by andersca@apple.com's avatar andersca@apple.com

Change callOnMainThread to take an std::function

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

Reviewed by Darin Adler.

This will let us pass anything that can be converted to an std::function (including lambdas and
WTF::Function objects) to callOnMainThread.

* wtf/MainThread.cpp:
(WTF::callOnMainThread):
* wtf/MainThread.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157374 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e9c90169
2013-10-12 Anders Carlsson <andersca@apple.com>
Change callOnMainThread to take an std::function
https://bugs.webkit.org/show_bug.cgi?id=122698
Reviewed by Darin Adler.
This will let us pass anything that can be converted to an std::function (including lambdas and
WTF::Function objects) to callOnMainThread.
* wtf/MainThread.cpp:
(WTF::callOnMainThread):
* wtf/MainThread.h:
2013-09-06 Jessica Pease <jessica_n_pease@apple.com>
Replace bounds checking ASSERTs with ASSERT_WITH_SECURITY_IMPLICATION
......
......@@ -232,14 +232,13 @@ void cancelCallOnMainThread(MainThreadFunction* function, void* context)
static void callFunctionObject(void* context)
{
Function<void ()>* function = static_cast<Function<void ()>*>(context);
auto function = std::unique_ptr<std::function<void ()>>(static_cast<std::function<void ()>*>(context));
(*function)();
delete function;
}
void callOnMainThread(const Function<void ()>& function)
void callOnMainThread(std::function<void ()> function)
{
callOnMainThread(callFunctionObject, new Function<void ()>(function));
callOnMainThread(callFunctionObject, std::make_unique<std::function<void ()>>(std::move(function)).release());
}
void setMainThreadCallbacksPaused(bool paused)
......
......@@ -30,6 +30,7 @@
#ifndef MainThread_h
#define MainThread_h
#include <functional>
#include <stdint.h>
namespace WTF {
......@@ -44,9 +45,8 @@ WTF_EXPORT_PRIVATE void callOnMainThread(MainThreadFunction*, void* context);
WTF_EXPORT_PRIVATE void callOnMainThreadAndWait(MainThreadFunction*, void* context);
WTF_EXPORT_PRIVATE void cancelCallOnMainThread(MainThreadFunction*, void* context);
template<typename> class Function;
WTF_EXPORT_PRIVATE void callOnMainThread(const Function<void ()>&);
WTF_EXPORT_PRIVATE void callOnMainThread(std::function<void ()>);
WTF_EXPORT_PRIVATE void setMainThreadCallbacksPaused(bool paused);
WTF_EXPORT_PRIVATE bool isMainThread();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment