Index: base/task_scheduler/task_priority_for_current_thread.cc |
diff --git a/base/task_scheduler/task_priority_for_current_thread.cc b/base/task_scheduler/task_priority_for_current_thread.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c63326f9d94db89a92e22d123b24924f7a99f6eb |
--- /dev/null |
+++ b/base/task_scheduler/task_priority_for_current_thread.cc |
@@ -0,0 +1,41 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/task_scheduler/task_priority_for_current_thread.h" |
+ |
+#include "base/lazy_instance.h" |
+#include "base/logging.h" |
+#include "base/threading/thread_local.h" |
+ |
+namespace base { |
+namespace internal { |
+ |
+namespace { |
+ |
+LazyInstance<ThreadLocalPointer<const TaskPriority>>::Leaky |
robliao
2016/12/01 19:27:27
Would ThreadLocalStorage::StaticSlot tls... = TLS_
fdoray
2016/12/01 19:41:07
I doubt it.
1. I don't need more direct control o
robliao
2016/12/01 20:08:57
sgtm.
|
+ tls_task_priority_for_current_thread = LAZY_INSTANCE_INITIALIZER; |
+ |
+} // namespace |
+ |
+ScopedSetTaskPriorityForCurrentThread::ScopedSetTaskPriorityForCurrentThread( |
+ TaskPriority priority) |
+ : priority_(priority) { |
+ DCHECK(!tls_task_priority_for_current_thread.Get().Get()); |
+ tls_task_priority_for_current_thread.Get().Set(&priority_); |
+} |
+ |
+ScopedSetTaskPriorityForCurrentThread:: |
+ ~ScopedSetTaskPriorityForCurrentThread() { |
+ DCHECK_EQ(&priority_, tls_task_priority_for_current_thread.Get().Get()); |
+ tls_task_priority_for_current_thread.Get().Set(nullptr); |
+} |
+ |
+TaskPriority GetTaskPriorityForCurrentThread() { |
+ const TaskPriority* priority = |
+ tls_task_priority_for_current_thread.Get().Get(); |
+ return priority ? *priority : TaskPriority::USER_VISIBLE; |
+} |
+ |
+} // namespace internal |
+} // namespace base |