llvm.org GIT mirror llvm / ce6e7c7
For CrashRecoveryContext::RunSafelyOnThread, propagate Darwin's PRIO_DARWIN_BG to the new thread if it is set on the calling thread. This allows libclang's indexing threads to propagate their priority to the clang module building threads. rdar://17459872 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211747 91177308-0d34-0410-b5e6-96231b3b80d8 Argyrios Kyrtzidis 6 years ago
2 changed file(s) with 24 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
8686 /// requested stack size).
8787 ///
8888 /// See RunSafely() and llvm_execute_on_thread().
89 ///
90 /// On Darwin, if PRIO_DARWIN_BG is set on the calling thread, it will be
91 /// propagated to the new thread as well.
8992 bool RunSafelyOnThread(function_ref, unsigned RequestedStackSize = 0);
9093 bool RunSafelyOnThread(void (*Fn)(void*), void *UserData,
9194 unsigned RequestedStackSize = 0) {
331331 return CRC->Backtrace;
332332 }
333333
334 //
334 // FIXME: Portability.
335 static void setThreadBackgroundPriority() {
336 #ifdef __APPLE__
337 setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG);
338 #endif
339 }
340
341 static bool hasThreadBackgroundPriority() {
342 #ifdef __APPLE__
343 return getpriority(PRIO_DARWIN_THREAD, 0) == 1;
344 #else
345 return false;
346 #endif
347 }
335348
336349 namespace {
337350 struct RunSafelyOnThreadInfo {
338351 function_ref Fn;
339352 CrashRecoveryContext *CRC;
353 bool UseBackgroundPriority;
340354 bool Result;
341355 };
342356 }
344358 static void RunSafelyOnThread_Dispatch(void *UserData) {
345359 RunSafelyOnThreadInfo *Info =
346360 reinterpret_cast(UserData);
361
362 if (Info->UseBackgroundPriority)
363 setThreadBackgroundPriority();
364
347365 Info->Result = Info->CRC->RunSafely(Info->Fn);
348366 }
349367 bool CrashRecoveryContext::RunSafelyOnThread(function_ref Fn,
350368 unsigned RequestedStackSize) {
351 RunSafelyOnThreadInfo Info = { Fn, this, false };
369 bool UseBackgroundPriority = hasThreadBackgroundPriority();
370 RunSafelyOnThreadInfo Info = { Fn, this, UseBackgroundPriority, false };
352371 llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize);
353372 if (CrashRecoveryContextImpl *CRC = (CrashRecoveryContextImpl *)Impl)
354373 CRC->setSwitchedThread();