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

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
30 // Runs on the background thread.
31 void BackgroundIO::NotifyController() {
32 controller_->OnIOComplete(this);
33 } 31 }
34 32
35 // --------------------------------------------------------------------------- 33 // ---------------------------------------------------------------------------
36 34
37 InFlightIO::InFlightIO() 35 InFlightIO::InFlightIO()
38 : callback_thread_(base::MessageLoopProxy::current()), 36 : callback_thread_(base::MessageLoopProxy::current()),
39 running_(false), single_thread_(false) { 37 running_(false), single_thread_(false) {
40 } 38 }
41 39
42 InFlightIO::~InFlightIO() { 40 InFlightIO::~InFlightIO() {
43 } 41 }
44 42
43 // Runs on the background thread.
44 void BackgroundIO::NotifyController() {
45 base::AutoLock lock(controller_lock_);
46 if (controller_)
47 controller_->OnIOComplete(this);
48 }
49
45 void InFlightIO::WaitForPendingIO() { 50 void InFlightIO::WaitForPendingIO() {
46 while (!io_list_.empty()) { 51 while (!io_list_.empty()) {
47 // Block the current thread until all pending IO completes. 52 // Block the current thread until all pending IO completes.
48 IOList::iterator it = io_list_.begin(); 53 IOList::iterator it = io_list_.begin();
49 InvokeCallback(*it, true); 54 InvokeCallback(*it, true);
50 } 55 }
51 } 56 }
52 57
58 void InFlightIO::DropPendingIO() {
59 while (!io_list_.empty()) {
60 IOList::iterator it = io_list_.begin();
61 BackgroundIO* operation = *it;
62 operation->Cancel();
63 DCHECK(io_list_.find(operation) != io_list_.end());
64 io_list_.erase(make_scoped_refptr(operation));
65 }
66 }
67
53 // Runs on a background thread. 68 // Runs on a background thread.
54 void InFlightIO::OnIOComplete(BackgroundIO* operation) { 69 void InFlightIO::OnIOComplete(BackgroundIO* operation) {
55 #ifndef NDEBUG 70 #ifndef NDEBUG
56 if (callback_thread_->BelongsToCurrentThread()) { 71 if (callback_thread_->BelongsToCurrentThread()) {
57 DCHECK(single_thread_ || !running_); 72 DCHECK(single_thread_ || !running_);
58 single_thread_ = true; 73 single_thread_ = true;
59 } 74 }
60 #endif 75 #endif
61 76
62 callback_thread_->PostTask(FROM_HERE, 77 callback_thread_->PostTask(FROM_HERE,
(...skipping 17 matching lines...) Expand all
80 OnOperationComplete(operation, cancel_task); 95 OnOperationComplete(operation, cancel_task);
81 } 96 }
82 97
83 // Runs on the primary thread. 98 // Runs on the primary thread.
84 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { 99 void InFlightIO::OnOperationPosted(BackgroundIO* operation) {
85 DCHECK(callback_thread_->BelongsToCurrentThread()); 100 DCHECK(callback_thread_->BelongsToCurrentThread());
86 io_list_.insert(make_scoped_refptr(operation)); 101 io_list_.insert(make_scoped_refptr(operation));
87 } 102 }
88 103
89 } // namespace disk_cache 104 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698