#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 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 | |
| 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 | |
| ACE_Filecache * | cvf_ = 0 |
| The reference to the instance. | |
Definition at line 165 of file Filecache.h.
|
|
Definition at line 202 of file Filecache.h.
00203 {
00204 /// For this stupid implementation, use an array. Someday, use a
00205 /// balanced search tree, or real hash table.
00206 ACE_DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE = 512,
00207
00208 /// This determines the highwater mark in megabytes for the cache.
00209 /// This will be ignored for now.
00210 ACE_DEFAULT_VIRTUAL_FILESYSTEM_CACHE_SIZE = 20
00211 };
|
|
|
Definition at line 236 of file Filecache.cpp.
00237 {
00238 }
|
|
|
Prevent it from being called.
Definition at line 230 of file Filecache.cpp.
|
|
||||||||||||
|
Create a new Filecache_Object, returns it.
Definition at line 383 of file Filecache.cpp. References ACE_NEW_RETURN, ACE_OFF_T, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_Filecache_Object::acquire(), file_lock_, and ACE::hash_pjw(). Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle().
00384 {
00385 ACE_Filecache_Object *handle = 0;
00386
00387 ACE_OFF_T loc = ACE::hash_pjw (filename) % this->size_;
00388 ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc];
00389
00390 ACE_NEW_RETURN (handle,
00391 ACE_Filecache_Object (filename, size, filelock),
00392 0);
00393 handle->acquire ();
00394
00395 return handle;
00396 }
|
|
||||||||||||
|
Return the file associated with ``filename'' if it is in the cache, or create if not. Definition at line 335 of file Filecache.cpp. References ACE_OFF_T, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_WRITE_GUARD_RETURN, file_lock_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), hash_, hash_lock_, ACE::hash_pjw(), insert_i(), ACE_Filecache_Object::update(), and update_i(). Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle().
00336 {
00337 ACE_Filecache_Object *handle = 0;
00338
00339 ACE_OFF_T loc = ACE::hash_pjw (filename) % this->size_;
00340 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc];
00341 ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc];
00342
00343 filelock.acquire_read ();
00344
00345 if (this->hash_.find (filename, handle) == -1)
00346 {
00347 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00348 ace_mon,
00349 hashlock,
00350 0);
00351
00352 // Second check in the method call
00353 handle = this->insert_i (filename, filelock, mapit);
00354
00355 if (handle == 0)
00356 filelock.release ();
00357 }
00358 else
00359 {
00360 if (handle->update ())
00361 {
00362 {
00363 // Double check locking pattern
00364 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00365 ace_mon,
00366 hashlock,
00367 0);
00368
00369 // Second check in the method call
00370 handle = this->update_i (filename, filelock, mapit);
00371
00372 if (handle == 0)
00373 filelock.release ();
00374 }
00375 }
00376 // ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) CVF: found %s\n"), filename));
00377 }
00378
00379 return handle;
00380 }
|
|
|
Returns 0 if the file associated with ``filename'' is in the cache, or -1 if not. Definition at line 305 of file Filecache.cpp. References ACE_TCHAR, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), and hash_.
|
|
|
Release an acquired Filecache_Object, returns it again or NULL if it was deleted. Definition at line 399 of file Filecache.cpp. References ACE_OFF_T, ACE_SYNCH_RW_MUTEX, ACE_WRITE_GUARD_RETURN, ACE_Filecache_Object::acquire(), ACE_Filecache_Object::action_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::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(), and ACE_Filecache_Object::stale_. Referenced by ACE_Filecache_Handle::~ACE_Filecache_Handle().
00400 {
00401 if (file == 0)
00402 return file;
00403
00404 ACE_OFF_T loc = ACE::hash_pjw (file->filename_) % this->size_;
00405 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc];
00406
00407 if (file != 0)
00408 switch (file->action_)
00409 {
00410 case ACE_Filecache_Object::ACE_WRITING:
00411 {
00412 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00413 ace_mon,
00414 hashlock,
00415 0);
00416
00417 file->release ();
00418
00419 this->remove_i (file->filename_);
00420 #if 0
00421 int result = this->hash_.bind (file->filename (), file);
00422
00423 if (result == 0)
00424 file->acquire ();
00425 #else
00426 // Last one using a stale file is resposible for deleting it.
00427 if (file->stale_)
00428 {
00429 // Try a lock. If it succeds, we can delete it now.
00430 // Otherwise, it will clean itself up later.
00431 if (file->lock_.tryacquire_write () == 0)
00432 {
00433 delete file;
00434 file = 0;
00435 }
00436 }
00437 #endif
00438 }
00439
00440 break;
00441 default:
00442 file->release ();
00443
00444 // Last one using a stale file is resposible for deleting it.
00445 if (file->stale_)
00446 {
00447 // Try a lock. If it succeds, we can delete it now.
00448 // Otherwise, it will clean itself up later.
00449 if (file->lock_.tryacquire_write () == 0)
00450 {
00451 delete file;
00452 file = 0;
00453 }
00454 }
00455
00456 break;
00457 }
00458
00459 return file;
00460 }
|
|
||||||||||||||||
|
Definition at line 241 of file Filecache.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::bind(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), and hash_. Referenced by fetch(), and update_i().
00244 {
00245 ACE_Filecache_Object *handle = 0;
00246
00247 if (this->hash_.find (filename, handle) == -1)
00248 {
00249 ACE_NEW_RETURN (handle,
00250 ACE_Filecache_Object (filename, filelock, 0, mapit),
00251 0);
00252
00253 // ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) CVF: creating %s\n"), filename));
00254
00255 if (this->hash_.bind (filename, handle) == -1)
00256 {
00257 delete handle;
00258 handle = 0;
00259 }
00260 }
00261 else
00262 handle = 0;
00263
00264 return handle;
00265 }
|
|
|
Singleton pattern.
Definition at line 209 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().
00210 {
00211 // Double check locking pattern.
00212 if (ACE_Filecache::cvf_ == 0)
00213 {
00214 ACE_SYNCH_RW_MUTEX &lock =
00215 *ACE_Managed_Object<ACE_SYNCH_RW_MUTEX>::get_preallocated_object
00216 (ACE_Object_Manager::ACE_FILECACHE_LOCK);
00217 ACE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, lock, 0);
00218
00219 // @@ James, please check each of the ACE_NEW_RETURN calls to
00220 // make sure that it is safe to return if allocation fails.
00221 if (ACE_Filecache::cvf_ == 0)
00222 ACE_NEW_RETURN (ACE_Filecache::cvf_,
00223 ACE_Filecache,
00224 0);
00225 }
00226
00227 return ACE_Filecache::cvf_;
00228 }
|
|
|
Remove the file associated with ``filename'' from the cache.
Definition at line 312 of file Filecache.cpp. References ACE_OFF_T, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_WRITE_GUARD_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), hash_, hash_lock_, ACE::hash_pjw(), and remove_i(). Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle().
00313 {
00314 ACE_Filecache_Object *handle = 0;
00315
00316 ACE_OFF_T loc = ACE::hash_pjw (filename) % this->size_;
00317 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc];
00318 // ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc];
00319
00320 if (this->hash_.find (filename, handle) != -1)
00321 {
00322 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX,
00323 ace_mon,
00324 hashlock,
00325 0);
00326
00327 return this->remove_i (filename);
00328 }
00329
00330 return 0;
00331 }
|
|
|
Definition at line 268 of file Filecache.cpp. References ACE_TCHAR, hash_, ACE_Filecache_Object::lock_, ACE_Filecache_Object::stale_, and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::unbind(). Referenced by finish(), remove(), and update_i().
00269 {
00270 ACE_Filecache_Object *handle = 0;
00271
00272 // Disassociate file from the cache.
00273 if (this->hash_.unbind (filename, handle) == 0)
00274 {
00275 handle->stale_ = 1;
00276
00277 // Try a lock. If it succeeds, we can delete it now.
00278 // Otherwise, it will clean itself up later.
00279 if (handle->lock_.tryacquire_write () == 0)
00280 {
00281 delete handle;
00282 handle = 0;
00283 }
00284 }
00285 else
00286 handle = 0;
00287
00288 return handle;
00289 }
|
|
||||||||||||||||
|
Definition at line 292 of file Filecache.cpp. References ACE_TCHAR, insert_i(), and remove_i(). Referenced by fetch().
00295 {
00296 ACE_Filecache_Object *handle = 0;
00297
00298 handle = this->remove_i (filename);
00299 handle = this->insert_i (filename, filelock, mapit);
00300
00301 return handle;
00302 }
|
|
|
The reference to the instance.
Definition at line 49 of file Filecache.cpp. Referenced by instance(). |
|
|
Definition at line 228 of file Filecache.h. |
|
|
The hash table.
Definition at line 221 of file Filecache.h. Referenced by fetch(), find(), finish(), insert_i(), remove(), and remove_i(). |
|
|
Definition at line 227 of file Filecache.h. |
|
|
Definition at line 218 of file Filecache.h. |
1.3.6