Title: [217998] trunk/Source/WTF
- Revision
- 217998
- Author
- [email protected]
- Date
- 2017-06-09 10:54:16 -0700 (Fri, 09 Jun 2017)
Log Message
Update WorkQueue::concurrentApply() to take a WTF::Function instead of an std::function
https://bugs.webkit.org/show_bug.cgi?id=173165
Reviewed by Saam Barati.
Update WorkQueue::concurrentApply() to take a WTF::Function instead of an std::function
as std::function has issues with regards to thread safety.
* wtf/WorkQueue.h:
* wtf/cocoa/WorkQueueCocoa.cpp:
(WTF::WorkQueue::concurrentApply):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (217997 => 217998)
--- trunk/Source/WTF/ChangeLog 2017-06-09 17:52:42 UTC (rev 217997)
+++ trunk/Source/WTF/ChangeLog 2017-06-09 17:54:16 UTC (rev 217998)
@@ -1,3 +1,17 @@
+2017-06-09 Chris Dumez <[email protected]>
+
+ Update WorkQueue::concurrentApply() to take a WTF::Function instead of an std::function
+ https://bugs.webkit.org/show_bug.cgi?id=173165
+
+ Reviewed by Saam Barati.
+
+ Update WorkQueue::concurrentApply() to take a WTF::Function instead of an std::function
+ as std::function has issues with regards to thread safety.
+
+ * wtf/WorkQueue.h:
+ * wtf/cocoa/WorkQueueCocoa.cpp:
+ (WTF::WorkQueue::concurrentApply):
+
2017-06-08 Xabier Rodriguez Calvar <[email protected]>
MediaTime class has rounding issues in different platforms
Modified: trunk/Source/WTF/wtf/WorkQueue.cpp (217997 => 217998)
--- trunk/Source/WTF/wtf/WorkQueue.cpp 2017-06-09 17:52:42 UTC (rev 217997)
+++ trunk/Source/WTF/wtf/WorkQueue.cpp 2017-06-09 17:54:16 UTC (rev 217998)
@@ -29,6 +29,7 @@
#include <mutex>
#include <wtf/Condition.h>
#include <wtf/Deque.h>
+#include <wtf/Function.h>
#include <wtf/Lock.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/NumberOfCores.h>
@@ -55,7 +56,7 @@
}
#if !PLATFORM(COCOA)
-void WorkQueue::concurrentApply(size_t iterations, const std::function<void (size_t index)>& function)
+void WorkQueue::concurrentApply(size_t iterations, WTF::Function<void (size_t index)>&& function)
{
if (!iterations)
return;
@@ -82,7 +83,7 @@
size_t workerCount() const { return m_workers.size(); }
- void dispatch(const std::function<void ()>* function)
+ void dispatch(const WTF::Function<void ()>* function)
{
LockHolder holder(m_lock);
@@ -94,7 +95,7 @@
NO_RETURN void threadBody()
{
while (true) {
- const std::function<void ()>* function;
+ const WTF::Function<void ()>* function;
{
LockHolder holder(m_lock);
@@ -112,7 +113,7 @@
Lock m_lock;
Condition m_condition;
- Deque<const std::function<void ()>*> m_queue;
+ Deque<const WTF::Function<void ()>*> m_queue;
Vector<RefPtr<Thread>> m_workers;
};
@@ -132,7 +133,7 @@
Condition condition;
Lock lock;
- std::function<void ()> applier = [&] {
+ WTF::Function<void ()> applier = [&, function = WTFMove(function)] {
size_t index;
// Call the function for as long as there are iterations left.
Modified: trunk/Source/WTF/wtf/WorkQueue.h (217997 => 217998)
--- trunk/Source/WTF/wtf/WorkQueue.h 2017-06-09 17:52:42 UTC (rev 217997)
+++ trunk/Source/WTF/wtf/WorkQueue.h 2017-06-09 17:54:16 UTC (rev 217998)
@@ -69,7 +69,7 @@
WTF_EXPORT_PRIVATE void dispatch(Function<void()>&&) override;
WTF_EXPORT_PRIVATE void dispatchAfter(Seconds, Function<void()>&&);
- WTF_EXPORT_PRIVATE static void concurrentApply(size_t iterations, const std::function<void(size_t index)>&);
+ WTF_EXPORT_PRIVATE static void concurrentApply(size_t iterations, WTF::Function<void(size_t index)>&&);
#if USE(COCOA_EVENT_LOOP)
dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
Modified: trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp (217997 => 217998)
--- trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp 2017-06-09 17:52:42 UTC (rev 217997)
+++ trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp 2017-06-09 17:54:16 UTC (rev 217998)
@@ -100,11 +100,11 @@
dispatch_release(m_dispatchQueue);
}
-void WorkQueue::concurrentApply(size_t iterations, const std::function<void(size_t index)>& function)
+void WorkQueue::concurrentApply(size_t iterations, WTF::Function<void(size_t index)>&& function)
{
- dispatch_apply(iterations, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t index) {
+ dispatch_apply(iterations, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), BlockPtr<void(size_t index)>::fromCallable([function = WTFMove(function)](size_t index) {
function(index);
- });
+ }).get());
}
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes