[clangd] Add thread priority lowering for MacOS as well
authorKadir Cetinkaya <kadircet@google.com>
Mon, 25 Feb 2019 09:19:26 +0000 (09:19 +0000)
committerKadir Cetinkaya <kadircet@google.com>
Mon, 25 Feb 2019 09:19:26 +0000 (09:19 +0000)
Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58492

llvm-svn: 354765

clang-tools-extra/clangd/Threading.cpp

index 139fcc2..695e30d 100644 (file)
@@ -7,6 +7,8 @@
 #include <thread>
 #ifdef __USE_POSIX
 #include <pthread.h>
+#elif defined(__APPLE__)
+#include <sys/resource.h>
 #endif
 
 namespace clang {
@@ -121,6 +123,12 @@ void setCurrentThreadPriority(ThreadPriority Priority) {
       Priority == ThreadPriority::Low && !AvoidThreadStarvation ? SCHED_IDLE
                                                                 : SCHED_OTHER,
       &priority);
+#elif defined(__APPLE__)
+  // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getpriority.2.html
+  setpriority(PRIO_DARWIN_THREAD, 0,
+              Priority == ThreadPriority::Low && !AvoidThreadStarvation
+                  ? PRIO_DARWIN_BG
+                  : 0);
 #endif
 }