summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authorokellogg <okellogg@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-03-24 12:27:03 +0000
committerokellogg <okellogg@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-03-24 12:27:03 +0000
commit6b6e65f031ebc3ade30b1db0abb800ceac80755c (patch)
tree56784af0f379e87ebbb4e1c06070d075b1b6629d /ace
parent91cb7119da3c2ea3a0c92d500d513fc4df50d740 (diff)
downloadATCD-6b6e65f031ebc3ade30b1db0abb800ceac80755c.tar.gz
ChangeLogTag:Mon Mar 24 13:16:29 CET 2003 Oliver Kellogg <oliver.kellogg@sysde.eads.net>
Diffstat (limited to 'ace')
-rw-r--r--ace/Node.cpp9
-rw-r--r--ace/Node.h1
-rw-r--r--ace/Unbounded_Set.cpp135
-rw-r--r--ace/Unbounded_Set.h17
-rw-r--r--ace/Unbounded_Set.inl4
5 files changed, 150 insertions, 16 deletions
diff --git a/ace/Node.cpp b/ace/Node.cpp
index 91e989d739b..f13b18cde86 100644
--- a/ace/Node.cpp
+++ b/ace/Node.cpp
@@ -23,14 +23,16 @@ ACE_Node<T>::~ACE_Node (void)
template <class T>
ACE_Node<T>::ACE_Node (const T &i, ACE_Node<T> *n)
: next_ (n),
- item_ (i)
+ item_ (i),
+ deleted_ (false)
{
// ACE_TRACE ("ACE_Node<T>::ACE_Node");
}
template <class T>
ACE_Node<T>::ACE_Node (ACE_Node<T> *n, int)
- : next_ (n)
+ : next_ (n),
+ deleted_ (false)
{
// ACE_TRACE ("ACE_Node<T>::ACE_Node");
}
@@ -38,7 +40,8 @@ ACE_Node<T>::ACE_Node (ACE_Node<T> *n, int)
template <class T>
ACE_Node<T>::ACE_Node (const ACE_Node<T> &s)
: next_ (s.next_),
- item_ (s.item_)
+ item_ (s.item_),
+ deleted_ (false)
{
// ACE_TRACE ("ACE_Node<T>::ACE_Node");
}
diff --git a/ace/Node.h b/ace/Node.h
index 3d69213bf26..65532c65ec5 100644
--- a/ace/Node.h
+++ b/ace/Node.h
@@ -63,6 +63,7 @@ private:
/// Current value of the item in this node.
T item_;
+ bool deleted_;
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
diff --git a/ace/Unbounded_Set.cpp b/ace/Unbounded_Set.cpp
index e1cf0708e6a..cc5fc9ea0a1 100644
--- a/ace/Unbounded_Set.cpp
+++ b/ace/Unbounded_Set.cpp
@@ -88,14 +88,17 @@ ACE_Unbounded_Set<T>::copy_nodes (const ACE_Unbounded_Set<T> &us)
for (ACE_Node<T> *curr = us.head_->next_;
curr != us.head_;
curr = curr->next_)
- this->insert_tail (curr->item_);
+ {
+ if (!curr->deleted_)
+ this->insert_tail (curr->item_);
+ }
}
template <class T> void
ACE_Unbounded_Set<T>::delete_nodes (void)
{
ACE_Node<T> *curr = this->head_->next_;
-
+ ACE_ASSERT (number_of_iterators_ == 0);
// Keep looking until we've hit the dummy node.
while (curr != this->head_)
@@ -113,6 +116,32 @@ ACE_Unbounded_Set<T>::delete_nodes (void)
this->head_->next_ = this->head_;
}
+template <class T> void
+ACE_Unbounded_Set<T>::cleanup ()
+{
+ /// curr is the address of the chaining
+ ACE_Node<T> **curr = &(this->head_->next_);
+ ACE_ASSERT (number_of_iterators_ == 0);
+
+ // Keep looking until we've hit the dummy node.
+ while (*curr != this->head_)
+ {
+ if ((*curr)->deleted_)
+ {
+ ACE_Node<T> *temp = *curr;
+ *curr = (*curr)->next_; // skip the deleted, curr is still the same
+ ACE_DES_FREE_TEMPLATE (temp,
+ this->allocator_->free,
+ ACE_Node,
+ <T>);
+ }
+ else
+ {
+ curr = &((*curr)->next_);
+ }
+ }
+}
+
template <class T>
ACE_Unbounded_Set<T>::~ACE_Unbounded_Set (void)
{
@@ -132,7 +161,8 @@ template <class T>
ACE_Unbounded_Set<T>::ACE_Unbounded_Set (ACE_Allocator *alloc)
: head_ (0),
cur_size_ (0),
- allocator_ (alloc)
+ allocator_ (alloc),
+ number_of_iterators_ (0)
{
// ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set");
@@ -150,7 +180,8 @@ template <class T>
ACE_Unbounded_Set<T>::ACE_Unbounded_Set (const ACE_Unbounded_Set<T> &us)
: head_ (0),
cur_size_ (0),
- allocator_ (us.allocator_)
+ allocator_ (us.allocator_),
+ number_of_iterators_ (0)
{
ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set");
@@ -186,7 +217,7 @@ ACE_Unbounded_Set<T>::find (const T &item) const
ACE_Node<T> *temp = this->head_->next_;
// Keep looping until we find the item.
- while (!(temp->item_ == item))
+ while (!(temp->item_ == item && !temp->deleted_))
temp = temp->next_;
// If we found the dummy node then it's not really there, otherwise,
@@ -221,14 +252,22 @@ ACE_Unbounded_Set<T>::remove (const T &item)
return -1; // Item was not found.
else
{
- ACE_Node<T> *temp = curr->next_;
- // 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_Node<T> *temp = curr->next_;
+ if(number_of_iterators_>0)
+ {
+ temp->deleted_=true;
+ }
+ else
+ {
+ // Skip over the node that we're deleting.
+ curr->next_ = temp->next_;
+
+ ACE_DES_FREE_TEMPLATE (temp,
+ this->allocator_->free,
+ ACE_Node,
+ <T>);
+ }
return 0;
}
}
@@ -247,6 +286,20 @@ ACE_Unbounded_Set<T>::end (void)
return ACE_Unbounded_Set_Iterator<T> (*this, 1);
}
+template <class T> void
+ACE_Unbounded_Set<T>::iterator_add (void)
+{
+ number_of_iterators_++;
+}
+
+template <class T> void
+ACE_Unbounded_Set<T>::iterator_leave (void)
+{
+ ACE_ASSERT (number_of_iterators_>0);
+ number_of_iterators_--;
+ if (number_of_iterators_==0)
+ cleanup ();
+}
ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Iterator)
@@ -262,6 +315,32 @@ ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T>
set_ (&s)
{
// ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator");
+ set_->iterator_add();
+}
+
+template <class T>
+ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator (const ACE_Unbounded_Set_Iterator<T> &o)
+ : current_ (o.current_), set_ (o.set_)
+{
+ set_->iterator_add ();
+}
+
+template <class T> void
+ACE_Unbounded_Set_Iterator<T>::operator= (const ACE_Unbounded_Set_Iterator &o)
+{
+ if (this == &o)
+ return;
+ set_->iterator_leave ();
+ this->set_ = o.set_;
+ this->current_ = o.current_;
+ set_->iterator_add ();
+}
+
+
+template <class T>
+ACE_Unbounded_Set_Iterator<T>::~ACE_Unbounded_Set_Iterator ()
+{
+ set_->iterator_leave ();
}
template <class T> int
@@ -269,6 +348,8 @@ ACE_Unbounded_Set_Iterator<T>::advance (void)
{
// ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::advance");
this->current_ = this->current_->next_;
+ while(this->current_->deleted_ && this->current_ != this->set_->head_)
+ this->current_ = this->current_->next_;
return this->current_ != this->set_->head_;
}
@@ -277,6 +358,8 @@ ACE_Unbounded_Set_Iterator<T>::first (void)
{
// ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::first");
this->current_ = this->set_->head_->next_;
+ while(this->current_->deleted_ && this->current_ != this->set_->head_)
+ this->current_ = this->current_->next_;
return this->current_ != this->set_->head_;
}
@@ -365,6 +448,30 @@ ACE_Unbounded_Set_Const_Iterator<T>::ACE_Unbounded_Set_Const_Iterator (const ACE
set_ (&s)
{
// ACE_TRACE ("ACE_Unbounded_Set_Const_Iterator<T>::ACE_Unbounded_Set_Const_Iterator");
+ set_->iterator_add ();
+}
+
+template <class T>
+ACE_Unbounded_Set_Const_Iterator<T>::ACE_Unbounded_Set_Const_Iterator(const ACE_Unbounded_Set_Const_Iterator<T> &o):current_(o.current_),set_(o.set_)
+{
+ set_->iterator_add ();
+}
+
+template <class T>
+void ACE_Unbounded_Set_Const_Iterator<T>::operator=(const ACE_Unbounded_Set_Const_Iterator& o)
+{
+ if (this == &o)
+ return;
+ set_->iterator_leave ();
+ this->set_ = o.set_;
+ this->current_ = o.current_;
+ set_->iterator_add ();
+}
+
+template <class T>
+ACE_Unbounded_Set_Const_Iterator<T>::~ACE_Unbounded_Set_Const_Iterator()
+{
+ set_->iterator_leave ();
}
template <class T> int
@@ -372,6 +479,8 @@ ACE_Unbounded_Set_Const_Iterator<T>::advance (void)
{
// ACE_TRACE ("ACE_Unbounded_Set_Const_Iterator<T>::advance");
this->current_ = this->current_->next_;
+ while(this->current_->deleted_ && this->current_ != this->set_->head_)
+ this->current_ = this->current_->next_;
return this->current_ != this->set_->head_;
}
@@ -380,6 +489,8 @@ ACE_Unbounded_Set_Const_Iterator<T>::first (void)
{
// ACE_TRACE ("ACE_Unbounded_Set_Const_Iterator<T>::first");
this->current_ = this->set_->head_->next_;
+ while(this->current_->deleted_ && this->current_ != this->set_->head_)
+ this->current_ = this->current_->next_;
return this->current_ != this->set_->head_;
}
diff --git a/ace/Unbounded_Set.h b/ace/Unbounded_Set.h
index d4c882b6f5c..5978cbc819e 100644
--- a/ace/Unbounded_Set.h
+++ b/ace/Unbounded_Set.h
@@ -33,6 +33,9 @@ class ACE_Unbounded_Set_Iterator
public:
// = Initialization method.
ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T> &s, int end = 0);
+ ACE_Unbounded_Set_Iterator (const ACE_Unbounded_Set_Iterator &o);
+ void operator= (const ACE_Unbounded_Set_Iterator &o);
+ ~ACE_Unbounded_Set_Iterator ();
// = Iteration methods.
@@ -92,6 +95,9 @@ class ACE_Unbounded_Set_Const_Iterator
public:
// = Initialization method.
ACE_Unbounded_Set_Const_Iterator (const ACE_Unbounded_Set<T> &s, int end = 0);
+ ACE_Unbounded_Set_Const_Iterator (const ACE_Unbounded_Set_Const_Iterator& o);
+ void operator= (const ACE_Unbounded_Set_Const_Iterator& o);
+ ~ACE_Unbounded_Set_Const_Iterator ();
// = Iteration methods.
@@ -278,6 +284,11 @@ public:
ACE_Unbounded_Set_Iterator<T> begin (void);
ACE_Unbounded_Set_Iterator<T> end (void);
+ /// An Iterator has to register itself here.
+ void iterator_add ();
+ /// An Iterator has to unregister itself here.
+ void iterator_leave ();
+
/// Declare the dynamic allocation hooks.
ACE_ALLOC_HOOK_DECLARE;
@@ -288,6 +299,9 @@ private:
/// Copy nodes into this set.
void copy_nodes (const ACE_Unbounded_Set<T> &);
+ /// Really delete all nodes marked for deletion.
+ void cleanup ();
+
/// Head of the linked list of Nodes.
ACE_Node<T> *head_;
@@ -296,6 +310,9 @@ private:
/// Allocation strategy of the set.
ACE_Allocator *allocator_;
+
+ /// Number of iterators working on this set.
+ int number_of_iterators_;
};
#if defined (__ACE_INLINE__)
diff --git a/ace/Unbounded_Set.inl b/ace/Unbounded_Set.inl
index 3f71cd2b498..fff0a0fcbb5 100644
--- a/ace/Unbounded_Set.inl
+++ b/ace/Unbounded_Set.inl
@@ -5,7 +5,9 @@ template <class T> ACE_INLINE int
ACE_Unbounded_Set<T>::is_empty (void) const
{
ACE_TRACE ("ACE_Unbounded_Set<T>::is_empty");
- return this->head_ == this->head_->next_;
+ // Does not work if deleted elements are in the list:
+ // return this->head_ == this->head_->next_;
+ return size() == 0;
}
template <class T> ACE_INLINE int