diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 23:24:06 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 23:24:06 +0000 |
commit | 3b93902e179c52cc8ed7af074427faf1f9409adf (patch) | |
tree | 1b5e6154ca27a2506e5730455454cc07d2c5bb9d /net/disk_cache/in_flight_io.cc | |
parent | 94a922b85962d298dbc5e66e88862e060a731eff (diff) | |
download | chromium_src-3b93902e179c52cc8ed7af074427faf1f9409adf.zip chromium_src-3b93902e179c52cc8ed7af074427faf1f9409adf.tar.gz chromium_src-3b93902e179c52cc8ed7af074427faf1f9409adf.tar.bz2 |
Disk cache: Switch the disk cache to use the cache_thread.
Add an InFlightBackendIO class that handles posting of
cacheoperations back and forth between the IO thread and
the cachethread.
BUG=26730
TEST=unit tests
Review URL: http://codereview.chromium.org/2829008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/in_flight_io.cc')
-rw-r--r-- | net/disk_cache/in_flight_io.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/net/disk_cache/in_flight_io.cc b/net/disk_cache/in_flight_io.cc new file mode 100644 index 0000000..09179ab --- /dev/null +++ b/net/disk_cache/in_flight_io.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/disk_cache/in_flight_io.h" + +#include "base/logging.h" + +namespace disk_cache { + +// Runs on the IO thread. +void BackgroundIO::OnIOSignalled() { + if (controller_) + controller_->InvokeCallback(this, false); +} + +void BackgroundIO::Cancel() { + DCHECK(controller_); + controller_ = NULL; +} + +// Runs on the background thread. +void BackgroundIO::NotifyController() { + controller_->OnIOComplete(this); +} + +// --------------------------------------------------------------------------- + +void InFlightIO::WaitForPendingIO() { + while (!io_list_.empty()) { + // Block the current thread until all pending IO completes. + IOList::iterator it = io_list_.begin(); + InvokeCallback(*it, true); + } +} + +// Runs on a background thread. +void InFlightIO::OnIOComplete(BackgroundIO* operation) { + callback_thread_->PostTask(FROM_HERE, + NewRunnableMethod(operation, + &BackgroundIO::OnIOSignalled)); + operation->io_completed()->Signal(); +} + +// Runs on the IO thread. +void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) { + operation->io_completed()->Wait(); + + if (cancel_task) + operation->Cancel(); + + // Make sure that we remove the operation from the list before invoking the + // callback (so that a subsequent cancel does not invoke the callback again). + DCHECK(io_list_.find(operation) != io_list_.end()); + io_list_.erase(operation); + OnOperationComplete(operation, cancel_task); +} + +// Runs on the IO thread. +void InFlightIO::OnOperationPosted(BackgroundIO* operation) { + io_list_.insert(operation); +} + +} // namespace disk_cache |