Skip to content

Commit e12131e

Browse files
eklitzkeMaskRay
authored andcommitted
Set indexer threads' priority to ThreadPriority::Background (#538)
1 parent 2bc83ec commit e12131e

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/messages/initialize.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "working_files.hh"
1313

1414
#include <llvm/ADT/Twine.h>
15+
#include <llvm/Config/llvm-config.h>
1516
#include <llvm/Support/Threading.h>
1617

1718
#include <rapidjson/document.h>
@@ -255,6 +256,12 @@ void *indexer(void *arg_) {
255256
delete arg;
256257
std::string name = "indexer" + std::to_string(idx);
257258
set_thread_name(name.c_str());
259+
// Don't lower priority on __APPLE__. getpriority(2) says "When setting a
260+
// thread into background state the scheduling priority is set to lowest
261+
// value, disk and network IO are throttled."
262+
#if LLVM_ENABLE_THREADS && LLVM_VERSION_MAJOR >= 9 && !defined(__APPLE__)
263+
set_thread_priority(ThreadPriority::Background);
264+
#endif
258265
pipeline::indexer_Main(h->manager, h->vfs, h->project, h->wfiles);
259266
pipeline::threadLeave();
260267
return nullptr;

0 commit comments

Comments
 (0)