platform_thread_internal_posix.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/optional.h"
  8. #include "base/threading/platform_thread.h"
  9. #include "build/build_config.h"
  10. namespace base {
  11. namespace internal {
  12. struct ThreadPriorityToNiceValuePair {
  13. ThreadPriority priority;
  14. int nice_value;
  15. };
  16. // The elements must be listed in the order of increasing priority (lowest
  17. // priority first), that is, in the order of decreasing nice values (highest
  18. // nice value first).
  19. BASE_EXPORT extern
  20. const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4];
  21. // Returns the nice value matching |priority| based on the platform-specific
  22. // implementation of kThreadPriorityToNiceValueMap.
  23. int ThreadPriorityToNiceValue(ThreadPriority priority);
  24. // Returns the ThreadPrioirty matching |nice_value| based on the platform-
  25. // specific implementation of kThreadPriorityToNiceValueMap.
  26. BASE_EXPORT ThreadPriority NiceValueToThreadPriority(int nice_value);
  27. // If non-nullopt, this return value will be used as the platform-specific
  28. // result of CanIncreaseThreadPriority().
  29. Optional<bool> CanIncreaseCurrentThreadPriorityForPlatform(
  30. ThreadPriority priority);
  31. // Allows platform specific tweaks to the generic POSIX solution for
  32. // SetCurrentThreadPriority(). Returns true if the platform-specific
  33. // implementation handled this |priority| change, false if the generic
  34. // implementation should instead proceed.
  35. bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority);
  36. // If non-null, this return value will be used as the platform-specific result
  37. // of CanIncreaseThreadPriority().
  38. Optional<ThreadPriority> GetCurrentThreadPriorityForPlatform();
  39. #if defined(OS_LINUX) || defined(OS_CHROMEOS)
  40. // Current thread id is cached in thread local storage for performance reasons.
  41. // In some rare cases it's important to clear that cache explicitly (e.g. after
  42. // going through clone() syscall which does not call pthread_atfork()
  43. // handlers).
  44. BASE_EXPORT void ClearTidCache();
  45. #endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
  46. } // namespace internal
  47. } // namespace base
  48. #endif // BASE_THREADING_PLATFORM_THREAD_INTERNAL_POSIX_H_