Changeset 205325 in webkit


Ignore:
Timestamp:
Sep 1, 2016 3:45:52 PM (8 years ago)
Author:
andersca@apple.com
Message:

Use BlockPtr::fromCallable in WorkQueue::dispatch and WorkQueue::dispatchAfter
https://bugs.webkit.org/show_bug.cgi?id=161512

Reviewed by Chris Dumez.

This lets us get rid of leakCallable and adoptCallable.

  • wtf/BlockPtr.h:
  • wtf/Function.h:
  • wtf/cocoa/WorkQueueCocoa.cpp:

(WTF::WorkQueue::dispatch):
(WTF::WorkQueue::dispatchAfter):

Location:
trunk/Source/WTF
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r205313 r205325  
     12016-09-01  Anders Carlsson  <andersca@apple.com>
     2
     3        Use BlockPtr::fromCallable in WorkQueue::dispatch and WorkQueue::dispatchAfter
     4        https://bugs.webkit.org/show_bug.cgi?id=161512
     5
     6        Reviewed by Chris Dumez.
     7
     8        This lets us get rid of leakCallable and adoptCallable.
     9
     10        * wtf/BlockPtr.h:
     11        * wtf/Function.h:
     12        * wtf/cocoa/WorkQueueCocoa.cpp:
     13        (WTF::WorkQueue::dispatch):
     14        (WTF::WorkQueue::dispatchAfter):
     15
    1162016-09-01  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/Source/WTF/wtf/BlockPtr.h

    r205313 r205325  
    9191
    9292        BlockPtr blockPtr;
    93         blockPtr.m_block = static_cast<BlockType>(block);
     93        blockPtr.m_block = reinterpret_cast<BlockType>(block);
    9494
    9595        return blockPtr;
  • trunk/Source/WTF/wtf/Function.h

    r203236 r205325  
    6767    }
    6868
     69private:
    6970    class CallableWrapperBase {
    7071        WTF_MAKE_FAST_ALLOCATED;
     
    7576    };
    7677
    77     CallableWrapperBase* leakCallable() WARN_UNUSED_RETURN
    78     {
    79         return m_callableWrapper.release();
    80     }
    81 
    82     static Function adoptCallable(CallableWrapperBase* callable)
    83     {
    84         Function function;
    85         function.m_callableWrapper.reset(callable);
    86         return function;
    87     }
    88 
    89 private:
    9078    template<typename CallableType>
    9179    class CallableWrapper : public CallableWrapperBase {
  • trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp

    r203236 r205325  
    2626#include "config.h"
    2727#include "WorkQueue.h"
     28#include "BlockPtr.h"
     29#include "Ref.h"
    2830
    2931namespace WTF {
     
    3133void WorkQueue::dispatch(Function<void ()>&& function)
    3234{
    33     ref();
    34     auto* callable = function.leakCallable();
    35     dispatch_async(m_dispatchQueue, ^{
    36         auto function = Function<void ()>::adoptCallable(callable);
     35    dispatch_async(m_dispatchQueue, BlockPtr<void ()>::fromCallable([protectedThis = makeRef(*this), function = WTFMove(function)] {
    3736        function();
    38         deref();
    39     });
     37    }).get());
    4038}
    4139
    4240void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, Function<void ()>&& function)
    4341{
    44     ref();
    45     auto* callable = function.leakCallable();
    46     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, ^{
    47         auto function = Function<void ()>::adoptCallable(callable);
     42    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, BlockPtr<void ()>::fromCallable([protectedThis = makeRef(*this), function = WTFMove(function)] {
    4843        function();
    49         deref();
    50     });
     44    }).get());
    5145}
    5246
Note: See TracChangeset for help on using the changeset viewer.