platform_thread_internal_posix.h 2.7 KB

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