| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( | 39 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( |
| 40 pending_task->birth_tally, pending_task->time_posted, stopwatch); | 40 pending_task->birth_tally, pending_task->time_posted, stopwatch); |
| 41 | 41 |
| 42 delete pending_task; | 42 delete pending_task; |
| 43 return 0; | 43 return 0; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Takes ownership of |pending_task| | 46 // Takes ownership of |pending_task| |
| 47 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { | 47 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { |
| 48 DCHECK(pending_task->task); |
| 49 |
| 48 ULONG flags = 0; | 50 ULONG flags = 0; |
| 49 if (task_is_slow) | 51 if (task_is_slow) |
| 50 flags |= WT_EXECUTELONGFUNCTION; | 52 flags |= WT_EXECUTELONGFUNCTION; |
| 51 | 53 |
| 52 if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) { | 54 if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) { |
| 53 DPLOG(ERROR) << "QueueUserWorkItem failed"; | 55 DPLOG(ERROR) << "QueueUserWorkItem failed"; |
| 54 delete pending_task; | 56 delete pending_task; |
| 55 return false; | 57 return false; |
| 56 } | 58 } |
| 57 | 59 |
| 58 return true; | 60 return true; |
| 59 } | 61 } |
| 60 | 62 |
| 61 } // namespace | 63 } // namespace |
| 62 | 64 |
| 63 // static | 65 // static |
| 64 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 66 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
| 65 base::Closure task, | 67 base::Closure task, |
| 66 bool task_is_slow) { | 68 bool task_is_slow) { |
| 67 PendingTask* pending_task = new PendingTask(from_here, std::move(task)); | 69 PendingTask* pending_task = new PendingTask(from_here, std::move(task)); |
| 68 return PostTaskInternal(pending_task, task_is_slow); | 70 return PostTaskInternal(pending_task, task_is_slow); |
| 69 } | 71 } |
| 70 | 72 |
| 71 // static | 73 // static |
| 72 bool WorkerPool::RunsTasksOnCurrentThread() { | 74 bool WorkerPool::RunsTasksOnCurrentThread() { |
| 73 return GetWorkerPoolRunningOnThisThread()->Get(); | 75 return GetWorkerPoolRunningOnThisThread()->Get(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace base | 78 } // namespace base |
| OLD | NEW |