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

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

Issue 9663075: Implementation of SequencedTaskRunner based on SequencedWorkerPool. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 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) 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 #pragma once 7 #pragma once
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <string> 10 #include <string>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/task_runner.h" 17 #include "base/task_runner.h"
18 18
19 namespace tracked_objects { 19 namespace tracked_objects {
20 class Location; 20 class Location;
21 } // namespace tracked_objects 21 } // namespace tracked_objects
22 22
23 namespace base { 23 namespace base {
24 24
25 class MessageLoopProxy; 25 class MessageLoopProxy;
26 26
27 template <class T> class DeleteHelper; 27 template <class T> class DeleteHelper;
28 28
29 class SequencedTaskRunner;
30
29 // A worker thread pool that enforces ordering between sets of tasks. It also 31 // A worker thread pool that enforces ordering between sets of tasks. It also
30 // allows you to specify what should happen to your tasks on shutdown. 32 // allows you to specify what should happen to your tasks on shutdown.
31 // 33 //
32 // To enforce ordering, get a unique sequence token from the pool and post all 34 // To enforce ordering, get a unique sequence token from the pool and post all
33 // tasks you want to order with the token. All tasks with the same token are 35 // tasks you want to order with the token. All tasks with the same token are
34 // guaranteed to execute serially, though not necessarily on the same thread. 36 // guaranteed to execute serially, though not necessarily on the same thread.
35 // 37 //
36 // Example: 38 // Example:
37 // SequencedWorkerPool::SequenceToken token = pool.GetSequenceToken(); 39 // SequencedWorkerPool::SequenceToken token = pool.GetSequenceToken();
38 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, 40 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // Returns a unique token that can be used to sequence tasks posted to 147 // Returns a unique token that can be used to sequence tasks posted to
146 // PostSequencedWorkerTask(). Valid tokens are alwys nonzero. 148 // PostSequencedWorkerTask(). Valid tokens are alwys nonzero.
147 SequenceToken GetSequenceToken(); 149 SequenceToken GetSequenceToken();
148 150
149 // Returns the sequence token associated with the given name. Calling this 151 // Returns the sequence token associated with the given name. Calling this
150 // function multiple times with the same string will always produce the 152 // function multiple times with the same string will always produce the
151 // same sequence token. If the name has not been used before, a new token 153 // same sequence token. If the name has not been used before, a new token
152 // will be created. 154 // will be created.
153 SequenceToken GetNamedSequenceToken(const std::string& name); 155 SequenceToken GetNamedSequenceToken(const std::string& name);
154 156
157 // Returns a SequencedTaskRunner wrapper for this SequencedWorkerPool and
akalin 2012/03/20 22:16:08 Perhaps clearer: // Returns a SequencedTaskRunner
Francois 2012/03/26 09:33:21 Done.
158 // the specified sequence token.
159 scoped_refptr<SequencedTaskRunner> GetSequencedTaskRunner(
160 SequenceToken token);
161
155 // Posts the given task for execution in the worker pool. Tasks posted with 162 // Posts the given task for execution in the worker pool. Tasks posted with
156 // this function will execute in an unspecified order on a background thread. 163 // this function will execute in an unspecified order on a background thread.
157 // Returns true if the task was posted. If your tasks have ordering 164 // Returns true if the task was posted. If your tasks have ordering
158 // requirements, see PostSequencedWorkerTask(). 165 // requirements, see PostSequencedWorkerTask().
159 // 166 //
160 // This class will attempt to delete tasks that aren't run 167 // This class will attempt to delete tasks that aren't run
161 // (non-block-shutdown semantics) but can't guarantee that this happens. If 168 // (non-block-shutdown semantics) but can't guarantee that this happens. If
162 // all worker threads are busy running CONTINUE_ON_SHUTDOWN tasks, there 169 // all worker threads are busy running CONTINUE_ON_SHUTDOWN tasks, there
163 // will be no workers available to delete these tasks. And there may be 170 // will be no workers available to delete these tasks. And there may be
164 // tasks with the same sequence token behind those CONTINUE_ON_SHUTDOWN 171 // tasks with the same sequence token behind those CONTINUE_ON_SHUTDOWN
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // Avoid pulling in too many headers by putting (almost) everything 263 // Avoid pulling in too many headers by putting (almost) everything
257 // into |inner_|. 264 // into |inner_|.
258 const scoped_ptr<Inner> inner_; 265 const scoped_ptr<Inner> inner_;
259 266
260 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); 267 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool);
261 }; 268 };
262 269
263 } // namespace base 270 } // namespace base
264 271
265 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 272 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698