Support WorkQueue QOS classes on Mavericks
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2015 17:06:15 +0000 (17:06 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2015 17:06:15 +0000 (17:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142328

Reviewed by Anders Carlsson.

"The priority of a dispatch queue is inherited from its target queue.  In order to
change the priority of a queue created with dispatch_queue_create(), use the
dispatch_get_global_queue() function to obtain a target queue of the desired prior-
ity."

* wtf/cocoa/WorkQueueCocoa.cpp:
(WTF::targetQueueForQOSClass):
(WTF::WorkQueue::platformInitialize):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181080 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp

index c4bea58..6285c11 100644 (file)
@@ -1,3 +1,19 @@
+2015-03-05  Antti Koivisto  <antti@apple.com>
+
+        Support WorkQueue QOS classes on Mavericks
+        https://bugs.webkit.org/show_bug.cgi?id=142328
+
+        Reviewed by Anders Carlsson.
+
+        "The priority of a dispatch queue is inherited from its target queue.  In order to
+        change the priority of a queue created with dispatch_queue_create(), use the
+        dispatch_get_global_queue() function to obtain a target queue of the desired prior-
+        ity."
+
+        * wtf/cocoa/WorkQueueCocoa.cpp:
+        (WTF::targetQueueForQOSClass):
+        (WTF::WorkQueue::platformInitialize):
+
 2015-03-03  Anders Carlsson  <andersca@apple.com>
 
         Remove unused compression code
 2015-03-03  Anders Carlsson  <andersca@apple.com>
 
         Remove unused compression code
index 2bd6611..1901b60 100644 (file)
@@ -62,6 +62,23 @@ static dispatch_qos_class_t dispatchQOSClass(WorkQueue::QOS qos)
         return QOS_CLASS_BACKGROUND;
     }
 }
         return QOS_CLASS_BACKGROUND;
     }
 }
+#else
+static dispatch_queue_t targetQueueForQOSClass(WorkQueue::QOS qos)
+{
+    switch (qos) {
+    case WorkQueue::QOS::UserInteractive:
+    case WorkQueue::QOS::UserInitiated:
+        return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
+    case WorkQueue::QOS::Utility:
+        return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
+    case WorkQueue::QOS::Background:
+        return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
+    case WorkQueue::QOS::Default:
+        ASSERT_NOT_REACHED();
+        return nullptr;
+    }
+    ASSERT_NOT_REACHED();
+}
 #endif
 
 void WorkQueue::platformInitialize(const char* name, Type type, QOS qos)
 #endif
 
 void WorkQueue::platformInitialize(const char* name, Type type, QOS qos)
@@ -73,6 +90,10 @@ void WorkQueue::platformInitialize(const char* name, Type type, QOS qos)
     UNUSED_PARAM(qos);
 #endif
     m_dispatchQueue = dispatch_queue_create(name, attr);
     UNUSED_PARAM(qos);
 #endif
     m_dispatchQueue = dispatch_queue_create(name, attr);
+#if !HAVE(QOS_CLASSES)
+    if (qos != WorkQueue::QOS::Default)
+        dispatch_set_target_queue(m_dispatchQueue, targetQueueForQOSClass(qos));
+#endif
     dispatch_set_context(m_dispatchQueue, this);
 }
 
     dispatch_set_context(m_dispatchQueue, this);
 }