xref: /aosp_15_r20/external/cronet/base/task/scoped_set_task_priority_for_current_thread.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #include "base/task/scoped_set_task_priority_for_current_thread.h"
6 
7 #include "base/compiler_specific.h"
8 #include "third_party/abseil-cpp/absl/base/attributes.h"
9 
10 namespace base {
11 namespace internal {
12 
13 namespace {
14 
15 ABSL_CONST_INIT thread_local TaskPriority task_priority_for_current_thread =
16     TaskPriority::USER_BLOCKING;
17 
18 }  // namespace
19 
ScopedSetTaskPriorityForCurrentThread(TaskPriority priority)20 ScopedSetTaskPriorityForCurrentThread::ScopedSetTaskPriorityForCurrentThread(
21     TaskPriority priority)
22     : resetter_(&task_priority_for_current_thread,
23                 priority,
24                 TaskPriority::USER_BLOCKING) {}
25 
26 ScopedSetTaskPriorityForCurrentThread::
27     ~ScopedSetTaskPriorityForCurrentThread() = default;
28 
GetTaskPriorityForCurrentThread()29 TaskPriority GetTaskPriorityForCurrentThread() {
30   // Workaround false-positive MSAN use-of-uninitialized-value on
31   // thread_local storage for loaded libraries:
32   // https://github.com/google/sanitizers/issues/1265
33   MSAN_UNPOISON(&task_priority_for_current_thread, sizeof(TaskPriority));
34 
35   return task_priority_for_current_thread;
36 }
37 
38 }  // namespace internal
39 }  // namespace base
40