#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 | |
int | 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 235 of file Filecache.cpp.
00236 { 00237 } |
|
Prevent it from being called.
Definition at line 229 of file Filecache.cpp.
|
|
Create a new Filecache_Object, returns it.
Definition at line 382 of file Filecache.cpp. References ACE_NEW_RETURN, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_Filecache_Object::acquire(), file_lock_, and ACE::hash_pjw(). Referenced by ACE_Filecache_Handle::ACE_Filecache_Handle().
00383 { 00384 ACE_Filecache_Object *handle = 0; 00385 00386 u_long loc = ACE::hash_pjw (filename) % this->size_; 00387 ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc]; 00388 00389 ACE_NEW_RETURN (handle, 00390 ACE_Filecache_Object (filename, size, filelock), 00391 0); 00392 handle->acquire (); 00393 00394 return handle; 00395 } |
|
Return the file associated with ``filename'' if it is in the cache, or create if not. Definition at line 334 of file Filecache.cpp. References 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().
00335 { 00336 ACE_Filecache_Object *handle = 0; 00337 00338 u_long loc = ACE::hash_pjw (filename) % this->size_; 00339 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc]; 00340 ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc]; 00341 00342 filelock.acquire_read (); 00343 00344 if (this->hash_.find (filename, handle) == -1) 00345 { 00346 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, 00347 ace_mon, 00348 hashlock, 00349 0); 00350 00351 // Second check in the method call 00352 handle = this->insert_i (filename, filelock, mapit); 00353 00354 if (handle == 0) 00355 filelock.release (); 00356 } 00357 else 00358 { 00359 if (handle->update ()) 00360 { 00361 { 00362 // Double check locking pattern 00363 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, 00364 ace_mon, 00365 hashlock, 00366 0); 00367 00368 // Second check in the method call 00369 handle = this->update_i (filename, filelock, mapit); 00370 00371 if (handle == 0) 00372 filelock.release (); 00373 } 00374 } 00375 // ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" (%t) CVF: found %s\n"), filename)); 00376 } 00377 00378 return handle; 00379 } |
|
Returns 0 if the file associated with ``filename'' is in the cache, or -1 if not. Definition at line 304 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 398 of file Filecache.cpp. References 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().
00399 { 00400 if (file == 0) 00401 return file; 00402 00403 u_long loc = ACE::hash_pjw (file->filename_) % this->size_; 00404 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc]; 00405 00406 if (file != 0) 00407 switch (file->action_) 00408 { 00409 case ACE_Filecache_Object::ACE_WRITING: 00410 { 00411 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, 00412 ace_mon, 00413 hashlock, 00414 0); 00415 00416 file->release (); 00417 00418 this->remove_i (file->filename_); 00419 #if 0 00420 int result = this->hash_.bind (file->filename (), file); 00421 00422 if (result == 0) 00423 file->acquire (); 00424 #else 00425 // Last one using a stale file is resposible for deleting it. 00426 if (file->stale_) 00427 { 00428 // Try a lock. If it succeds, we can delete it now. 00429 // Otherwise, it will clean itself up later. 00430 if (file->lock_.tryacquire_write () == 0) 00431 { 00432 delete file; 00433 file = 0; 00434 } 00435 } 00436 #endif 00437 } 00438 00439 break; 00440 default: 00441 file->release (); 00442 00443 // Last one using a stale file is resposible for deleting it. 00444 if (file->stale_) 00445 { 00446 // Try a lock. If it succeds, we can delete it now. 00447 // Otherwise, it will clean itself up later. 00448 if (file->lock_.tryacquire_write () == 0) 00449 { 00450 delete file; 00451 file = 0; 00452 } 00453 } 00454 00455 break; 00456 } 00457 00458 return file; 00459 } |
|
Definition at line 240 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().
00243 { 00244 ACE_Filecache_Object *handle = 0; 00245 00246 if (this->hash_.find (filename, handle) == -1) 00247 { 00248 ACE_NEW_RETURN (handle, 00249 ACE_Filecache_Object (filename, filelock, 0, mapit), 00250 0); 00251 00252 // ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" (%t) CVF: creating %s\n"), filename)); 00253 00254 if (this->hash_.bind (filename, handle) == -1) 00255 { 00256 delete handle; 00257 handle = 0; 00258 } 00259 } 00260 else 00261 handle = 0; 00262 00263 return handle; 00264 } |
|
Singleton pattern.
Definition at line 208 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().
00209 { 00210 // Double check locking pattern. 00211 if (ACE_Filecache::cvf_ == 0) 00212 { 00213 ACE_SYNCH_RW_MUTEX &lock = 00214 *ACE_Managed_Object<ACE_SYNCH_RW_MUTEX>::get_preallocated_object 00215 (ACE_Object_Manager::ACE_FILECACHE_LOCK); 00216 ACE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, ace_mon, lock, 0); 00217 00218 // @@ James, please check each of the ACE_NEW_RETURN calls to 00219 // make sure that it is safe to return if allocation fails. 00220 if (ACE_Filecache::cvf_ == 0) 00221 ACE_NEW_RETURN (ACE_Filecache::cvf_, 00222 ACE_Filecache, 00223 0); 00224 } 00225 00226 return ACE_Filecache::cvf_; 00227 } |
|
Remove the file associated with ``filename'' from the cache.
Definition at line 311 of file Filecache.cpp. References 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().
00312 { 00313 ACE_Filecache_Object *handle = 0; 00314 00315 u_long loc = ACE::hash_pjw (filename) % this->size_; 00316 ACE_SYNCH_RW_MUTEX &hashlock = this->hash_lock_[loc]; 00317 // ACE_SYNCH_RW_MUTEX &filelock = this->file_lock_[loc]; 00318 00319 if (this->hash_.find (filename, handle) != -1) 00320 { 00321 ACE_WRITE_GUARD_RETURN (ACE_SYNCH_RW_MUTEX, 00322 ace_mon, 00323 hashlock, 00324 0); 00325 00326 return this->remove_i (filename); 00327 } 00328 00329 return 0; 00330 } |
|
Definition at line 267 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().
00268 { 00269 ACE_Filecache_Object *handle = 0; 00270 00271 // Disassociate file from the cache. 00272 if (this->hash_.unbind (filename, handle) == 0) 00273 { 00274 handle->stale_ = 1; 00275 00276 // Try a lock. If it succeds, we can delete it now. 00277 // Otherwise, it will clean itself up later. 00278 if (handle->lock_.tryacquire_write () == 0) 00279 { 00280 delete handle; 00281 handle = 0; 00282 } 00283 } 00284 else 00285 handle = 0; 00286 00287 return handle; 00288 } |
|
Definition at line 291 of file Filecache.cpp. References ACE_TCHAR, insert_i(), and remove_i(). Referenced by fetch().
00294 { 00295 ACE_Filecache_Object *handle = 0; 00296 00297 handle = this->remove_i (filename); 00298 handle = this->insert_i (filename, filelock, mapit); 00299 00300 return handle; 00301 } |
|
The reference to the instance.
Definition at line 48 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. |