Title: [205325] trunk/Source/WTF
- Revision
- 205325
- Author
- [email protected]
- Date
- 2016-09-01 15:45:52 -0700 (Thu, 01 Sep 2016)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (205324 => 205325)
--- trunk/Source/WTF/ChangeLog 2016-09-01 22:34:27 UTC (rev 205324)
+++ trunk/Source/WTF/ChangeLog 2016-09-01 22:45:52 UTC (rev 205325)
@@ -1,5 +1,20 @@
2016-09-01 Anders Carlsson <[email protected]>
+ 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):
+
+2016-09-01 Anders Carlsson <[email protected]>
+
add BlockPtr::fromCallable
https://bugs.webkit.org/show_bug.cgi?id=161504
Modified: trunk/Source/WTF/wtf/BlockPtr.h (205324 => 205325)
--- trunk/Source/WTF/wtf/BlockPtr.h 2016-09-01 22:34:27 UTC (rev 205324)
+++ trunk/Source/WTF/wtf/BlockPtr.h 2016-09-01 22:45:52 UTC (rev 205325)
@@ -90,7 +90,7 @@
new (&block->f) F { std::move(function) };
BlockPtr blockPtr;
- blockPtr.m_block = static_cast<BlockType>(block);
+ blockPtr.m_block = reinterpret_cast<BlockType>(block);
return blockPtr;
}
Modified: trunk/Source/WTF/wtf/Function.h (205324 => 205325)
--- trunk/Source/WTF/wtf/Function.h 2016-09-01 22:34:27 UTC (rev 205324)
+++ trunk/Source/WTF/wtf/Function.h 2016-09-01 22:45:52 UTC (rev 205325)
@@ -66,6 +66,7 @@
return *this;
}
+private:
class CallableWrapperBase {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -74,19 +75,6 @@
virtual Out call(In...) = 0;
};
- CallableWrapperBase* leakCallable() WARN_UNUSED_RETURN
- {
- return m_callableWrapper.release();
- }
-
- static Function adoptCallable(CallableWrapperBase* callable)
- {
- Function function;
- function.m_callableWrapper.reset(callable);
- return function;
- }
-
-private:
template<typename CallableType>
class CallableWrapper : public CallableWrapperBase {
public:
Modified: trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp (205324 => 205325)
--- trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp 2016-09-01 22:34:27 UTC (rev 205324)
+++ trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp 2016-09-01 22:45:52 UTC (rev 205325)
@@ -25,29 +25,23 @@
#include "config.h"
#include "WorkQueue.h"
+#include "BlockPtr.h"
+#include "Ref.h"
namespace WTF {
void WorkQueue::dispatch(Function<void ()>&& function)
{
- ref();
- auto* callable = function.leakCallable();
- dispatch_async(m_dispatchQueue, ^{
- auto function = Function<void ()>::adoptCallable(callable);
+ dispatch_async(m_dispatchQueue, BlockPtr<void ()>::fromCallable([protectedThis = makeRef(*this), function = WTFMove(function)] {
function();
- deref();
- });
+ }).get());
}
void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, Function<void ()>&& function)
{
- ref();
- auto* callable = function.leakCallable();
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, ^{
- auto function = Function<void ()>::adoptCallable(callable);
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, BlockPtr<void ()>::fromCallable([protectedThis = makeRef(*this), function = WTFMove(function)] {
function();
- deref();
- });
+ }).get());
}
#if HAVE(QOS_CLASSES)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes