OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_posix.h" | 5 #include "base/threading/worker_pool_posix.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 private: | 71 private: |
72 const std::string name_prefix_; | 72 const std::string name_prefix_; |
73 scoped_refptr<base::PosixDynamicThreadPool> pool_; | 73 scoped_refptr<base::PosixDynamicThreadPool> pool_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(WorkerThread); | 75 DISALLOW_COPY_AND_ASSIGN(WorkerThread); |
76 }; | 76 }; |
77 | 77 |
78 void WorkerThread::ThreadMain() { | 78 void WorkerThread::ThreadMain() { |
79 const std::string name = base::StringPrintf( | 79 const std::string name = base::StringPrintf( |
80 "%s/%d", name_prefix_.c_str(), PlatformThread::CurrentId()); | 80 "%s/%d", name_prefix_.c_str(), PlatformThread::CurrentId()); |
| 81 // Note |name.c_str()| must remain valid for for the whole life of the thread. |
81 PlatformThread::SetName(name.c_str()); | 82 PlatformThread::SetName(name.c_str()); |
82 | 83 |
83 for (;;) { | 84 for (;;) { |
84 PosixDynamicThreadPool::PendingTask pending_task = pool_->WaitForTask(); | 85 PosixDynamicThreadPool::PendingTask pending_task = pool_->WaitForTask(); |
85 if (pending_task.task.is_null()) | 86 if (pending_task.task.is_null()) |
86 break; | 87 break; |
87 UNSHIPPED_TRACE_EVENT2("task", "WorkerThread::ThreadMain::Run", | 88 UNSHIPPED_TRACE_EVENT2("task", "WorkerThread::ThreadMain::Run", |
88 "src_file", pending_task.posted_from.file_name(), | 89 "src_file", pending_task.posted_from.file_name(), |
89 "src_func", pending_task.posted_from.function_name()); | 90 "src_func", pending_task.posted_from.function_name()); |
90 | 91 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return PendingTask(FROM_HERE, base::Closure()); | 218 return PendingTask(FROM_HERE, base::Closure()); |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 PendingTask pending_task = pending_tasks_.front(); | 222 PendingTask pending_task = pending_tasks_.front(); |
222 pending_tasks_.pop(); | 223 pending_tasks_.pop(); |
223 return pending_task; | 224 return pending_task; |
224 } | 225 } |
225 | 226 |
226 } // namespace base | 227 } // namespace base |
OLD | NEW |