summaryrefslogtreecommitdiff
path: root/src/WrDiskCache.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/WrDiskCache.cc')
-rw-r--r--src/WrDiskCache.cc27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/WrDiskCache.cc b/src/WrDiskCache.cc
index 9db39fe2..5bc57273 100644
--- a/src/WrDiskCache.cc
+++ b/src/WrDiskCache.cc
@@ -42,15 +42,11 @@
namespace aria2 {
-WrDiskCache::WrDiskCache(size_t limit)
- : limit_(limit),
- total_(0),
- clock_(0)
-{}
+WrDiskCache::WrDiskCache(size_t limit) : limit_(limit), total_(0), clock_(0) {}
WrDiskCache::~WrDiskCache()
{
- if(total_) {
+ if (total_) {
A2_LOG_WARN(fmt("Write disk cache is not empty size=%lu",
static_cast<unsigned long>(total_)));
}
@@ -61,11 +57,12 @@ bool WrDiskCache::add(WrDiskCacheEntry* ent)
ent->setSizeKey(ent->getSize());
ent->setLastUpdate(++clock_);
std::pair<EntrySet::iterator, bool> rv = set_.insert(ent);
- if(rv.second) {
+ if (rv.second) {
total_ += ent->getSize();
ensureLimit();
return true;
- } else {
+ }
+ else {
A2_LOG_WARN(fmt("Found duplicate cache entry a.{size=%lu,clock=%" PRId64
"} b{size=%lu,clock=%" PRId64 "}",
static_cast<unsigned long>((*rv.first)->getSize()),
@@ -78,32 +75,32 @@ bool WrDiskCache::add(WrDiskCacheEntry* ent)
bool WrDiskCache::remove(WrDiskCacheEntry* ent)
{
- if(set_.erase(ent)) {
+ if (set_.erase(ent)) {
A2_LOG_DEBUG(fmt("Removed cache entry size=%lu, clock=%" PRId64,
static_cast<unsigned long>(ent->getSize()),
ent->getLastUpdate()));
total_ -= ent->getSize();
return true;
- } else {
+ }
+ else {
return false;
}
}
bool WrDiskCache::update(WrDiskCacheEntry* ent, ssize_t delta)
{
- if(!set_.erase(ent)) {
+ if (!set_.erase(ent)) {
return false;
}
A2_LOG_DEBUG(fmt("Update cache entry size=%lu, delta=%ld, clock=%" PRId64,
static_cast<unsigned long>(ent->getSize()),
- static_cast<long>(delta),
- ent->getLastUpdate()));
+ static_cast<long>(delta), ent->getLastUpdate()));
ent->setSizeKey(ent->getSize());
ent->setLastUpdate(++clock_);
set_.insert(ent);
- if(delta < 0) {
+ if (delta < 0) {
assert(total_ >= static_cast<size_t>(-delta));
}
total_ += delta;
@@ -113,7 +110,7 @@ bool WrDiskCache::update(WrDiskCacheEntry* ent, ssize_t delta)
void WrDiskCache::ensureLimit()
{
- while(total_ > limit_) {
+ while (total_ > limit_) {
auto i = set_.begin();
WrDiskCacheEntry* ent = *i;
A2_LOG_DEBUG(fmt("Force flush cache entry size=%lu, clock=%" PRId64,