diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-01-14 06:47:54 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-01-14 06:47:54 +0000 |
commit | 6416ffa4a145482060ccde6063808fd4e8a96f61 (patch) | |
tree | 025176f690e688c2fa4842b60439da510f90102d | |
parent | edd06d807229d1f2db75e6b31f5f026323e874c0 (diff) | |
download | ATCD-6416ffa4a145482060ccde6063808fd4e8a96f61.tar.gz |
.
-rw-r--r-- | ace/Cache_Hash_T.cpp | 51 | ||||
-rw-r--r-- | ace/Cache_Hash_T.h | 17 | ||||
-rw-r--r-- | ace/Cache_Heap_T.cpp | 44 | ||||
-rw-r--r-- | ace/Cache_Heap_T.h | 28 | ||||
-rw-r--r-- | ace/Cache_Manager.h | 11 | ||||
-rw-r--r-- | ace/Cache_Manager_T.cpp | 29 | ||||
-rw-r--r-- | ace/Cache_Manager_T.h | 38 | ||||
-rw-r--r-- | ace/Cache_Object.cpp | 70 | ||||
-rw-r--r-- | ace/Cache_Object.h | 40 |
9 files changed, 192 insertions, 136 deletions
diff --git a/ace/Cache_Hash_T.cpp b/ace/Cache_Hash_T.cpp index f0d948e09f2..b1c330d72eb 100644 --- a/ace/Cache_Hash_T.cpp +++ b/ace/Cache_Hash_T.cpp @@ -8,16 +8,16 @@ ACE_RCSID(ace, Cache_Hash_T, "$Id$") -template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> unsigned long +template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> u_long ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::hash (const EXT_ID &ext_id) const { return HASH_FUNC (ext_id) % this->size_; } template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> int -ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::isprime (unsigned long number) const +ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::isprime (u_long number) const { - unsigned long d = 3; + u_long d = 3; if (number <= 2) return (number == 2); @@ -63,19 +63,16 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::ACE_Cache_Hash (ACE_Allocator *alloc, size_t memsize = this->size_ * sizeof (CACHE_BUCKET_MANAGER *); + // @@ James, can you please use the right ACE_* allocation macro here? this->hashtable_ = (CACHE_BUCKET_MANAGER **) this->allocator_->malloc (memsize); if (this->hashtable_) - { - for (size_t i = 0; i < this->size_; i++) - this->hashtable_[i] = 0; - } + for (size_t i = 0; i < this->size_; i++) + this->hashtable_[i] = 0; else - { - this->size_ = 0; - // should indicate something is wrong to the user. - } + // should indicate something is wrong to the user. + this->size_ = 0; } template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> @@ -84,14 +81,13 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::~ACE_Cache_Hash (void) if (this->hashtable_) { for (size_t i = 0; i < this->size_; i++) - { - if (this->hashtable_[i]) - { - ACE_DES_FREE (this->hashtable_[i], this->allocator_->free, - CACHE_BUCKET_MANAGER); - this->hashtable_[i] = 0; - } - } + if (this->hashtable_[i]) + { + ACE_DES_FREE (this->hashtable_[i], this->allocator_->free, + CACHE_BUCKET_MANAGER); + this->hashtable_[i] = 0; + } + this->allocator_->free (this->hashtable_); this->hashtable_ = 0; } @@ -102,7 +98,7 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::~ACE_Cache_Hash (void) template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> int ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::find (const EXT_ID &ext_id) const { - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) return -1; @@ -114,7 +110,7 @@ template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> int ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::find (const EXT_ID &ext_id, ACE_Cache_Object *&int_id) const { - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) return -1; @@ -127,7 +123,7 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::bind (const EXT_ID &ext_id, ACE_Cache_Object *const &int_id) { int result; - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) { @@ -149,7 +145,7 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::trybind (const EXT_ID &ext_id, ACE_Cache_Object *&int_id) { int result; - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) { @@ -173,7 +169,7 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::rebind (const EXT_ID &ext_id, ACE_Cache_Object *&old_int_id) { int result; - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) { @@ -196,7 +192,7 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::rebind (const EXT_ID &ext_id, template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> int ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::unbind (const EXT_ID &ext_id) { - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) return -1; @@ -208,7 +204,7 @@ template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> int ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::unbind (const EXT_ID &ext_id, ACE_Cache_Object *&int_id) { - unsigned long hash_idx = this->hash (ext_id); + u_long hash_idx = this->hash (ext_id); if (this->hashtable_[hash_idx] == 0) return -1; @@ -223,7 +219,4 @@ ACE_Cache_Hash<EXT_ID,HASH_FUNC,EQ_FUNC>::size (void) const return this->size_; } - - - #endif /* UTL_CACHEHASH_T_CPP */ diff --git a/ace/Cache_Hash_T.h b/ace/Cache_Hash_T.h index 12e4703a94a..0fe5ac0f8ab 100644 --- a/ace/Cache_Hash_T.h +++ b/ace/Cache_Hash_T.h @@ -1,16 +1,25 @@ /* -*- c++ -*- */ // $Id$ +// @@ James, please add a standard "header" here like you see in all +// the other ACE headerfiles. + #ifndef ACE_CACHE_HASH_T_H #define ACE_CACHE_HASH_T_H #include "ace/OS.h" + +// @@ James, I think that this #include is wrong... #include "ace_Cache_Object.h" // Forward declaration template <class EXT_ID, class INT_ID, class EQ_FUNC> class ACE_Hash_Bucket_Manager; +// @@ James, can you please update ALL of these classes and methods to +// use the standard ACE commenting style, i.e., add = TITLE and = +// DESCRIPTION headers and comments for each method. + template <class EXT_ID, class HASH_FUNC, class EQ_FUNC> class ACE_Cache_Hash { @@ -40,8 +49,8 @@ public: protected: - virtual unsigned long hash (const EXT_ID &ext_id) const; - int isprime (unsigned long number) const; + virtual u_long hash (const EXT_ID &ext_id) const; + int isprime (u_long number) const; int new_cachebucket (size_t idx); private: @@ -54,6 +63,10 @@ private: }; +// @@ James, please also make sure that you add the +// #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +// stuff as well... (see other template files to see how this works). + #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) #include "ace_Cache_Hash_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ diff --git a/ace/Cache_Heap_T.cpp b/ace/Cache_Heap_T.cpp index aa2f763bb6d..bc1f3f4389d 100644 --- a/ace/Cache_Heap_T.cpp +++ b/ace/Cache_Heap_T.cpp @@ -21,17 +21,16 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::ACE_Cache_Heap (ACE_Allocator *alloc, size_t memsize = this->maxsize_ * sizeof (Cache_Heap_Item *); + // @@ James, can you please use the right ACE_* macro here? this->heap_ = (Cache_Heap_Item **) this->allocator_->malloc (memsize); + if (this->heap_) - { - for (size_t i = 0; i < this->maxsize_; i++) - this->heap_[i] = 0; - } + for (size_t i = 0; i < this->maxsize_; i++) + this->heap_[i] = 0; else - { - this->maxsize_ = 0; - // should indicate something - } + // should indicate something. + this->maxsize_ = 0; + } template <class EXT_ID, class FACT, class H_FN, class E_FN> @@ -40,14 +39,12 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::~ACE_Cache_Heap (void) if (this->heap_ != 0) { for (size_t i = 0; i < this->maxsize_; i++) - { - if (this->heap_[i]) - { - ACE_DES_FREE (this->heap_[i], this->allocator_->free, - Cache_Heap_Item); - this->heap_[i] = 0; - } - } + if (this->heap_[i]) + { + ACE_DES_FREE (this->heap_[i], this->allocator_->free, + Cache_Heap_Item); + this->heap_[i] = 0; + } this->allocator_->free (this->heap_); this->heap_ = 0; } @@ -64,7 +61,7 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::is_empty (void) const template <class EXT_ID, class FACT, class H_FN, class E_FN> int ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::is_full (void) const { - return (this->size_ == this->maxsize_); + return this->size_ == this->maxsize_; } template <class EXT_ID, class FACT, class H_FN, class E_FN> size_t @@ -88,6 +85,7 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::maxsize (Cache_Manager *cm, size_t memsize = new_maxsize * sizeof (Cache_Heap_Item *); + // @@ JAmes, can you please use the right ACE_*_RETURN macro here? Cache_Heap_Item **new_heap = (Cache_Heap_Item **) this->allocator_->malloc (memsize); if (new_heap) @@ -101,6 +99,7 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::maxsize (Cache_Manager *cm, else new_heap[i] = 0; + // @@ James, why is this volatile?! Cache_Heap_Item ** volatile temp = this->heap_; this->heap_ = new_heap; this->maxsize_ = new_maxsize; @@ -143,7 +142,9 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::insert (const EXT_ID &ext_id, ACE_NEW_MALLOC_RETURN (item, (Cache_Heap_Item *) this->allocator_->malloc (sizeof (Cache_Heap_Item)), - Cache_Heap_Item (ext_id, int_id), -1); + Cache_Heap_Item (ext_id, + int_id), + -1); this->insert_i (item); @@ -217,7 +218,8 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::remove (EXT_ID &ext_id, ext_id = item->ext_id_; int_id = item->int_id_; - ACE_DES_FREE (item, this->allocator_->free, Cache_Heap_Item); + ACE_DES_FREE (item, + this->allocator_->free, Cache_Heap_Item); item = 0; return 0; } @@ -228,6 +230,7 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::remove (void *item) if (item == 0) return 0; + // James, please use the right ACE_*_cast() macro here. Cache_Heap_Item *real_item = (Cache_Heap_Item *) item; // Make sure the item is where it thinks it is. @@ -248,6 +251,7 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::adjust (void *item) if (item == 0) return 0; + // James, please use the right ACE_*_cast() macro here. Cache_Heap_Item *real_item = (Cache_Heap_Item *) item; // Make sure the item is where it thinks it is. @@ -260,7 +264,6 @@ ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::adjust (void *item) return 0; } - template <class EXT_ID, class FACT, class H_FN, class E_FN> ACE_Cache_Heap_Item<EXT_ID,FACT,H_FN,E_FN>:: ACE_Cache_Heap_Item (const EXT_ID &ext_id, ACE_Cache_Object *const &int_id) @@ -277,5 +280,4 @@ ACE_Cache_Heap_Item<EXT_ID,FACT,H_FN,E_FN>::priority (void) return this->int_id_->priority (); } - #endif /* ACE_CACHE_HEAP_T_CPP */ diff --git a/ace/Cache_Heap_T.h b/ace/Cache_Heap_T.h index 9c12a051980..6c36460b802 100644 --- a/ace/Cache_Heap_T.h +++ b/ace/Cache_Heap_T.h @@ -1,10 +1,14 @@ /* -*- c++ -*- */ // $Id$ +// @@ James, please add a standard "header" here like you see in all +// the other ACE headerfiles. + #ifndef ACE_CACHE_HEAP_T_H #define ACE_CACHE_HEAP_T_H #include "ace/Malloc.h" +// @@ James, this #include is wrong... #include "ace_Cache_Object.h" // Forward declarations @@ -14,6 +18,9 @@ class ACE_Cache_Manager; template <class EXT_ID, class FACTORY, class HASH_FUNC, class EQ_FUNC> class ACE_Cache_Heap_Item; +// @@ James, can you please update ALL of these classes and methods to +// use the standard ACE commenting style, i.e., add = TITLE and = +// DESCRIPTION headers and comments for each method. template <class EXT_ID, class FACT, class H_FN, class E_FN> class ACE_Cache_Heap @@ -21,11 +28,13 @@ class ACE_Cache_Heap // standalone data structure. { public: + typedef ACE_Cache_Manager<EXT_ID, FACT, H_FN, E_FN> + Cache_Manager; + typedef ACE_Cache_Heap_Item<EXT_ID, FACT, H_FN, E_FN> + Cache_Heap_Item; - typedef ACE_Cache_Manager<EXT_ID, FACT, H_FN, E_FN> Cache_Manager; - typedef ACE_Cache_Heap_Item<EXT_ID, FACT, H_FN, E_FN> Cache_Heap_Item; - - ACE_Cache_Heap (ACE_Allocator *alloc = 0, size_t maxsize = 8192); + ACE_Cache_Heap (ACE_Allocator *alloc = 0, + size_t maxsize = 8192); // maxsize is the total number of objects the in memory cache is // willing to manage @@ -72,30 +81,29 @@ private: size_t size_; Cache_Heap_Item **heap_; - }; template <class EXT_ID, class FACT, class H_FN, class E_FN> class ACE_Cache_Heap_Item { - friend class ACE_Cache_Heap<EXT_ID, FACT, H_FN, E_FN>; public: - ACE_Cache_Heap_Item (const EXT_ID &ext_id, ACE_Cache_Object *const &int_id); - unsigned int priority (void); + u_int priority (void); private: - EXT_ID ext_id_; ACE_Cache_Object *int_id_; size_t heap_idx_; - }; +// @@ James, please also make sure that you add the +// #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +// stuff as well... (see other template files to see how this works). + #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) #include "ace_Cache_Heap_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ diff --git a/ace/Cache_Manager.h b/ace/Cache_Manager.h index 11341b0e0f2..c80edb806b6 100644 --- a/ace/Cache_Manager.h +++ b/ace/Cache_Manager.h @@ -1,6 +1,9 @@ /* -*- c++ -*- */ // $Id$ +// @@ James, please add a standard "header" here like you see in all +// the other ACE headerfiles. + #ifndef ACE_CACHE_MANAGER_H #define ACE_CACHE_MANAGER_H @@ -8,8 +11,13 @@ #include "ace/ACE.h" #include "ace/Synch.h" +// @@ James, this #include is wrong... #include "ace_Cache_Manager_T.h" +// @@ James, can you please update ALL of these classes and methods to +// use the standard ACE commenting style, i.e., add = TITLE and = +// DESCRIPTION headers and comments for each method. + class ACE_String_Hash_Functor { public: @@ -20,6 +28,8 @@ private: int i_; }; +// @@ James, can you put these functors into the same place that the +// ones used by Irfan in the Hash_Map_Manager_Ex file are used?! class ACE_String_Equal_Functor { public: @@ -42,5 +52,4 @@ typedef ACE_Cache_Manager<const char *, ACE_String_Equal_Functor> ACE_String_Counted_Cache_Manager; - #endif /* ACE_CACHE_MANAGER_H */ diff --git a/ace/Cache_Manager_T.cpp b/ace/Cache_Manager_T.cpp index b2867229243..ffabdfa75f5 100644 --- a/ace/Cache_Manager_T.cpp +++ b/ace/Cache_Manager_T.cpp @@ -39,6 +39,8 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> if (this->lowwater_ > this->highwater_) this->lowwater_ = this->highwater_ / 2; + // @@ James, please don't use "magic numbers" like 1024. Make sure + // you use the same symbolic constants as the other places... if (this->maxobjsize_ > (this->highwater_ - this->lowwater_) * 1024) this->maxobjsize_ = (this->highwater_ - this->lowwater_) * (1024/2); @@ -55,6 +57,8 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> (Cache_Hash *) this->allocator_->malloc (sizeof (Cache_Hash)), Cache_Hash (alloc, hashsize)); + // @@ James, please check the ACE_NEW_MALLOC macro -- it should do + // this check and bailout if this->hash_ == 0... if (this->hash_ == 0) { @@ -67,6 +71,9 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> this->allocator_->malloc (sizeof (Cache_Heap)), Cache_Heap (alloc, maxsize)); + // @@ James, please check the ACE_NEW_MALLOC macro -- it should do + // this check and bailout if this->hash_ == 0... + if (this->heap_ == 0) { this->maxsize_ = 0; @@ -77,7 +84,6 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> } } - template <class KEY, class FACTORY, class HASH_FUNC, class EQ_FUNC> int ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> ::open (ACE_Allocator *alloc, @@ -121,6 +127,7 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> if (this->factory_ == 0) this->factory_ = Object_Factory::instance (); + // @@ James, please use the ACE_NEW_MALLOC_RETURN macro here. this->hash_ = (Cache_Hash *) this->allocator_->malloc (sizeof (Cache_Hash)); if (this->hash_ == 0) { @@ -129,9 +136,13 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> return -1; } + + // @@ James, please use the ACE_NEW_*_RETURN macro here. new (this->hash_) Cache_Hash (alloc, hashsize); + // @@ James, please use the ACE_NEW_MALLOC_RETURN macro here. this->heap_ = (Cache_Heap *) this->allocator_->malloc (sizeof (Cache_Heap)); + if (this->heap_ == 0) { errno = ENOMEM; @@ -143,6 +154,8 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> return -1; } + + // @@ James, please use the ACE_NEW_*_RETURN macro here. new (this->heap_) Cache_Heap (alloc, maxsize); return 0; @@ -299,6 +312,7 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> ::MAKE (const void *data, size_t size, ACE_Cache_Object *&obj) { // verify object is within cacheable range + // @@ James, please don't use these magic numbers... if (size/1024 > this->maxobjsize_ || size/1024 < this->minobjsize_) return -1; @@ -308,14 +322,10 @@ ACE_Cache_Manager<KEY,FACTORY,HASH_FUNC,EQ_FUNC> // make sure we have sufficient memory if (this->waterlevel_ + size > this->highwater_ * (1024 * 1024)) - { - do - { - if (this->FLUSH_i () == -1) - return -1; - } - while (this->waterlevel_ > this->lowwater_ * (1024 * 1024)); - } + do + if (this->FLUSH_i () == -1) + return -1; + while (this->waterlevel_ > this->lowwater_ * (1024 * 1024)); obj = this->factory_->create (data, size); if (this->TAKE (obj) == -1) @@ -410,5 +420,4 @@ ACE_Cache_Proxy<KEY, DATA, CACHE_MANAGER>::operator DATA * (void) const return this->data (); } - #endif /* ACE_CACHE_MANAGER_T_CPP */ diff --git a/ace/Cache_Manager_T.h b/ace/Cache_Manager_T.h index 582d5c2c07f..a35ccc70c9c 100644 --- a/ace/Cache_Manager_T.h +++ b/ace/Cache_Manager_T.h @@ -1,15 +1,22 @@ /* -*- c++ -*- */ -// Hey Emacs! This is a C++ file! // $Id$ +// @@ James, please add a standard "header" here like you see in all +// the other ACE headerfiles. + #ifndef ACE_CACHE_MANAGER_T_H #define ACE_CACHE_MANAGER_T_H #include "ace/Singleton.h" #include "ace/Synch.h" +// @@ James, I think that this #include is wrong... #include "ace_Cache_Object.h" +// @@ James, can you please update ALL of these classes and methods to +// use the standard ACE commenting style, i.e., add = TITLE and = +// DESCRIPTION headers and comments for each method. + template <class KEY, class HASH_FUNC, class EQ_FUNC> class ACE_Cache_Hash; template <class KEY, class FACTORY, class HASH_FUNC, class EQ_FUNC> class ACE_Cache_Heap; @@ -17,19 +24,24 @@ class ACE_Cache_Heap; template <class KEY, class FACTORY, class HASH_FUNC, class EQ_FUNC> class ACE_Cache_Manager { - friend class ACE_Cache_Hash<KEY, HASH_FUNC, EQ_FUNC>; friend class ACE_Cache_Heap<KEY, FACTORY, HASH_FUNC, EQ_FUNC>; public: - - typedef ACE_Singleton<FACTORY, ACE_SYNCH_MUTEX> Object_Factory; - typedef ACE_Cache_Hash<KEY, HASH_FUNC, EQ_FUNC> Cache_Hash; - typedef ACE_Cache_Heap<KEY, FACTORY, HASH_FUNC, EQ_FUNC> Cache_Heap; + typedef ACE_Singleton<FACTORY, ACE_SYNCH_MUTEX> + Object_Factory; + typedef ACE_Cache_Hash<KEY, HASH_FUNC, EQ_FUNC> + Cache_Hash; + typedef ACE_Cache_Heap<KEY, FACTORY, HASH_FUNC, EQ_FUNC> + Cache_Heap; ACE_Cache_Manager (ACE_Allocator *alloc = 0, ACE_Cache_Object_Factory *cof = 0, + // @@ James, can you please remove the use of + // explicit constants here and use macros instead + // that can be redefined, a la the ones in OS.h. + size_t hashsize = 1024, // number of hash buckets size_t maxsize = 4096, // max number of in memory // objects @@ -140,10 +152,8 @@ private: Cache_Heap *heap_; ACE_SYNCH_RW_MUTEX lock_; - }; - template <class KEY, class DATA, class CACHE_MANAGER> class ACE_Cache_Proxy { @@ -155,7 +165,10 @@ public: ACE_Cache_Proxy (const KEY &, Cache_Manager * = 0); // Corresponds to a GET - ACE_Cache_Proxy (const KEY &, DATA *, size_t, Cache_Manager * = 0); + ACE_Cache_Proxy (const KEY &, + DATA *, + size_t, + Cache_Manager * = 0); // Corresponds to a U/PUT ~ACE_Cache_Proxy (void); @@ -164,15 +177,16 @@ public: operator DATA * (void) const; private: - ACE_Cache_Object *object_; Cache_Manager *manager_; - }; - +// @@ James, please also make sure that you add the +// #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +// stuff as well... (see other template files to see how this works). #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +// @@ James, this #include is incorrect. #include "ace_Cache_Manager_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ diff --git a/ace/Cache_Object.cpp b/ace/Cache_Object.cpp index c9f0af4e2cf..ae46b14a67b 100644 --- a/ace/Cache_Object.cpp +++ b/ace/Cache_Object.cpp @@ -4,15 +4,17 @@ ACE_RCSID(ace, Cache_Object, "$Id$") -ACE_Cache_Object::ACE_Cache_Object (const void *data, size_t size) +ACE_Cache_Object::ACE_Cache_Object (const void *data, + size_t size) : data_ (data), size_ (size) { this->first_access_ = ACE_OS::time ((time_t *)0); - this->new_last_access_ = this->last_access_ = this->first_access_; + this->last_access_ = this->first_access_; + this->new_last_access_ = this->last_access_; } -ACE_Cache_Object::~ACE_Cache_Object () +ACE_Cache_Object::~ACE_Cache_Object (void) { this->data_ = 0; this->size_ = 0; @@ -30,7 +32,7 @@ ACE_Cache_Object::size (void) const return this->size_; } -unsigned int +u_int ACE_Cache_Object::count (void) const { return this->count_i (); @@ -62,7 +64,7 @@ ACE_Cache_Object::first_access (void) const return this->first_access_; } -unsigned int +u_int ACE_Cache_Object::priority (void) const { return this->priority_i (); @@ -80,9 +82,9 @@ ACE_Cache_Object::heap_item (void *item) this->heap_item_ = item; } - ACE_Referenced_Cache_Object:: -ACE_Referenced_Cache_Object (const void *data, size_t size) +ACE_Referenced_Cache_Object (const void *data, + size_t size) : ACE_Cache_Object (data, size) { } @@ -91,9 +93,10 @@ ACE_Referenced_Cache_Object::~ACE_Referenced_Cache_Object (void) { } -unsigned int +u_int ACE_Referenced_Cache_Object::count_i (void) const { + // @@ James, please use the appropriate ACE_*_cast() macro here. ACE_Referenced_Cache_Object *mutable_this = (ACE_Referenced_Cache_Object *) this; @@ -115,23 +118,23 @@ ACE_Referenced_Cache_Object::release_i (void) return this->count_.release (); } -unsigned int +u_int ACE_Referenced_Cache_Object::priority_i (void) const { - unsigned int priority = ~(0U); + u_int priority = ~(0U); double delta - = ACE_OS::difftime (this->last_access (), this->first_access ()); + = ACE_OS::difftime (this->last_access (), + this->first_access ()); if (delta >= 0.0 && delta < ~(0U)) - priority = (unsigned) delta; + priority = u_int (delta); return priority; } - - ACE_Counted_Cache_Object:: -ACE_Counted_Cache_Object (const void *data, size_t size) +ACE_Counted_Cache_Object (const void *data, + size_t size) : ACE_Cache_Object (data, size), count_ (0), new_count_ (0) @@ -142,11 +145,12 @@ ACE_Counted_Cache_Object::~ACE_Counted_Cache_Object (void) { } -unsigned int +u_int ACE_Counted_Cache_Object::count_i (void) const { - ACE_Counted_Cache_Object *mutable_this = (ACE_Counted_Cache_Object *) this; - + // @@ James, please use the appropriate ACE_*_cast() macro here. + ACE_Counted_Cache_Object *mutable_this = + (ACE_Counted_Cache_Object *) this; { ACE_Guard<ACE_SYNCH_MUTEX> g (mutable_this->lock_); @@ -173,7 +177,7 @@ ACE_Counted_Cache_Object::release_i (void) return 0; } -unsigned int +u_int ACE_Counted_Cache_Object::priority_i (void) const { return this->count_i (); @@ -213,24 +217,31 @@ ACE_Referenced_Cache_Object_Factory } ACE_Cache_Object * -ACE_Referenced_Cache_Object_Factory::create (const void *data, size_t size) +ACE_Referenced_Cache_Object_Factory::create (const void *data, + size_t size) { ACE_Referenced_Cache_Object *obj; size_t obj_size = sizeof (ACE_Referenced_Cache_Object); + ACE_NEW_MALLOC_RETURN (obj, (ACE_Referenced_Cache_Object *) this->allocator_->malloc (obj_size), - ACE_Referenced_Cache_Object (data, size), 0); - + ACE_Referenced_Cache_Object (data, + size), + 0); return obj; } void ACE_Referenced_Cache_Object_Factory::destroy (ACE_Cache_Object *obj) { - ACE_Referenced_Cache_Object *rco = (ACE_Referenced_Cache_Object *) obj; - ACE_DES_FREE (rco, this->allocator_->free, ACE_Referenced_Cache_Object); + // @@ James, please use the appropriate ACE_*_cast() macro here. + ACE_Referenced_Cache_Object *rco = + (ACE_Referenced_Cache_Object *) obj; + ACE_DES_FREE (rco, + this->allocator_->free, + ACE_Referenced_Cache_Object); } ACE_Counted_Cache_Object_Factory @@ -253,7 +264,9 @@ ACE_Counted_Cache_Object_Factory::create (const void *data, size_t size) ACE_NEW_MALLOC_RETURN (obj, (ACE_Counted_Cache_Object *) this->allocator_->malloc (obj_size), - ACE_Counted_Cache_Object (data, size), 0); + ACE_Counted_Cache_Object (data, + size), + 0); return obj; } @@ -261,6 +274,9 @@ ACE_Counted_Cache_Object_Factory::create (const void *data, size_t size) void ACE_Counted_Cache_Object_Factory::destroy (ACE_Cache_Object *obj) { - ACE_Counted_Cache_Object *cco = (ACE_Counted_Cache_Object *) obj; - ACE_DES_FREE (cco, this->allocator_->free, ACE_Counted_Cache_Object); + // @@ James, please use the appropriate ACE_*_cast() macro here. + ACE_Counted_Cache_Object *cco = + (ACE_Counted_Cache_Object *) obj; + ACE_DES_FREE (cco, + this->allocator_->free, ACE_Counted_Cache_Object); } diff --git a/ace/Cache_Object.h b/ace/Cache_Object.h index 985bfb2ead2..f403ec59c89 100644 --- a/ace/Cache_Object.h +++ b/ace/Cache_Object.h @@ -1,6 +1,8 @@ /* -*- c++ -*- */ // $Id$ +// @@ James, please add a standard "header" here like you see in all +// the other ACE headerfiles. #ifndef ACE_CACHE_OBJECT_H #define ACE_CACHE_OBJECT_H @@ -9,6 +11,10 @@ #include "ace/Synch.h" #include "ace/Malloc.h" +// @@ James, can you please update ALL of these classes and methods to +// use the standard ACE commenting style, i.e., add = TITLE and = +// DESCRIPTION headers and comments for each method. + // Cache bucket -- use Hash_Bucket to hold cacheable objects. class ACE_Cache_Object @@ -19,7 +25,7 @@ public: const void *data (void) const; size_t size (void) const; - unsigned int count (void) const; + u_int count (void) const; int acquire (void); int release (void); @@ -27,7 +33,7 @@ public: time_t last_access (void) const; time_t first_access (void) const; - unsigned int priority (void) const; + u_int priority (void) const; enum { ACE_CO_REFERENCED, ACE_CO_COUNTED }; @@ -35,14 +41,12 @@ public: void heap_item (void *item); protected: - - virtual unsigned int count_i (void) const = 0; + virtual u_int count_i (void) const = 0; virtual int acquire_i (void) = 0; virtual int release_i (void) = 0; - virtual unsigned int priority_i (void) const = 0; + virtual u_int priority_i (void) const = 0; private: - const void *data_; size_t size_; @@ -51,7 +55,6 @@ private: time_t new_last_access_; void *heap_item_; - }; class ACE_Referenced_Cache_Object : public ACE_Cache_Object @@ -61,14 +64,12 @@ public: virtual ~ACE_Referenced_Cache_Object (void); protected: - - virtual unsigned int count_i (void) const; + virtual u_int count_i (void) const; virtual int acquire_i (void); virtual int release_i (void); - virtual unsigned int priority_i (void) const; + virtual u_int priority_i (void) const; private: - /* MUTABLE */ ACE_SYNCH_RW_MUTEX count_; }; @@ -78,26 +79,21 @@ public: ACE_Counted_Cache_Object (const void *, size_t); virtual ~ACE_Counted_Cache_Object (void); - protected: - - virtual unsigned int count_i (void) const; + virtual u_int count_i (void) const; virtual int acquire_i (void); virtual int release_i (void); - virtual unsigned int priority_i (void) const; + virtual u_int priority_i (void) const; private: - - unsigned int count_; - unsigned int new_count_; + u_int count_; + u_int new_count_; /* MUTABLE */ ACE_SYNCH_MUTEX lock_; - }; class ACE_Cache_Object_Factory { public: - ACE_Cache_Object_Factory (ACE_Allocator *alloc = 0); virtual ~ACE_Cache_Object_Factory (void); @@ -107,9 +103,7 @@ public: virtual void destroy (ACE_Cache_Object *) = 0; protected: - ACE_Allocator *allocator_; - }; class ACE_Referenced_Cache_Object_Factory : public ACE_Cache_Object_Factory @@ -120,7 +114,6 @@ public: virtual ACE_Cache_Object * create (const void *, size_t); virtual void destroy (ACE_Cache_Object *); - }; class ACE_Counted_Cache_Object_Factory : public ACE_Cache_Object_Factory @@ -131,7 +124,6 @@ public: virtual ACE_Cache_Object * create (const void *, size_t); virtual void destroy (ACE_Cache_Object *); - }; #endif /* UTL_CACHE_OBJECT_H */ |