A hash table holding the information about entry point into the Cached Virtual Filesystem. On insertion, the reference count is incremented. On destruction, reference count is decremented. More...
#include <Filecache.h>
Public Types | |
enum | { ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE = 512, ACE_DEFAULT_VIRTUAL_FILESYSTEM_CACHE_SIZE = 20 } |
Public Member Functions | |
~ACE_Filecache (void) | |
int | find (const ACE_TCHAR *filename) |
ACE_Filecache_Object * | fetch (const ACE_TCHAR *filename, int mapit=1) |
ACE_Filecache_Object * | remove (const ACE_TCHAR *filename) |
Remove the file associated with ``filename'' from the cache. | |
ACE_Filecache_Object * | create (const ACE_TCHAR *filename, int size) |
Create a new Filecache_Object, returns it. | |
ACE_Filecache_Object * | finish (ACE_Filecache_Object *&new_file) |
Static Public Member Functions | |
static ACE_Filecache * | instance (void) |
Singleton pattern. | |
Protected Member Functions | |
ACE_Filecache_Object * | insert_i (const ACE_TCHAR *filename, ACE_SYNCH_RW_MUTEX &filelock, int mapit) |
ACE_Filecache_Object * | remove_i (const ACE_TCHAR *filename) |
ACE_Filecache_Object * | update_i (const ACE_TCHAR *filename, ACE_SYNCH_RW_MUTEX &filelock, int mapit) |
ACE_Filecache (void) | |
Prevent it from being called. | |
Private Attributes | |
ACE_OFF_T | size_ |
ACE_Filecache_Hash | hash_ |
The hash table. | |
ACE_SYNCH_RW_MUTEX | hash_lock_ [ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE] |
ACE_SYNCH_RW_MUTEX | file_lock_ [ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE] |
Static Private Attributes | |
static ACE_Filecache * | cvf_ |
The reference to the instance. |
A hash table holding the information about entry point into the Cached Virtual Filesystem. On insertion, the reference count is incremented. On destruction, reference count is decremented.
Definition at line 167 of file Filecache.h.
anonymous enum |
Definition at line 204 of file Filecache.h.
{ /// For this stupid implementation, use an array. Someday, use a /// balanced search tree, or real hash table. ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE = 512, /// This determines the highwater mark in megabytes for the cache. /// This will be ignored for now. ACE_DEFAULT_VIRTUAL_FILESYSTEM_CACHE_SIZE = 20 };
ACE_Filecache::~ACE_Filecache | ( | void | ) |
Definition at line 236 of file Filecache.cpp.
{ }
ACE_Filecache::ACE_Filecache | ( | void | ) | [protected] |
Prevent it from being called.
Definition at line 230 of file Filecache.cpp.
: size_ (ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE), hash_ (size_) { }
ACE_Filecache_Object * ACE_Filecache::create | ( | const ACE_TCHAR * | filename, | |
int | size | |||
) |
Create a new Filecache_Object, returns it.
Definition at line 383 of file Filecache.cpp.
{ ACE_Filecache_Object *handle = 0; ACE_OFF_T loc = ACE::hash_pjw (filename) % this->size_; ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc]; ACE_NEW_RETURN (handle, ACE_Filecache_Object (filename, size, filelock), 0); handle->acquire (); return handle; }
ACE_Filecache_Object * ACE_Filecache::fetch | ( | const ACE_TCHAR * | filename, | |
int | mapit = 1 | |||
) |
Return the file associated with ``filename'' if it is in the cache, or create if not.
Definition at line 335 of file Filecache.cpp.
{ ACE_Filecache_Object *handle = 0; ACE_OFF_T loc = ACE::hash_pjw (filename) % this->size_; ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc]; ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc]; filelock.acquire_read (); if (this->hash_.find (filename, handle) == -1) { ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, hashlock, 0); // Second check in the method call handle = this->insert_i (filename, filelock, mapit); if (handle == 0) filelock.release (); } else { if (handle->update ()) { { // Double check locking pattern ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, hashlock, 0); // Second check in the method call handle = this->update_i (filename, filelock, mapit); if (handle == 0) filelock.release (); } } // ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) CVF: found %s\n"), filename)); } return handle; }
int ACE_Filecache::find | ( | const ACE_TCHAR * | filename | ) |
Returns 0 if the file associated with ``filename'' is in the cache, or -1 if not.
Definition at line 305 of file Filecache.cpp.
ACE_Filecache_Object * ACE_Filecache::finish | ( | ACE_Filecache_Object *& | new_file | ) |
Release an acquired Filecache_Object, returns it again or NULL if it was deleted.
Definition at line 399 of file Filecache.cpp.
{ if (file == 0) return file; ACE_OFF_T loc = ACE::hash_pjw (file->filename_) % this->size_; ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc]; if (file != 0) switch (file->action_) { case ACE_Filecache_Object::ACE_WRITING: { ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, hashlock, 0); file->release (); this->remove_i (file->filename_); #if 0 int result = this->hash_.bind (file->filename (), file); if (result == 0) file->acquire (); #else // Last one using a stale file is resposible for deleting it. if (file->stale_) { // Try a lock. If it succeds, we can delete it now. // Otherwise, it will clean itself up later. if (file->lock_.tryacquire_write () == 0) { delete file; file = 0; } } #endif } break; default: file->release (); // Last one using a stale file is resposible for deleting it. if (file->stale_) { // Try a lock. If it succeds, we can delete it now. // Otherwise, it will clean itself up later. if (file->lock_.tryacquire_write () == 0) { delete file; file = 0; } } break; } return file; }
ACE_Filecache_Object * ACE_Filecache::insert_i | ( | const ACE_TCHAR * | filename, | |
ACE_SYNCH_RW_MUTEX & | filelock, | |||
int | mapit | |||
) | [protected] |
Definition at line 241 of file Filecache.cpp.
{ ACE_Filecache_Object *handle = 0; if (this->hash_.find (filename, handle) == -1) { ACE_NEW_RETURN (handle, ACE_Filecache_Object (filename, filelock, 0, mapit), 0); // ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) CVF: creating %s\n"), filename)); if (this->hash_.bind (filename, handle) == -1) { delete handle; handle = 0; } } else handle = 0; return handle; }
ACE_Filecache * ACE_Filecache::instance | ( | void | ) | [static] |
Singleton pattern.
Definition at line 209 of file Filecache.cpp.
{ // Double check locking pattern. if (ACE_Filecache::cvf_ == 0) { ACE_SYNCH_RW_MUTEX &lock = *ACE_Managed_Object<ACE_SYNCH_RW_MUTEX>::get_preallocated_object (ACE_Object_Manager::ACE_FILECACHE_LOCK); ACE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, lock, 0); // @@ James, please check each of the ACE_NEW_RETURN calls to // make sure that it is safe to return if allocation fails. if (ACE_Filecache::cvf_ == 0) ACE_NEW_RETURN (ACE_Filecache::cvf_, ACE_Filecache, 0); } return ACE_Filecache::cvf_; }
ACE_Filecache_Object * ACE_Filecache::remove | ( | const ACE_TCHAR * | filename | ) |
Remove the file associated with ``filename'' from the cache.
Definition at line 312 of file Filecache.cpp.
{ ACE_Filecache_Object *handle = 0; ACE_OFF_T loc = ACE::hash_pjw (filename) % this->size_; ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc]; // ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc]; if (this->hash_.find (filename, handle) != -1) { ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, hashlock, 0); return this->remove_i (filename); } return 0; }
ACE_Filecache_Object * ACE_Filecache::remove_i | ( | const ACE_TCHAR * | filename | ) | [protected] |
Definition at line 268 of file Filecache.cpp.
{ ACE_Filecache_Object *handle = 0; // Disassociate file from the cache. if (this->hash_.unbind (filename, handle) == 0) { handle->stale_ = 1; // Try a lock. If it succeeds, we can delete it now. // Otherwise, it will clean itself up later. if (handle->lock_.tryacquire_write () == 0) { delete handle; handle = 0; } } else handle = 0; return handle; }
ACE_Filecache_Object * ACE_Filecache::update_i | ( | const ACE_TCHAR * | filename, | |
ACE_SYNCH_RW_MUTEX & | filelock, | |||
int | mapit | |||
) | [protected] |
Definition at line 292 of file Filecache.cpp.
{ ACE_Filecache_Object *handle = 0; handle = this->remove_i (filename); handle = this->insert_i (filename, filelock, mapit); return handle; }
ACE_Filecache* ACE_Filecache::cvf_ [static, private] |
The reference to the instance.
Definition at line 226 of file Filecache.h.
ACE_SYNCH_RW_MUTEX ACE_Filecache::file_lock_[ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE] [private] |
Definition at line 230 of file Filecache.h.
ACE_Filecache_Hash ACE_Filecache::hash_ [private] |
The hash table.
Definition at line 223 of file Filecache.h.
ACE_SYNCH_RW_MUTEX ACE_Filecache::hash_lock_[ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE] [private] |
Definition at line 229 of file Filecache.h.
ACE_OFF_T ACE_Filecache::size_ [private] |
Definition at line 220 of file Filecache.h.