scoped_set_task_priority_for_current_thread.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2016 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_TASK_SCOPED_SET_TASK_PRIORITY_FOR_CURRENT_THREAD_H_
  5. #define BASE_TASK_SCOPED_SET_TASK_PRIORITY_FOR_CURRENT_THREAD_H_
  6. #include "base/base_export.h"
  7. #include "base/task/task_traits.h"
  8. namespace base {
  9. namespace internal {
  10. class BASE_EXPORT ScopedSetTaskPriorityForCurrentThread {
  11. public:
  12. // Within the scope of this object, GetTaskPriorityForCurrentThread() will
  13. // return |priority|.
  14. explicit ScopedSetTaskPriorityForCurrentThread(TaskPriority priority);
  15. ScopedSetTaskPriorityForCurrentThread(
  16. const ScopedSetTaskPriorityForCurrentThread&) = delete;
  17. ScopedSetTaskPriorityForCurrentThread& operator=(
  18. const ScopedSetTaskPriorityForCurrentThread&) = delete;
  19. ~ScopedSetTaskPriorityForCurrentThread();
  20. private:
  21. const TaskPriority priority_;
  22. };
  23. // Returns the priority of the task running on the current thread,
  24. // or TaskPriority::USER_BLOCKING by default if none.
  25. BASE_EXPORT TaskPriority GetTaskPriorityForCurrentThread();
  26. } // namespace internal
  27. } // namespace base
  28. #endif // BASE_TASK_SCOPED_SET_TASK_PRIORITY_FOR_CURRENT_THREAD_H_