diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-07 05:39:31 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-07 05:39:31 +0000 |
commit | d93ad24560fc76f2d7912095aa6efd009a2e9b04 (patch) | |
tree | f05e06b60fcc62435ee9da27a88d5acd47c643af /base/threading | |
parent | cef3ea564024b93a2067742164feed870ee3fef2 (diff) | |
download | chromium_src-d93ad24560fc76f2d7912095aa6efd009a2e9b04.zip chromium_src-d93ad24560fc76f2d7912095aa6efd009a2e9b04.tar.gz chromium_src-d93ad24560fc76f2d7912095aa6efd009a2e9b04.tar.bz2 |
Revert 116816 - Hook up the SequencedWorkerPool to the browser thread.
This does some refactoring of the static data in the browser thread so we only have one global object instead of a bunch fo separate arrays.
It also hooks up the visited link master's I/O to use this new system as a proof of concept.
Review URL: http://codereview.chromium.org/9065009
TBR=brettw@chromium.org
Review URL: http://codereview.chromium.org/9122022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116817 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading')
-rw-r--r-- | base/threading/sequenced_worker_pool.cc | 62 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool.h | 6 |
2 files changed, 15 insertions, 53 deletions
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc index 0a3697b..05ccff1 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -57,31 +57,20 @@ class SequencedWorkerPool::Inner Inner(size_t max_threads, const std::string& thread_name_prefix); virtual ~Inner(); + // Backends for SequenceWorkerPool. SequenceToken GetSequenceToken(); - SequenceToken GetNamedSequenceToken(const std::string& name); - - // This function accepts a name and an ID. If the name is null, the - // token ID is used. This allows us to implement the optional name lookup - // from a single function without having to enter the lock a separate time. - bool PostTask(const std::string* optional_token_name, - int sequence_token_id, + bool PostTask(int sequence_token_id, SequencedWorkerPool::WorkerShutdown shutdown_behavior, const tracked_objects::Location& from_here, const base::Closure& task); - void Shutdown(); - void SetTestingObserver(SequencedWorkerPool::TestingObserver* observer); // Runs the worker loop on the background thread. void ThreadLoop(Worker* this_worker); private: - // Called from within the lock, this converts the given token name into a - // token ID, creating a new one if necessary. - int LockedGetNamedTokenID(const std::string& name); - // The calling code should clear the given delete_these_oustide_lock // vector the next time the lock is released. See the implementation for // a more detailed description. @@ -246,11 +235,18 @@ SequencedWorkerPool::SequenceToken SequencedWorkerPool::Inner::GetNamedSequenceToken( const std::string& name) { base::AutoLock lock(lock_); - return SequenceToken(LockedGetNamedTokenID(name)); + std::map<std::string, int>::const_iterator found = + named_sequence_tokens_.find(name); + if (found != named_sequence_tokens_.end()) + return SequenceToken(found->second); // Got an existing one. + + // Create a new one for this name. + SequenceToken result = GetSequenceToken(); + named_sequence_tokens_.insert(std::make_pair(name, result.id_)); + return result; } bool SequencedWorkerPool::Inner::PostTask( - const std::string* optional_token_name, int sequence_token_id, SequencedWorkerPool::WorkerShutdown shutdown_behavior, const tracked_objects::Location& from_here, @@ -267,10 +263,6 @@ bool SequencedWorkerPool::Inner::PostTask( if (terminating_) return false; - // Now that we have the lock, apply the named token rules. - if (optional_token_name) - sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name); - pending_tasks_.push_back(sequenced); pending_task_count_++; if (shutdown_behavior == BLOCK_SHUTDOWN) @@ -385,22 +377,6 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { cond_var_.Signal(); } -int SequencedWorkerPool::Inner::LockedGetNamedTokenID( - const std::string& name) { - lock_.AssertAcquired(); - DCHECK(!name.empty()); - - std::map<std::string, int>::const_iterator found = - named_sequence_tokens_.find(name); - if (found != named_sequence_tokens_.end()) - return found->second; // Got an existing one. - - // Create a new one for this name. - SequenceToken result = GetSequenceToken(); - named_sequence_tokens_.insert(std::make_pair(name, result.id_)); - return result.id_; -} - bool SequencedWorkerPool::Inner::GetWork( SequencedTask* task, std::vector<base::Closure>* delete_these_outside_lock) { @@ -617,38 +593,30 @@ SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken( bool SequencedWorkerPool::PostWorkerTask( const tracked_objects::Location& from_here, const base::Closure& task) { - return inner_->PostTask(NULL, 0, BLOCK_SHUTDOWN, from_here, task); + return inner_->PostTask(0, BLOCK_SHUTDOWN, from_here, task); } bool SequencedWorkerPool::PostWorkerTaskWithShutdownBehavior( const tracked_objects::Location& from_here, const base::Closure& task, WorkerShutdown shutdown_behavior) { - return inner_->PostTask(NULL, 0, shutdown_behavior, from_here, task); + return inner_->PostTask(0, shutdown_behavior, from_here, task); } bool SequencedWorkerPool::PostSequencedWorkerTask( SequenceToken sequence_token, const tracked_objects::Location& from_here, const base::Closure& task) { - return inner_->PostTask(NULL, sequence_token.id_, BLOCK_SHUTDOWN, + return inner_->PostTask(sequence_token.id_, BLOCK_SHUTDOWN, from_here, task); } -bool SequencedWorkerPool::PostNamedSequencedWorkerTask( - const std::string& token_name, - const tracked_objects::Location& from_here, - const base::Closure& task) { - DCHECK(!token_name.empty()); - return inner_->PostTask(&token_name, 0, BLOCK_SHUTDOWN, from_here, task); -} - bool SequencedWorkerPool::PostSequencedWorkerTaskWithShutdownBehavior( SequenceToken sequence_token, const tracked_objects::Location& from_here, const base::Closure& task, WorkerShutdown shutdown_behavior) { - return inner_->PostTask(NULL, sequence_token.id_, shutdown_behavior, + return inner_->PostTask(sequence_token.id_, shutdown_behavior, from_here, task); } diff --git a/base/threading/sequenced_worker_pool.h b/base/threading/sequenced_worker_pool.h index 71e431c..c6e0560 100644 --- a/base/threading/sequenced_worker_pool.h +++ b/base/threading/sequenced_worker_pool.h @@ -172,12 +172,6 @@ class BASE_EXPORT SequencedWorkerPool { const tracked_objects::Location& from_here, const base::Closure& task); - // Like PostSequencedWorkerTask above, but allows you to specify a named - // token, which saves an extra call to GetNamedSequenceToken. - bool PostNamedSequencedWorkerTask(const std::string& token_name, - const tracked_objects::Location& from_here, - const base::Closure& task); - // Same as PostSequencedWorkerTask but allows specification of the shutdown // behavior. bool PostSequencedWorkerTaskWithShutdownBehavior( |