Changeset 157374 in webkit


Ignore:
Timestamp:
Oct 13, 2013 9:12:49 AM (11 years ago)
Author:
andersca@apple.com
Message:

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:
Location:
trunk/Source/WTF
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r157341 r157374  
     12013-10-12  Anders Carlsson  <andersca@apple.com>
     2
     3        Change callOnMainThread to take an std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=122698
     5
     6        Reviewed by Darin Adler.
     7
     8        This will let us pass anything that can be converted to an std::function (including lambdas and
     9        WTF::Function objects) to callOnMainThread.
     10
     11        * wtf/MainThread.cpp:
     12        (WTF::callOnMainThread):
     13        * wtf/MainThread.h:
     14
    1152013-09-06  Jessica Pease  <jessica_n_pease@apple.com>
    216
  • trunk/Source/WTF/wtf/MainThread.cpp

    r155926 r157374  
    233233static void callFunctionObject(void* context)
    234234{
    235     Function<void ()>* function = static_cast<Function<void ()>*>(context);
     235    auto function = std::unique_ptr<std::function<void ()>>(static_cast<std::function<void ()>*>(context));
    236236    (*function)();
    237     delete function;
    238 }
    239 
    240 void callOnMainThread(const Function<void ()>& function)
    241 {
    242     callOnMainThread(callFunctionObject, new Function<void ()>(function));
     237}
     238
     239void callOnMainThread(std::function<void ()> function)
     240{
     241    callOnMainThread(callFunctionObject, std::make_unique<std::function<void ()>>(std::move(function)).release());
    243242}
    244243
  • trunk/Source/WTF/wtf/MainThread.h

    r156127 r157374  
    3131#define MainThread_h
    3232
     33#include <functional>
    3334#include <stdint.h>
    3435
     
    4546WTF_EXPORT_PRIVATE void cancelCallOnMainThread(MainThreadFunction*, void* context);
    4647
    47 template<typename> class Function;
    48 WTF_EXPORT_PRIVATE void callOnMainThread(const Function<void ()>&);
    49    
     48WTF_EXPORT_PRIVATE void callOnMainThread(std::function<void ()>);
     49
    5050WTF_EXPORT_PRIVATE void setMainThreadCallbacksPaused(bool paused);
    5151
Note: See TracChangeset for help on using the changeset viewer.