#include <Filecache.h>
Collaboration diagram for ACE_Filecache:

Public Types | |
| enum | { ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE = 512, ACE_DEFAULT_VIRTUAL_FILESYSTEM_CACHE_SIZE = 20 } |
Public Methods | |
| ~ACE_Filecache (void) | |
| int | find (const ACE_TCHAR *filename) |
| Returns 0 if the file associated with ``filename'' is in the cache, or -1 if not. More... | |
| ACE_Filecache_Object * | fetch (const ACE_TCHAR *filename, int mapit=1) |
| Return the file associated with ``filename'' if it is in the cache, or create if not. More... | |
| ACE_Filecache_Object * | remove (const ACE_TCHAR *filename) |
| Remove the file associated with ``filename'' from the cache. More... | |
| ACE_Filecache_Object * | create (const ACE_TCHAR *filename, int size) |
| Create a new Filecache_Object, returns it. More... | |
| ACE_Filecache_Object * | finish (ACE_Filecache_Object *&new_file) |
| Release an acquired Filecache_Object, returns it again or NULL if it was deleted. More... | |
Static Public Methods | |
| ACE_Filecache * | instance (void) |
| Singleton pattern. More... | |
Protected Methods | |
| 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. More... | |
Private Attributes | |
| int | size_ |
| ACE_Filecache_Hash | hash_ |
| The hash table. More... | |
| 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 | |
| ACE_Filecache * | cvf_ = 0 |
| The reference to the instance. More... | |
Definition at line 169 of file Filecache.h.
|
|
Definition at line 206 of file Filecache.h.
00207 {
00208 /// For this stupid implementation, use an array. Someday, use a
00209 /// balanced search tree, or real hash table.
00210 ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE = 512,
00211
00212 /// This determines the highwater mark in megabytes for the cache.
00213 /// This will be ignored for now.
00214 ACE_DEFAULT_VIRTUAL_FILESYSTEM_CACHE_SIZE = 20
00215 };
|
|
|
Definition at line 226 of file Filecache.cpp.
00227 {
00228 }
|
|
|
Prevent it from being called.
Definition at line 220 of file Filecache.cpp.
00221 : size_ (ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE), 00222 hash_ (this->size_) 00223 { 00224 } |
|
||||||||||||
|
Create a new Filecache_Object, returns it.
Definition at line 373 of file Filecache.cpp. References ACE_NEW_RETURN, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_Filecache_Object::acquire, file_lock_, ACE::hash_pjw, and size_. Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle.
00374 {
00375 ACE_Filecache_Object *handle = 0;
00376
00377 u_long loc = ACE::hash_pjw (filename) % this->size_;
00378 ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc];
00379
00380 ACE_NEW_RETURN (handle,
00381 ACE_Filecache_Object (filename, size, filelock),
00382 0);
00383 handle->acquire ();
00384
00385 return handle;
00386 }
|
|
||||||||||||
|
Return the file associated with ``filename'' if it is in the cache, or create if not.
Definition at line 325 of file Filecache.cpp. References ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_WRITE_GUARD_RETURN, file_lock_, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::find, hash_, hash_lock_, ACE::hash_pjw, insert_i, size_, ACE_Filecache_Object::update, and update_i. Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle.
00326 {
00327 ACE_Filecache_Object *handle = 0;
00328
00329 u_long loc = ACE::hash_pjw (filename) % this->size_;
00330 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc];
00331 ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc];
00332
00333 filelock.acquire_read ();
00334
00335 if (this->hash_.find (filename, handle) == -1)
00336 {
00337 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00338 ace_mon,
00339 hashlock,
00340 0);
00341
00342 // Second check in the method call
00343 handle = this->insert_i (filename, filelock, mapit);
00344
00345 if (handle == 0)
00346 filelock.release ();
00347 }
00348 else
00349 {
00350 if (handle->update ())
00351 {
00352 {
00353 // Double check locking pattern
00354 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00355 ace_mon,
00356 hashlock,
00357 0);
00358
00359 // Second check in the method call
00360 handle = this->update_i (filename, filelock, mapit);
00361
00362 if (handle == 0)
00363 filelock.release ();
00364 }
00365 }
00366 // ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" (%t) CVF: found %s\n"), filename));
00367 }
00368
00369 return handle;
00370 }
|
|
|
Returns 0 if the file associated with ``filename'' is in the cache, or -1 if not.
Definition at line 295 of file Filecache.cpp. References ACE_TCHAR, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::find, and hash_.
|
|
|
Release an acquired Filecache_Object, returns it again or NULL if it was deleted.
Definition at line 389 of file Filecache.cpp. References ACE_SYNCH_RW_MUTEX, ACE_WRITE_GUARD_RETURN, ACE_Filecache_Object::ACE_WRITING, ACE_Filecache_Object::acquire, ACE_Filecache_Object::action_, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::bind, ACE_Filecache_Object::filename, ACE_Filecache_Object::filename_, hash_, hash_lock_, ACE::hash_pjw, ACE_Filecache_Object::lock_, ACE_Filecache_Object::release, remove_i, size_, and ACE_Filecache_Object::stale_. Referenced by ACE_Filecache_Handle::~ACE_Filecache_Handle.
00390 {
00391 if (file == 0)
00392 return file;
00393
00394 u_long loc = ACE::hash_pjw (file->filename_) % this->size_;
00395 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc];
00396
00397 if (file != 0)
00398 switch (file->action_)
00399 {
00400 case ACE_Filecache_Object::ACE_WRITING:
00401 {
00402 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00403 ace_mon,
00404 hashlock,
00405 0);
00406
00407 file->release ();
00408
00409 this->remove_i (file->filename_);
00410 #if 0
00411 int result = this->hash_.bind (file->filename (), file);
00412
00413 if (result == 0)
00414 file->acquire ();
00415 #else
00416 // Last one using a stale file is resposible for deleting it.
00417 if (file->stale_)
00418 {
00419 // Try a lock. If it succeds, we can delete it now.
00420 // Otherwise, it will clean itself up later.
00421 if (file->lock_.tryacquire_write () == 0)
00422 {
00423 delete file;
00424 file = 0;
00425 }
00426 }
00427 #endif
00428 }
00429
00430 break;
00431 default:
00432 file->release ();
00433
00434 // Last one using a stale file is resposible for deleting it.
00435 if (file->stale_)
00436 {
00437 // Try a lock. If it succeds, we can delete it now.
00438 // Otherwise, it will clean itself up later.
00439 if (file->lock_.tryacquire_write () == 0)
00440 {
00441 delete file;
00442 file = 0;
00443 }
00444 }
00445
00446 break;
00447 }
00448
00449 return file;
00450 }
|
|
||||||||||||||||
|
Definition at line 231 of file Filecache.cpp. References ACE_NEW_RETURN, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::bind, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::find, and hash_. Referenced by fetch, and update_i.
00234 {
00235 ACE_Filecache_Object *handle = 0;
00236
00237 if (this->hash_.find (filename, handle) == -1)
00238 {
00239 ACE_NEW_RETURN (handle,
00240 ACE_Filecache_Object (filename, filelock, 0, mapit),
00241 0);
00242
00243 // ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" (%t) CVF: creating %s\n"), filename));
00244
00245 if (this->hash_.bind (filename, handle) == -1)
00246 {
00247 delete handle;
00248 handle = 0;
00249 }
00250 }
00251 else
00252 handle = 0;
00253
00254 return handle;
00255 }
|
|
|
Singleton pattern.
Definition at line 199 of file Filecache.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_SYNCH_RW_MUTEX, and cvf_. Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle, and ACE_Filecache_Handle::~ACE_Filecache_Handle.
00200 {
00201 // Double check locking pattern.
00202 if (ACE_Filecache::cvf_ == 0)
00203 {
00204 ACE_SYNCH_RW_MUTEX &lock =
00205 *ACE_Managed_Object<ACE_SYNCH_RW_MUTEX>::get_preallocated_object
00206 (ACE_Object_Manager::ACE_FILECACHE_LOCK);
00207 ACE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, lock, 0);
00208
00209 // @@ James, please check each of the ACE_NEW_RETURN calls to
00210 // make sure that it is safe to return if allocation fails.
00211 if (ACE_Filecache::cvf_ == 0)
00212 ACE_NEW_RETURN (ACE_Filecache::cvf_,
00213 ACE_Filecache,
00214 0);
00215 }
00216
00217 return ACE_Filecache::cvf_;
00218 }
|
|
|
Remove the file associated with ``filename'' from the cache.
Definition at line 302 of file Filecache.cpp. References ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_WRITE_GUARD_RETURN, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::find, hash_, hash_lock_, ACE::hash_pjw, remove_i, and size_. Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle.
00303 {
00304 ACE_Filecache_Object *handle = 0;
00305
00306 u_long loc = ACE::hash_pjw (filename) % this->size_;
00307 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc];
00308 // ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc];
00309
00310 if (this->hash_.find (filename, handle) != -1)
00311 {
00312 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00313 ace_mon,
00314 hashlock,
00315 0);
00316
00317 return this->remove_i (filename);
00318 }
00319
00320 return 0;
00321 }
|
|
|
Definition at line 258 of file Filecache.cpp. References ACE_TCHAR, hash_, ACE_Filecache_Object::lock_, ACE_Filecache_Object::stale_, and ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_Filecache_Object *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::unbind. Referenced by finish, remove, and update_i.
00259 {
00260 ACE_Filecache_Object *handle = 0;
00261
00262 // Disassociate file from the cache.
00263 if (this->hash_.unbind (filename, handle) == 0)
00264 {
00265 handle->stale_ = 1;
00266
00267 // Try a lock. If it succeds, we can delete it now.
00268 // Otherwise, it will clean itself up later.
00269 if (handle->lock_.tryacquire_write () == 0)
00270 {
00271 delete handle;
00272 handle = 0;
00273 }
00274 }
00275 else
00276 handle = 0;
00277
00278 return handle;
00279 }
|
|
||||||||||||||||
|
Definition at line 282 of file Filecache.cpp. References ACE_SYNCH_RW_MUTEX, ACE_TCHAR, insert_i, and remove_i. Referenced by fetch.
00285 {
00286 ACE_Filecache_Object *handle = 0;
00287
00288 handle = this->remove_i (filename);
00289 handle = this->insert_i (filename, filelock, mapit);
00290
00291 return handle;
00292 }
|
|
|
The reference to the instance.
Definition at line 39 of file Filecache.cpp. Referenced by instance. |
|
|
Definition at line 232 of file Filecache.h. |
|
|
The hash table.
Definition at line 225 of file Filecache.h. Referenced by fetch, find, finish, insert_i, remove, and remove_i. |
|
|
Definition at line 231 of file Filecache.h. |
|
|
Definition at line 222 of file Filecache.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002