1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_THREADING_PLATFORM_THREAD_INTERNAL_POSIX_H_ 6 #define BASE_THREADING_PLATFORM_THREAD_INTERNAL_POSIX_H_ 7 8 #include "base/base_export.h" 9 #include "base/threading/platform_thread.h" 10 #include "build/build_config.h" 11 #include "third_party/abseil-cpp/absl/types/optional.h" 12 13 namespace base { 14 15 namespace internal { 16 17 struct ThreadTypeToNiceValuePair { 18 ThreadType thread_type; 19 int nice_value; 20 }; 21 22 struct ThreadPriorityToNiceValuePairForTest { 23 ThreadPriorityForTest priority; 24 int nice_value; 25 }; 26 27 // The elements must be listed in the order of increasing priority (lowest 28 // priority first), that is, in the order of decreasing nice values (highest 29 // nice value first). 30 extern const ThreadTypeToNiceValuePair kThreadTypeToNiceValueMap[7]; 31 32 // The elements must be listed in the order of decreasing priority (highest 33 // priority first), that is, in the order of increasing nice values (lowest nice 34 // value first). 35 extern const ThreadPriorityToNiceValuePairForTest 36 kThreadPriorityToNiceValueMapForTest[7]; 37 38 // Returns the nice value matching |priority| based on the platform-specific 39 // implementation of kThreadTypeToNiceValueMap. 40 int ThreadTypeToNiceValue(ThreadType thread_type); 41 42 // Returns whether SetCurrentThreadTypeForPlatform can set a thread as 43 // kRealtimeAudio. 44 bool CanSetThreadTypeToRealtimeAudio(); 45 46 // Allows platform specific tweaks to the generic POSIX solution for 47 // SetCurrentThreadType(). Returns true if the platform-specific 48 // implementation handled this |thread_type| change, false if the generic 49 // implementation should instead proceed. 50 bool SetCurrentThreadTypeForPlatform(ThreadType thread_type, 51 MessagePumpType pump_type_hint); 52 53 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) 54 // Current thread id is cached in thread local storage for performance reasons. 55 // In some rare cases it's important to invalidate that cache explicitly (e.g. 56 // after going through clone() syscall which does not call pthread_atfork() 57 // handlers). 58 // This can only be called when the process is single-threaded. 59 BASE_EXPORT void InvalidateTidCache(); 60 #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) 61 62 // Returns the ThreadPrioirtyForTest matching |nice_value| based on the 63 // platform-specific implementation of kThreadPriorityToNiceValueMapForTest. 64 ThreadPriorityForTest NiceValueToThreadPriorityForTest(int nice_value); 65 66 absl::optional<ThreadPriorityForTest> 67 GetCurrentThreadPriorityForPlatformForTest(); 68 69 int GetCurrentThreadNiceValue(); 70 71 } // namespace internal 72 73 } // namespace base 74 75 #endif // BASE_THREADING_PLATFORM_THREAD_INTERNAL_POSIX_H_ 76