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

Side by Side Diff: base/threading/worker_pool_win.cc

Issue 8139028: Add WorkerPool::PostTaskAndReply and use in DHCP code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Naming and comment fixes based on self-review. Created 9 years, 2 months 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 | Annotate | Revision Log
OLDNEW
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.h" 5 #include "base/threading/worker_pool.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/logging.h" 9 #include "base/logging.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "base/threading/post_task_and_reply_impl.h"
11 #include "base/tracked_objects.h" 12 #include "base/tracked_objects.h"
12 13
13 namespace base { 14 namespace base {
14 15
15 namespace { 16 namespace {
16 17
17 struct PendingTask { 18 struct PendingTask {
18 PendingTask( 19 PendingTask(
19 const tracked_objects::Location& posted_from, 20 const tracked_objects::Location& posted_from,
20 const base::Closure& task) 21 const base::Closure& task)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 65
65 if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) { 66 if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) {
66 DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError(); 67 DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError();
67 delete pending_task; 68 delete pending_task;
68 return false; 69 return false;
69 } 70 }
70 71
71 return true; 72 return true;
72 } 73 }
73 74
75 class PostTaskAndReplyWorkerPool : public PostTaskAndReplyImpl {
76 public:
77 PostTaskAndReplyWorkerPool(bool task_is_slow) : task_is_slow_(task_is_slow) {
78 }
79
80 bool PostTask(const tracked_objects::Location& from_here,
81 const Closure& task) {
82 return WorkerPool::PostTask(from_here, task, task_is_slow_);
83 }
84
85 private:
86 bool task_is_slow_;
87 };
88
74 } // namespace 89 } // namespace
75 90
76 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 91 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
77 Task* task, bool task_is_slow) { 92 Task* task, bool task_is_slow) {
78 PendingTask* pending_task = 93 PendingTask* pending_task =
79 new PendingTask(from_here, 94 new PendingTask(from_here,
80 base::Bind(&subtle::TaskClosureAdapter::Run, 95 base::Bind(&subtle::TaskClosureAdapter::Run,
81 new subtle::TaskClosureAdapter(task))); 96 new subtle::TaskClosureAdapter(task)));
82 return PostTaskInternal(pending_task, task_is_slow); 97 return PostTaskInternal(pending_task, task_is_slow);
83 } 98 }
84 99
85 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 100 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
86 const base::Closure& task, bool task_is_slow) { 101 const base::Closure& task, bool task_is_slow) {
87 PendingTask* pending_task = new PendingTask(from_here, task); 102 PendingTask* pending_task = new PendingTask(from_here, task);
88 return PostTaskInternal(pending_task, task_is_slow); 103 return PostTaskInternal(pending_task, task_is_slow);
89 } 104 }
90 105
106 bool WorkerPool::PostTaskAndReply(const tracked_objects::Location& from_here,
107 const Closure& task,
108 const Closure& reply,
109 bool task_is_slow) {
110 return PostTaskAndReplyWorkerPool(task_is_slow).PostTaskAndReply(
111 from_here, task, reply);
awong 2011/10/05 17:27:01 Yeah, if PostTaskAndReply were in a header file, t
112 }
113
91 } // namespace base 114 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698