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

Side by Side Diff: base/threading/sequenced_worker_pool.h

Issue 369703003: Reduce usage of MessageLoopProxy in base/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 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
« no previous file with comments | « base/test/thread_test_helper.cc ('k') | base/threading/sequenced_worker_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 5 #ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_H_
6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_H_
7 7
8 #include <cstddef> 8 #include <cstddef>
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/task_runner.h" 16 #include "base/task_runner.h"
17 17
18 namespace tracked_objects { 18 namespace tracked_objects {
19 class Location; 19 class Location;
20 } // namespace tracked_objects 20 } // namespace tracked_objects
21 21
22 namespace base { 22 namespace base {
23 23
24 class MessageLoopProxy;
25
26 template <class T> class DeleteHelper; 24 template <class T> class DeleteHelper;
27 25
28 class SequencedTaskRunner; 26 class SequencedTaskRunner;
29 27
30 // A worker thread pool that enforces ordering between sets of tasks. It also 28 // A worker thread pool that enforces ordering between sets of tasks. It also
31 // allows you to specify what should happen to your tasks on shutdown. 29 // allows you to specify what should happen to your tasks on shutdown.
32 // 30 //
33 // To enforce ordering, get a unique sequence token from the pool and post all 31 // To enforce ordering, get a unique sequence token from the pool and post all
34 // tasks you want to order with the token. All tasks with the same token are 32 // tasks you want to order with the token. All tasks with the same token are
35 // guaranteed to execute serially, though not necessarily on the same thread. 33 // guaranteed to execute serially, though not necessarily on the same thread.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 virtual void WillWaitForShutdown() = 0; 148 virtual void WillWaitForShutdown() = 0;
151 virtual void OnDestruct() = 0; 149 virtual void OnDestruct() = 0;
152 }; 150 };
153 151
154 // Gets the SequencedToken of the current thread. 152 // Gets the SequencedToken of the current thread.
155 // If current thread is not a SequencedWorkerPool worker thread or is running 153 // If current thread is not a SequencedWorkerPool worker thread or is running
156 // an unsequenced task, returns an invalid SequenceToken. 154 // an unsequenced task, returns an invalid SequenceToken.
157 static SequenceToken GetSequenceTokenForCurrentThread(); 155 static SequenceToken GetSequenceTokenForCurrentThread();
158 156
159 // When constructing a SequencedWorkerPool, there must be a 157 // When constructing a SequencedWorkerPool, there must be a
160 // MessageLoop on the current thread unless you plan to deliberately 158 // Task Runner on the current thread unless you plan to deliberately
161 // leak it. 159 // leak it.
162 160
163 // Pass the maximum number of threads (they will be lazily created as needed) 161 // Pass the maximum number of threads (they will be lazily created as needed)
164 // and a prefix for the thread name to aid in debugging. 162 // and a prefix for the thread name to aid in debugging.
165 SequencedWorkerPool(size_t max_threads, 163 SequencedWorkerPool(size_t max_threads,
166 const std::string& thread_name_prefix); 164 const std::string& thread_name_prefix);
167 165
168 // Like above, but with |observer| for testing. Does not take 166 // Like above, but with |observer| for testing. Does not take
169 // ownership of |observer|. 167 // ownership of |observer|.
170 SequencedWorkerPool(size_t max_threads, 168 SequencedWorkerPool(size_t max_threads,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 338
341 virtual void OnDestruct() const override; 339 virtual void OnDestruct() const override;
342 340
343 private: 341 private:
344 friend class RefCountedThreadSafe<SequencedWorkerPool>; 342 friend class RefCountedThreadSafe<SequencedWorkerPool>;
345 friend class DeleteHelper<SequencedWorkerPool>; 343 friend class DeleteHelper<SequencedWorkerPool>;
346 344
347 class Inner; 345 class Inner;
348 class Worker; 346 class Worker;
349 347
350 const scoped_refptr<MessageLoopProxy> constructor_message_loop_; 348 const scoped_refptr<SequencedTaskRunner> constructor_task_runner_;
351 349
352 // Avoid pulling in too many headers by putting (almost) everything 350 // Avoid pulling in too many headers by putting (almost) everything
353 // into |inner_|. 351 // into |inner_|.
354 const scoped_ptr<Inner> inner_; 352 const scoped_ptr<Inner> inner_;
355 353
356 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); 354 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool);
357 }; 355 };
358 356
359 } // namespace base 357 } // namespace base
360 358
361 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 359 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_
OLDNEW
« no previous file with comments | « base/test/thread_test_helper.cc ('k') | base/threading/sequenced_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698