1 // Copyright 2016 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_TASK_SCOPED_SET_TASK_PRIORITY_FOR_CURRENT_THREAD_H_ 6 #define BASE_TASK_SCOPED_SET_TASK_PRIORITY_FOR_CURRENT_THREAD_H_ 7 8 #include "base/auto_reset.h" 9 #include "base/base_export.h" 10 #include "base/task/task_traits.h" 11 12 namespace base { 13 namespace internal { 14 15 class BASE_EXPORT 16 [[maybe_unused, nodiscard]] ScopedSetTaskPriorityForCurrentThread { 17 public: 18 // Within the scope of this object, GetTaskPriorityForCurrentThread() will 19 // return |priority|. 20 explicit ScopedSetTaskPriorityForCurrentThread(TaskPriority priority); 21 22 ScopedSetTaskPriorityForCurrentThread( 23 const ScopedSetTaskPriorityForCurrentThread&) = delete; 24 ScopedSetTaskPriorityForCurrentThread& operator=( 25 const ScopedSetTaskPriorityForCurrentThread&) = delete; 26 27 ~ScopedSetTaskPriorityForCurrentThread(); 28 29 private: 30 const AutoReset<TaskPriority> resetter_; 31 }; 32 33 // Returns the priority of the task running on the current thread, 34 // or TaskPriority::USER_BLOCKING by default if none. 35 BASE_EXPORT TaskPriority GetTaskPriorityForCurrentThread(); 36 37 } // namespace internal 38 } // namespace base 39 40 #endif // BASE_TASK_SCOPED_SET_TASK_PRIORITY_FOR_CURRENT_THREAD_H_ 41