OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/threading/worker_pool.h" | 5 #include "base/threading/worker_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/pending_task.h" | 10 #include "base/pending_task.h" |
11 #include "base/threading/thread_local.h" | 11 #include "base/threading/thread_local.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 base::LazyInstance<ThreadLocalBoolean>::Leaky | 19 ThreadLocalBoolean* GetWorkerPoolRunningOnThisThread() { |
20 g_worker_pool_running_on_this_thread = LAZY_INSTANCE_INITIALIZER; | 20 static auto thread_local_boolean = new ThreadLocalBoolean(); |
| 21 return thread_local_boolean; |
| 22 } |
21 | 23 |
22 DWORD CALLBACK WorkItemCallback(void* param) { | 24 DWORD CALLBACK WorkItemCallback(void* param) { |
23 PendingTask* pending_task = static_cast<PendingTask*>(param); | 25 PendingTask* pending_task = static_cast<PendingTask*>(param); |
24 TRACE_TASK_EXECUTION("WorkerThread::ThreadMain::Run", *pending_task); | 26 TRACE_TASK_EXECUTION("WorkerThread::ThreadMain::Run", *pending_task); |
25 | 27 |
26 g_worker_pool_running_on_this_thread.Get().Set(true); | 28 GetWorkerPoolRunningOnThisThread()->Set(true); |
27 | 29 |
28 tracked_objects::TaskStopwatch stopwatch; | 30 tracked_objects::TaskStopwatch stopwatch; |
29 stopwatch.Start(); | 31 stopwatch.Start(); |
30 std::move(pending_task->task).Run(); | 32 std::move(pending_task->task).Run(); |
31 stopwatch.Stop(); | 33 stopwatch.Stop(); |
32 | 34 |
33 g_worker_pool_running_on_this_thread.Get().Set(false); | 35 GetWorkerPoolRunningOnThisThread()->Set(false); |
34 | 36 |
35 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( | 37 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( |
36 pending_task->birth_tally, pending_task->time_posted, stopwatch); | 38 pending_task->birth_tally, pending_task->time_posted, stopwatch); |
37 | 39 |
38 delete pending_task; | 40 delete pending_task; |
39 return 0; | 41 return 0; |
40 } | 42 } |
41 | 43 |
42 // Takes ownership of |pending_task| | 44 // Takes ownership of |pending_task| |
43 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { | 45 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { |
(...skipping 14 matching lines...) Expand all Loading... |
58 | 60 |
59 // static | 61 // static |
60 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 62 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
61 const base::Closure& task, bool task_is_slow) { | 63 const base::Closure& task, bool task_is_slow) { |
62 PendingTask* pending_task = new PendingTask(from_here, task); | 64 PendingTask* pending_task = new PendingTask(from_here, task); |
63 return PostTaskInternal(pending_task, task_is_slow); | 65 return PostTaskInternal(pending_task, task_is_slow); |
64 } | 66 } |
65 | 67 |
66 // static | 68 // static |
67 bool WorkerPool::RunsTasksOnCurrentThread() { | 69 bool WorkerPool::RunsTasksOnCurrentThread() { |
68 return g_worker_pool_running_on_this_thread.Get().Get(); | 70 return GetWorkerPoolRunningOnThisThread()->Get(); |
69 } | 71 } |
70 | 72 |
71 } // namespace base | 73 } // namespace base |
OLD | NEW |