Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: base/task_scheduler/task_priority_for_current_thread.cc

Issue 2546773002: TaskScheduler: Add internal::GetTaskPriorityForCurrentThread(). (Closed)
Patch Set: traits -> priority Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
5 #include "base/task_scheduler/task_priority_for_current_thread.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "base/threading/thread_local.h"
10
11 namespace base {
12 namespace internal {
13
14 namespace {
15
16 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.
17 tls_task_priority_for_current_thread = LAZY_INSTANCE_INITIALIZER;
18
19 } // namespace
20
21 ScopedSetTaskPriorityForCurrentThread::ScopedSetTaskPriorityForCurrentThread(
22 TaskPriority priority)
23 : priority_(priority) {
24 DCHECK(!tls_task_priority_for_current_thread.Get().Get());
25 tls_task_priority_for_current_thread.Get().Set(&priority_);
26 }
27
28 ScopedSetTaskPriorityForCurrentThread::
29 ~ScopedSetTaskPriorityForCurrentThread() {
30 DCHECK_EQ(&priority_, tls_task_priority_for_current_thread.Get().Get());
31 tls_task_priority_for_current_thread.Get().Set(nullptr);
32 }
33
34 TaskPriority GetTaskPriorityForCurrentThread() {
35 const TaskPriority* priority =
36 tls_task_priority_for_current_thread.Get().Get();
37 return priority ? *priority : TaskPriority::USER_VISIBLE;
38 }
39
40 } // namespace internal
41 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698