diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-12-06 01:16:28 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-12-06 01:16:28 +0900 |
| commit | 2c5e77f4222f2d0e62c70a321b4b770467e3dae3 (patch) | |
| tree | a461279a9b812da77d08629f30753869cc434fcf /src/Piece.cc | |
| parent | 56c498bcbfa1b7645c75e39142ac9f6c6ca369c6 (diff) | |
Flush cached data on checkout/cancel Segment
This change prevents the cached data from overlap because of BT peers.
Diffstat (limited to 'src/Piece.cc')
| -rw-r--r-- | src/Piece.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Piece.cc b/src/Piece.cc index f1e59cd9..1a667a0e 100644 --- a/src/Piece.cc +++ b/src/Piece.cc @@ -319,6 +319,9 @@ void Piece::removeUser(cuid_t cuid) void Piece::initWrCache(WrDiskCache* diskCache, const SharedHandle<DiskAdaptor>& diskAdaptor) { + if(!diskCache) { + return; + } assert(wrCache_ == 0); wrCache_ = new WrDiskCacheEntry(diskAdaptor); bool rv = diskCache->add(wrCache_); @@ -327,6 +330,9 @@ void Piece::initWrCache(WrDiskCache* diskCache, void Piece::flushWrCache(WrDiskCache* diskCache) { + if(!diskCache) { + return; + } assert(wrCache_); ssize_t size = static_cast<ssize_t>(wrCache_->getSize()); diskCache->update(wrCache_, -size); @@ -335,6 +341,9 @@ void Piece::flushWrCache(WrDiskCache* diskCache) void Piece::clearWrCache(WrDiskCache* diskCache) { + if(!diskCache) { + return; + } assert(wrCache_); ssize_t size = static_cast<ssize_t>(wrCache_->getSize()); diskCache->update(wrCache_, -size); @@ -344,8 +353,11 @@ void Piece::clearWrCache(WrDiskCache* diskCache) void Piece::updateWrCache(WrDiskCache* diskCache, unsigned char* data, size_t offset, size_t len, int64_t goff) { - A2_LOG_DEBUG(fmt("updateWrCache entry=%p", wrCache_)); + if(!diskCache) { + return; + } assert(wrCache_); + A2_LOG_DEBUG(fmt("updateWrCache entry=%p", wrCache_)); WrDiskCacheEntry::DataCell* cell = new WrDiskCacheEntry::DataCell(); cell->goff = goff; cell->data = data; @@ -360,7 +372,7 @@ void Piece::updateWrCache(WrDiskCache* diskCache, unsigned char* data, void Piece::releaseWrCache(WrDiskCache* diskCache) { - if(wrCache_) { + if(diskCache && wrCache_) { diskCache->remove(wrCache_); delete wrCache_; wrCache_ = 0; |
