diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-04-24 20:24:58 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-04-24 20:24:58 +0000 |
commit | 70a5cbfdb25c97454761256a4480403d8db7dd19 (patch) | |
tree | 11a3650a7f967bdc7ac043082c60baf6c1e003cc | |
parent | e59723a9d2364947a53c387648d9774b1547139e (diff) | |
download | ATCD-70a5cbfdb25c97454761256a4480403d8db7dd19.tar.gz |
.
-rw-r--r-- | ChangeLog-99b | 9 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | ace/Containers_T.cpp | 228 | ||||
-rw-r--r-- | ace/Containers_T.h | 17 | ||||
-rw-r--r-- | ace/Containers_T.i | 18 | ||||
-rw-r--r-- | ace/Future.h | 6 |
6 files changed, 187 insertions, 92 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b index f7a40c2b9df..4f951f236ee 100644 --- a/ChangeLog-99b +++ b/ChangeLog-99b @@ -1,3 +1,12 @@ +Sat Apr 24 13:09:27 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/Containers_T.h: Added allocator support to ACE_Array. + Thakns to Paul Francis <pfrancis@dkl.com> for contributing this. + + * ace/Future.h (class ACE_Future): Make sure to mention that + get()'s ACE_Time_Value must be in absolute, not relative, time. + Thanks to Ian MacDonald <ianmacd@bg.com> for reporting this. + Sat Apr 24 07:24:51 1999 David L. Levine <levine@cs.wustl.edu> * tests/Reverse_Lock_Test.cpp: removed ACE_Guard<ACE_SYNCH_MUTEX> @@ -816,6 +816,7 @@ Rene Matteau <matteau@ca.ibm.com> Hans Ridder <ridder@veritas.com> Todd Mullanix <Todd.Mullanix@sylantro.com> Hai Vu <Hai_Vu@Mitel.Com> +Paul Francis <pfrancis@dkl.com> I would particularly like to thank Paul Stephenson, who worked with me at Ericsson and is now at ObjectSpace. Paul devised the recursive diff --git a/ace/Containers_T.cpp b/ace/Containers_T.cpp index 78d7516369c..e08933d5de9 100644 --- a/ace/Containers_T.cpp +++ b/ace/Containers_T.cpp @@ -146,7 +146,7 @@ ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (ACE_Allocator *alloc) this->allocator_ = ACE_Allocator::instance (); ACE_NEW_MALLOC (this->head_, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), ACE_Node<T>); this->head_->next_ = this->head_; } @@ -185,7 +185,7 @@ ACE_Unbounded_Stack<T>::copy_all_nodes (const ACE_Unbounded_Stack<T> &s) { ACE_Node<T> *nptr = temp->next_; ACE_NEW_MALLOC (temp->next_, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), ACE_Node<T> (s_temp->item_, nptr)); temp = temp->next_; } @@ -202,7 +202,7 @@ ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (const ACE_Unbounded_Stack<T> &s) this->allocator_ = ACE_Allocator::instance (); ACE_NEW_MALLOC (this->head_, - (ACE_Node<T>*) this->allocator_->malloc( sizeof (ACE_Node<T>)), + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), ACE_Node<T>); this->head_->next_ = this->head_; @@ -228,8 +228,10 @@ ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack (void) // ACE_TRACE ("ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack"); this->delete_all_nodes (); - ACE_DES_FREE_TEMPLATE (head_, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (head_, + this->allocator_->free, + ACE_Node, + <T>); } template<class T> int @@ -240,8 +242,9 @@ ACE_Unbounded_Stack<T>::push (const T &new_item) ACE_Node<T> *temp; ACE_NEW_MALLOC_RETURN (temp, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T> (new_item, this->head_->next_), -1); + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), + ACE_Node<T> (new_item, this->head_->next_), + -1); this->head_->next_ = temp; this->cur_size_++; @@ -261,8 +264,10 @@ ACE_Unbounded_Stack<T>::pop (T &item) item = temp->item_; this->head_->next_ = temp->next_; - ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (temp, + this->allocator_->free, + ACE_Node, + <T>); this->cur_size_--; return 0; } @@ -318,8 +323,10 @@ ACE_Unbounded_Stack<T>::remove (const T &item) // Skip over the node that we're deleting. curr->next_ = temp->next_; this->cur_size_--; - ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (temp, + this->allocator_->free, + ACE_Node, + <T>); return 0; } } @@ -336,7 +343,7 @@ ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (ACE_Allocator *alloc) this->allocator_ = ACE_Allocator::instance (); ACE_NEW_MALLOC (this->head_, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), ACE_Node<T>); // Make the list circular by pointing it back to itself. @@ -355,7 +362,7 @@ ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (const ACE_Unbounded_Queue<T> &us) this->allocator_ = ACE_Allocator::instance (); ACE_NEW_MALLOC (this->head_, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), ACE_Node<T>); this->head_->next_ = this->head_; this->copy_nodes (us); @@ -438,7 +445,8 @@ ACE_Unbounded_Queue<T>::delete_nodes (void) ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, - ACE_Node, <T>); + ACE_Node, + <T>); this->cur_size_--; } @@ -452,8 +460,10 @@ ACE_Unbounded_Queue<T>::~ACE_Unbounded_Queue (void) // ACE_TRACE ("ACE_Unbounded_Queue<T>::~ACE_Unbounded_Queue (void)"); this->delete_nodes (); - ACE_DES_FREE_TEMPLATE (head_, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (head_, + this->allocator_->free, + ACE_Node, + <T>); this->head_ = 0; } @@ -466,8 +476,9 @@ ACE_Unbounded_Queue<T>::enqueue_head (const T &new_item) // Create a new node that points to the original head. ACE_NEW_MALLOC_RETURN (temp, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T> (new_item, this->head_->next_), -1); + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), + ACE_Node<T> (new_item, this->head_->next_), + -1); // Link this pointer into the front of the list. this->head_->next_ = temp; @@ -488,7 +499,7 @@ ACE_Unbounded_Queue<T>::enqueue_tail (const T &new_item) // Create a new dummy node. ACE_NEW_MALLOC_RETURN (temp, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), ACE_Node<T> (this->head_->next_), -1); // Link this dummy pointer into the list. @@ -514,8 +525,10 @@ ACE_Unbounded_Queue<T>::dequeue_head (T &item) item = temp->item_; this->head_->next_ = temp->next_; - ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (temp, + this->allocator_->free, + ACE_Node, + <T>); --this->cur_size_; return 0; } @@ -771,8 +784,9 @@ ACE_Double_Linked_List<T>::~ACE_Double_Linked_List (void) { this->delete_nodes (); - ACE_DES_FREE (head_, this->allocator_->free, - T); + ACE_DES_FREE (head_, + this->allocator_->free, + T); this->head_ = 0; } @@ -1190,7 +1204,8 @@ ACE_Bounded_Set<T>::ACE_Bounded_Set (void) { ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set"); - ACE_NEW (this->search_structure_, ACE_Bounded_Set<T>::Search_Structure[this->max_size_]); + ACE_NEW (this->search_structure_, + ACE_Bounded_Set<T>::Search_Structure[this->max_size_]); for (size_t i = 0; i < this->max_size_; i++) this->search_structure_[i].is_free_ = 1; @@ -1203,7 +1218,8 @@ ACE_Bounded_Set<T>::ACE_Bounded_Set (const ACE_Bounded_Set<T> &bs) { ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set"); - ACE_NEW (this->search_structure_, ACE_Bounded_Set<T>::Search_Structure[this->max_size_]); + ACE_NEW (this->search_structure_, + ACE_Bounded_Set<T>::Search_Structure[this->max_size_]); for (size_t i = 0; i < this->cur_size_; i++) this->search_structure_[i] = bs.search_structure_[i]; @@ -1237,7 +1253,8 @@ ACE_Bounded_Set<T>::ACE_Bounded_Set (size_t size) max_size_ (size) { ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set"); - ACE_NEW (this->search_structure_, ACE_Bounded_Set<T>::Search_Structure[size]); + ACE_NEW (this->search_structure_, + ACE_Bounded_Set<T>::Search_Structure[size]); for (size_t i = 0; i < this->max_size_; i++) this->search_structure_[i].is_free_ = 1; @@ -1473,7 +1490,8 @@ ACE_Unbounded_Set<T>::insert_tail (const T &item) // Create a new dummy node. ACE_NEW_MALLOC_RETURN (temp, (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T> (this->head_->next_), -1); + ACE_Node<T> (this->head_->next_), + -1); // Link this pointer into the list. this->head_->next_ = temp; @@ -1536,8 +1554,10 @@ ACE_Unbounded_Set<T>::delete_nodes (void) { ACE_Node<T> *temp = curr; curr = curr->next_; - ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (temp, + this->allocator_->free, + ACE_Node, + <T>); this->cur_size_--; } @@ -1553,8 +1573,10 @@ ACE_Unbounded_Set<T>::~ACE_Unbounded_Set (void) this->delete_nodes (); // Delete the dummy node. - ACE_DES_FREE_TEMPLATE (head_, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (head_, + this->allocator_->free, + ACE_Node, + <T>); this->head_ = 0; } @@ -1656,8 +1678,10 @@ ACE_Unbounded_Set<T>::remove (const T &item) // Skip over the node that we're deleting. curr->next_ = temp->next_; this->cur_size_--; - ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, - ACE_Node, <T>); + ACE_DES_FREE_TEMPLATE (temp, + this->allocator_->free, + ACE_Node, + <T>); return 0; } } @@ -1934,9 +1958,11 @@ ACE_Ordered_MultiSet<T>::remove (const T &item) this->cur_size_--; - ACE_DES_FREE_TEMPLATE (node, this->allocator_->free, ACE_DNode, <T>); - - return 0; + ACE_DES_FREE_TEMPLATE (node, + this->allocator_->free, + ACE_DNode, + <T>); + return 0; } return -1; @@ -1999,10 +2025,10 @@ ACE_Ordered_MultiSet<T>::insert_from (const T &item, ACE_DNode<T> *position, // create a new node ACE_DNode<T> *temp; - ACE_NEW_MALLOC_RETURN ( - temp, - (ACE_DNode<T>*) this->allocator_->malloc (sizeof (ACE_DNode<T>)), - ACE_DNode<T> (item), -1); + ACE_NEW_MALLOC_RETURN (temp, + (ACE_DNode<T>*) this->allocator_->malloc (sizeof (ACE_DNode<T>)), + ACE_DNode<T> (item), + -1); // obtain approximate location of the node int result = locate (item, position, position); @@ -2150,20 +2176,23 @@ template <class T> void ACE_Ordered_MultiSet<T>::delete_nodes (void) { // iterate through list, deleting nodes - ACE_DNode<T> *curr = this->head_; - while (curr) - { - ACE_DNode<T> *temp = curr; - curr = curr->next_; - ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, ACE_DNode, <T>); - } + for (ACE_DNode<T> *curr = this->head_; + curr != 0; + ) + { + ACE_DNode<T> *temp = curr; + curr = curr->next_; + ACE_DES_FREE_TEMPLATE (temp, + this->allocator_->free, + ACE_DNode, + <T>); + } this->head_ = 0; this->tail_ = 0; this->cur_size_ = 0; } - ACE_ALLOC_HOOK_DEFINE(ACE_Ordered_MultiSet_Iterator) template <class T> @@ -2194,10 +2223,10 @@ template <class T> T * ACE_DLList<T>::insert_tail (T *new_item) { ACE_DLList_Node *temp1, *temp2; - ACE_NEW_MALLOC_RETURN ( - temp1, - (ACE_DLList_Node *) this->allocator_->malloc (sizeof (ACE_DLList_Node)), - ACE_DLList_Node ((void *&)new_item), 0); + ACE_NEW_MALLOC_RETURN (temp1, + (ACE_DLList_Node *) this->allocator_->malloc (sizeof (ACE_DLList_Node)), + ACE_DLList_Node ((void *&)new_item), + 0); temp2 = ACE_DLList_Base::insert_tail (temp1); return (T *) (temp2 ? temp2->item_ : 0); @@ -2221,7 +2250,9 @@ ACE_DLList<T>::delete_head (void) { ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_head (); T *temp2 = (T *) (temp1 ? temp1->item_ : 0); - ACE_DES_FREE (temp1, this->allocator_->free, ACE_DLList_Node); + ACE_DES_FREE (temp1, + this->allocator_->free, + ACE_DLList_Node); return temp2; } @@ -2231,8 +2262,9 @@ ACE_DLList<T>::delete_tail (void) { ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_tail (); T *temp2 = (T *) (temp1 ? temp1->item_ : 0); - ACE_DES_FREE (temp1, this->allocator_->free, ACE_DLList_Node); - + ACE_DES_FREE (temp1, + this->allocator_->free, + ACE_DLList_Node); return temp2; } @@ -2241,26 +2273,49 @@ ACE_DLList<T>::delete_tail (void) // Dynamically initialize an array. template <class T> -ACE_Array_Base<T>::ACE_Array_Base (size_t size) +ACE_Array_Base<T>::ACE_Array_Base (size_t size, + ACE_Allocator *alloc) : max_size_ (size), - cur_size_ (size) + cur_size_ (size), + allocator_ (alloc) { + if (this->allocator_ == 0) + this->allocator_ = ACE_Allocator::instance (); + if (size != 0) - ACE_NEW (this->array_, T[size]); + { + ACE_NEW_MALLOC (this->array_, + (T *) this->allocator_->malloc (size * sizeof (T)), + T); + for (size_t i = 0; i < size; ++i) + new (&array_[i]) T; + } else this->array_ = 0; } template <class T> ACE_Array_Base<T>::ACE_Array_Base (size_t size, - const T &default_value) + const T &default_value, + ACE_Allocator *alloc) : max_size_ (size), - cur_size_ (size) + cur_size_ (size), + allocator_ (alloc) { - ACE_NEW (this->array_, T[size]); + if (this->allocator_ == 0) + this->allocator_ = ACE_Allocator::instance (); + + if (size != 0) + { + ACE_NEW_MALLOC (this->array_, + (T *) this->allocator_->malloc (size * sizeof (T)), + T); - for (size_t i = 0; i < size; i++) - this->array_[i] = default_value; + for (size_t i = 0; i < size; ++i) + new (&array_[i]) T (default_value); + } + else + this->array_ = 0; } // The copy constructor (performs initialization). @@ -2268,12 +2323,18 @@ ACE_Array_Base<T>::ACE_Array_Base (size_t size, template <class T> ACE_Array_Base<T>::ACE_Array_Base (const ACE_Array_Base<T> &s) : max_size_ (s.size ()), - cur_size_ (s.size ()) + cur_size_ (s.size ()), + allocator_ (s.allocator_) { - ACE_NEW (this->array_, T[s.size ()]); + if (this->allocator_ == 0) + this->allocator_ = ACE_Allocator::instance (); + + ACE_NEW_MALLOC (this->array_, + (T *) this->allocator_->malloc (s.size () * sizeof (T)), + T); for (size_t i = 0; i < this->size (); i++) - this->array_[i] = s.array_[i]; + new (&this->array_[i]) T (s.array_[i]); } // Assignment operator (performs assignment). @@ -2287,16 +2348,20 @@ ACE_Array_Base<T>::operator= (const ACE_Array_Base<T> &s) { if (this->max_size_ < s.size ()) { - delete [] this->array_; - ACE_NEW (this->array_, - T[s.size ()]); + ACE_DES_FREE (this->array_, + this->allocator_->free, + T); + + ACE_NEW_MALLOC (this->array_, + (T *) this->allocator_->malloc (s.size () * sizeof (T)), + T); this->max_size_ = s.size (); } this->cur_size_ = s.size (); for (size_t i = 0; i < this->size (); i++) - this->array_[i] = s.array_[i]; + new (&this->array_[i]) T (s.array_[i]); } } @@ -2335,19 +2400,22 @@ ACE_Array_Base<T>::max_size (size_t new_size) { if (new_size > this->max_size_) { - // @@ We should use auto_ptr<>! - T* tmp; - ACE_NEW_RETURN (tmp, - T[new_size], - -1); - - for (size_t i = 0; i < this->cur_size_; ++i) - tmp[i] = this->array_[i]; - - delete[] this->array_; + T *tmp; + + ACE_NEW_MALLOC_RETURN (tmp, + (T *) this->allocator_->malloc (new_size * sizeof (T)), + T, + -1); + for (size_t i = 0; i < cur_size_; ++i) + new (&tmp[i]) T (this->array_[i]); + + ACE_DES_FREE (this->array_, + this->allocator_->free, + T); this->array_ = tmp; this->max_size_ = new_size; } + return 0; } diff --git a/ace/Containers_T.h b/ace/Containers_T.h index e8b8bb16518..318477259de 100644 --- a/ace/Containers_T.h +++ b/ace/Containers_T.h @@ -1398,10 +1398,13 @@ public: // = Initialization and termination methods. - ACE_Array_Base (size_t size = 0); + ACE_Array_Base (size_t size = 0, + ACE_Allocator *alloc = 0); // Dynamically create an uninitialized array. - ACE_Array_Base (size_t size, const T &default_value); + ACE_Array_Base (size_t size, + const T &default_value, + ACE_Allocator *alloc = 0); // Dynamically initialize the entire array to the <default_value>. ACE_Array_Base (const ACE_Array_Base<T> &s); @@ -1476,6 +1479,9 @@ private: T *array_; // Pointer to the array's storage buffer. + ACE_Allocator *allocator_; + // Allocation strategy of the ACE_Array_Base. + friend class ACE_Array_Iterator<T>; }; @@ -1500,10 +1506,13 @@ public: // = Initialization and termination methods. - ACE_Array (size_t size = 0); + ACE_Array (size_t size = 0, + ACE_Allocator* alloc = 0); // Dynamically create an uninitialized array. - ACE_Array (size_t size, const T &default_value); + ACE_Array (size_t size, + const T &default_value, + ACE_Allocator* alloc = 0); // Dynamically initialize the entire array to the <default_value>. ACE_Array (const ACE_Array<T> &s); diff --git a/ace/Containers_T.i b/ace/Containers_T.i index ebca9194910..322080ac2ad 100644 --- a/ace/Containers_T.i +++ b/ace/Containers_T.i @@ -308,7 +308,9 @@ ACE_Ordered_MultiSet<T>::size (void) const template <class T> ACE_INLINE ACE_Array_Base<T>::~ACE_Array_Base (void) { - delete [] this->array_; + ACE_DES_FREE (this->array_, + this->allocator_->free, + T); } template <class T> ACE_INLINE size_t @@ -344,15 +346,17 @@ ACE_Array_Base<T>::operator[] (size_t index) const // **************************************************************** template <class T> ACE_INLINE -ACE_Array<T>::ACE_Array (size_t size) - : ACE_Array_Base<T>(size) +ACE_Array<T>::ACE_Array (size_t size, + ACE_Allocator *alloc) + : ACE_Array_Base<T> (size, alloc) { } template <class T> ACE_INLINE ACE_Array<T>::ACE_Array (size_t size, - const T &default_value) - : ACE_Array_Base<T> (size, default_value) + const T &default_value, + ACE_Allocator *alloc) + : ACE_Array_Base<T> (size, default_value, alloc) { } @@ -451,7 +455,9 @@ template <class T> ACE_INLINE int ACE_DLList<T>::remove (ACE_DLList_Node *n) { int result = ACE_DLList_Base::remove (n); - ACE_DES_FREE (n, this->allocator_->free, ACE_DLList_Node); + ACE_DES_FREE (n, + this->allocator_->free, + ACE_DLList_Node); return result; } diff --git a/ace/Future.h b/ace/Future.h index 36d65b46cb0..e512f627f26 100644 --- a/ace/Future.h +++ b/ace/Future.h @@ -73,7 +73,8 @@ private: int get (T &value, ACE_Time_Value *tv); - // Wait up to <tv> time to get the <value>. + // Wait up to <tv> time to get the <value>. Note that <tv> must be + // specified in absolute time rather than relative time. operator T (); // Type conversion. will block forever until the result is @@ -160,7 +161,8 @@ public: int get (T &value, ACE_Time_Value *tv = 0); - // Wait up to <tv> time to get the <value>. + // Wait up to <tv> time to get the <value>. Note that <tv> must be + // specified in absolute time rather than relative time. operator T (); // Type conversion, which obtains the result of the asynchronous |