Index: base/task_scheduler/task_traits_for_current_thread.cc |
diff --git a/base/task_scheduler/task_traits_for_current_thread.cc b/base/task_scheduler/task_traits_for_current_thread.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..391dee4804e3df851a4a8499efff2144823d3d1e |
--- /dev/null |
+++ b/base/task_scheduler/task_traits_for_current_thread.cc |
@@ -0,0 +1,43 @@ |
+// 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_traits_for_current_thread.h" |
+ |
+#include "base/lazy_instance.h" |
+#include "base/threading/thread_local.h" |
+ |
+namespace base { |
+namespace internal { |
+ |
+namespace { |
+ |
+LazyInstance<ThreadLocalPointer<const TaskTraits>>::Leaky |
+ tls_traits_for_current_thread = LAZY_INSTANCE_INITIALIZER; |
+ |
+} // namespace |
+ |
+ScopedSetTaskTraitsForCurrentThread::ScopedSetTaskTraitsForCurrentThread( |
+ const TaskTraits* traits) |
robliao
2016/12/01 18:12:01
Crazy thought. Can this simply be a const TaskTrai
fdoray
2016/12/01 19:16:02
n/a with TaskPriority
|
+#if DCHECK_IS_ON() |
+ : traits_(traits) |
+#endif |
+{ |
+ DCHECK(!GetTaskTraitsForCurrentThread()); |
+ DCHECK(traits); |
+ tls_traits_for_current_thread.Get().Set(traits); |
+} |
+ |
+ScopedSetTaskTraitsForCurrentThread::~ScopedSetTaskTraitsForCurrentThread() { |
+#if DCHECK_IS_ON() |
+ DCHECK_EQ(traits_, GetTaskTraitsForCurrentThread()); |
gab
2016/12/01 18:04:39
Is this necessary? As long as we DCHECK == null in
fdoray
2016/12/01 19:16:02
Not necessary. Do you still want me to remove it w
|
+#endif |
+ tls_traits_for_current_thread.Get().Set(nullptr); |
+} |
+ |
+const TaskTraits* GetTaskTraitsForCurrentThread() { |
+ return tls_traits_for_current_thread.Get().Get(); |
+} |
+ |
+} // namespace internal |
+} // namespace base |