Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

o new version

o if overfull cache: release items as soon as they get idle.
  • Loading branch information...
commit 7c00d62b0d43945295056fb4293438ae67cf633f 1 parent 562b493
@hzeller authored
Showing with 20 additions and 6 deletions.
  1. +13 −5 file-handler-cache.cc
  2. +6 −0 file-handler-cache.h
  3. +1 −1  fuse-convolve.cc
View
18 file-handler-cache.cc
@@ -66,6 +66,10 @@ void FileHandlerCache::Unpin(const std::string &key) {
CacheMap::iterator found = cache_.find(key);
assert(found != cache_.end());
--found->second->references;
+ // If we are already beyond cache size, clean up as soon as we get idle.
+ if (found->second->references == 0 && cache_.size() > max_size_) {
+ Erase_Locked(found);
+ }
}
void FileHandlerCache::SetObserver(Observer *observer) {
@@ -93,6 +97,13 @@ struct FileHandlerCache::CompareAge {
}
};
+void FileHandlerCache::Erase_Locked(CacheMap::iterator &cache_it) {
+ if (observer_) observer_->RetireHandlerEvent(cache_it->second->handler);
+ delete cache_it->second->handler; // FileHandler
+ delete cache_it->second; // Entry
+ cache_.erase(cache_it);
+}
+
void FileHandlerCache::CleanupOldestUnreferenced_Locked() {
assert(cache_.size() > max_size_); // otherwise we shouldn't have been called
// While this iterating through the whole cache might look expensive,
@@ -110,10 +121,7 @@ void FileHandlerCache::CleanupOldestUnreferenced_Locked() {
CompareAge comparator;
std::sort(for_removal.begin(), for_removal.end(), comparator);
for (size_t i = 0; i < to_erase_count; ++i) {
- CacheMap::iterator &cache_it = for_removal[i];
- if (observer_) observer_->RetireHandlerEvent(cache_it->second->handler);
- delete cache_it->second->handler; // FileHandler
- delete cache_it->second; // Entry
- cache_.erase(cache_it);
+ Erase_Locked(for_removal[i]);
}
}
+
View
6 file-handler-cache.h
@@ -68,6 +68,12 @@ class FileHandlerCache {
struct CompareAge;
typedef std::map<std::string, Entry*> CacheMap;
+ // -- methods called while holding the mutex.
+
+ // Inform observer, delete FileFilter and erase element from cache.
+ void Erase_Locked(CacheMap::iterator &cache_it);
+
+ // Find oldes element and get rid of it.
void CleanupOldestUnreferenced_Locked();
const size_t max_size_;
View
2  fuse-convolve.cc
@@ -22,7 +22,7 @@
// Use latest version.
#define FUSE_USE_VERSION 26
-#define FUSE_CONVOLVE_VERSION_INFO "v. 0.77 &mdash; 2012-09-14"
+#define FUSE_CONVOLVE_VERSION_INFO "v. 0.78 &mdash; 2012-09-15"
#include <fuse.h>
#include <stdio.h>
Please sign in to comment.
Something went wrong with that request. Please try again.