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

Side by Side Diff: net/disk_cache/in_flight_io.cc

Issue 9702059: Disk cache: Remove all non essential synchronization from the cache destructor. (Closed) Base URL: svn://svn.chromium.org/chrome/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) 2011 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 #include "net/disk_cache/in_flight_io.h" 5 #include "net/disk_cache/in_flight_io.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace disk_cache { 11 namespace disk_cache {
12 12
13 BackgroundIO::BackgroundIO(InFlightIO* controller) 13 BackgroundIO::BackgroundIO(InFlightIO* controller)
14 : controller_(controller), result_(-1), io_completed_(true, false) { 14 : result_(-1), io_completed_(true, false), controller_(controller) {
15 } 15 }
16 16
17 // Runs on the primary thread. 17 // Runs on the primary thread.
18 void BackgroundIO::OnIOSignalled() { 18 void BackgroundIO::OnIOSignalled() {
19 if (controller_) 19 if (controller_)
20 controller_->InvokeCallback(this, false); 20 controller_->InvokeCallback(this, false);
21 } 21 }
22 22
23 void BackgroundIO::Cancel() { 23 void BackgroundIO::Cancel() {
24 // controller_ may be in use from the background thread at this time.
25 base::AutoLock lock(controller_lock_);
24 DCHECK(controller_); 26 DCHECK(controller_);
25 controller_ = NULL; 27 controller_ = NULL;
26 } 28 }
27 29
28 BackgroundIO::~BackgroundIO() {} 30 BackgroundIO::~BackgroundIO() {}
29 31
30 // Runs on the background thread.
31 void BackgroundIO::NotifyController() {
32 controller_->OnIOComplete(this);
33 }
34
35 // --------------------------------------------------------------------------- 32 // ---------------------------------------------------------------------------
36 33
37 InFlightIO::InFlightIO() 34 InFlightIO::InFlightIO()
38 : callback_thread_(base::MessageLoopProxy::current()), 35 : callback_thread_(base::MessageLoopProxy::current()),
39 running_(false), single_thread_(false) { 36 running_(false), single_thread_(false) {
40 } 37 }
41 38
42 InFlightIO::~InFlightIO() { 39 InFlightIO::~InFlightIO() {
43 } 40 }
44 41
42 // Runs on the background thread.
43 void BackgroundIO::NotifyController() {
44 base::AutoLock lock(controller_lock_);
45 if (controller_)
46 controller_->OnIOComplete(this);
47 }
48
45 void InFlightIO::WaitForPendingIO() { 49 void InFlightIO::WaitForPendingIO() {
46 while (!io_list_.empty()) { 50 while (!io_list_.empty()) {
47 // Block the current thread until all pending IO completes. 51 // Block the current thread until all pending IO completes.
48 IOList::iterator it = io_list_.begin(); 52 IOList::iterator it = io_list_.begin();
49 InvokeCallback(*it, true); 53 InvokeCallback(*it, true);
50 } 54 }
51 } 55 }
52 56
57 void InFlightIO::DropPendingIO() {
58 while (!io_list_.empty()) {
59 IOList::iterator it = io_list_.begin();
60 BackgroundIO* operation = *it;
61 operation->Cancel();
62 DCHECK(io_list_.find(operation) != io_list_.end());
63 io_list_.erase(make_scoped_refptr(operation));
64 }
65 }
66
53 // Runs on a background thread. 67 // Runs on a background thread.
54 void InFlightIO::OnIOComplete(BackgroundIO* operation) { 68 void InFlightIO::OnIOComplete(BackgroundIO* operation) {
55 #ifndef NDEBUG 69 #ifndef NDEBUG
56 if (callback_thread_->BelongsToCurrentThread()) { 70 if (callback_thread_->BelongsToCurrentThread()) {
57 DCHECK(single_thread_ || !running_); 71 DCHECK(single_thread_ || !running_);
58 single_thread_ = true; 72 single_thread_ = true;
59 } 73 }
60 #endif 74 #endif
61 75
62 callback_thread_->PostTask(FROM_HERE, 76 callback_thread_->PostTask(FROM_HERE,
(...skipping 17 matching lines...) Expand all
80 OnOperationComplete(operation, cancel_task); 94 OnOperationComplete(operation, cancel_task);
81 } 95 }
82 96
83 // Runs on the primary thread. 97 // Runs on the primary thread.
84 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { 98 void InFlightIO::OnOperationPosted(BackgroundIO* operation) {
85 DCHECK(callback_thread_->BelongsToCurrentThread()); 99 DCHECK(callback_thread_->BelongsToCurrentThread());
86 io_list_.insert(make_scoped_refptr(operation)); 100 io_list_.insert(make_scoped_refptr(operation));
87 } 101 }
88 102
89 } // namespace disk_cache 103 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698