| 6 |
| 7 | #include <memory> |
| 8 |
| 9 | #include "base/feature_list.h" |
| 10 |
| 11 | namespace base { |
| 12 |
| 13 | namespace { |
| 14 |
| 15 | // Whether thread priorities should be used. When disabled, |
| 16 | // PlatformThread::SetCurrentThreadPriority() no-ops. |
| 17 | const Feature kThreadPrioritiesFeature{"ThreadPriorities", |
| 18 | FEATURE_ENABLED_BY_DEFAULT}; |
| 19 |
| 20 | // Whether thread priorities should be used. |
| 21 | // |
| 22 | // PlatformThread::SetCurrentThreadPriority() doesn't query the state of the |
| 23 | // feature directly because FeatureList initialization is not always |
| 24 | // synchronized with PlatformThread::SetCurrentThreadPriority(). |
| 25 | std::atomic<bool> g_use_thread_priorities(true); |
| 26 |
| 27 | } // namespace |
| 28 |
| 29 | // static |
| 30 | void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) { |
| 31 | if (g_use_thread_priorities.load()) |
| 32 | SetCurrentThreadPriorityImpl(priority); |
| 33 | } |
| 34 |
| 35 | namespace internal { |
| 36 |
| 37 | void InitializeThreadPrioritiesFeature() { |
| 38 | // A DCHECK is triggered on FeatureList initialization if the state of a |
| 39 | // feature has been checked before. To avoid triggering this DCHECK in unit |
| 40 | // tests that call this before initializing the FeatureList, only check the |
| 41 | // state of the feature if the FeatureList is initialized. |
| 42 | if (FeatureList::GetInstance() && |
| 43 | !FeatureList::IsEnabled(kThreadPrioritiesFeature)) { |
| 44 | g_use_thread_priorities.store(false); |
| 45 | } |
| 46 | } |
| 47 |
| 48 | } // namespace internal |
| 49 |
| 50 | } // namespace base |
| 51 |