summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbala <balanatarajan@users.noreply.github.com>2001-03-27 21:16:45 +0000
committerbala <balanatarajan@users.noreply.github.com>2001-03-27 21:16:45 +0000
commitc7ab790b60749d6434baa2a6d25c7e484e3a0c4d (patch)
tree5702c2da2272776f83c58714eebc49993faa32f4
parent531dc443ef24bd7b6b6fd2b667d51a2d8d15fada (diff)
downloadATCD-c7ab790b60749d6434baa2a6d25c7e484e3a0c4d.tar.gz
ChangeLogTag: Tue Mar 27 15:08:41 2001 Balachandran Natarajan <bala@cs.wustl.edu>
-rw-r--r--TAO/ChangeLogs/ChangeLog-02a9
-rw-r--r--TAO/tao/Leader_Follower.cpp100
-rw-r--r--TAO/tao/Leader_Follower.h46
-rw-r--r--TAO/tao/Leader_Follower.i14
-rw-r--r--TAO/tao/Wait_On_Leader_Follower.cpp29
5 files changed, 49 insertions, 149 deletions
diff --git a/TAO/ChangeLogs/ChangeLog-02a b/TAO/ChangeLogs/ChangeLog-02a
index efbdd3e5f0f..2f9e47b2a7b 100644
--- a/TAO/ChangeLogs/ChangeLog-02a
+++ b/TAO/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,12 @@
+Tue Mar 27 15:08:41 2001 Balachandran Natarajan <bala@cs.wustl.edu>
+
+ * tao/Wait_On_Leader_Follower.cpp: Added an ACE_TEXT () wrapper
+ for a debug statement. Thanks to Pratt Nick for poiting this
+ out.
+
+ * tao/Leader_Follower.{h,cpp,i}: Reverted the changes for Bug
+ #721. Looks like the fix is causing the ORB to crash.
+
Tue Mar 27 14:20:48 2001 Balachandran Natarajan <bala@cs.wustl.edu>
* orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp: Changed
diff --git a/TAO/tao/Leader_Follower.cpp b/TAO/tao/Leader_Follower.cpp
index 13d9e88fbef..54b04613a25 100644
--- a/TAO/tao/Leader_Follower.cpp
+++ b/TAO/tao/Leader_Follower.cpp
@@ -18,89 +18,17 @@ TAO_Leader_Follower::~TAO_Leader_Follower (void)
this->reactor_ = 0;
}
-TAO_Leader_Follower::TAO_Follower_Node::TAO_Follower_Node (TAO_SYNCH_CONDITION* follower_ptr)
- : follower_ (follower_ptr),
- next_ (0)
-{
-
-}
-
-TAO_Leader_Follower::TAO_Follower_Queue::TAO_Follower_Queue (void)
- : head_ (0),
- tail_ (0)
-{
-
-}
-
-int
-TAO_Leader_Follower::TAO_Follower_Queue::insert (TAO_Follower_Node* node)
-{
- TAO_Follower_Node* curr = 0;
-
- // Check if there is already an existing entry
- for (curr = this->head_;
- curr != 0 && curr != node;
- curr = curr->next_)
- ;
- // An entry exists already in the queue
- if (curr == node)
- return 1;
- else
- {
- // Add the node to the tail and modify the pointers
- TAO_Follower_Node* temp = this->tail_;
- this->tail_ = node;
- if (this->head_ == 0)
- this->head_ = this->tail_;
- else
- temp->next_ = this->tail_;
- }
- return 0;
-}
-
-int
-TAO_Leader_Follower::TAO_Follower_Queue::remove (TAO_Follower_Node* node)
-{
- TAO_Follower_Node* prev = 0;
- TAO_Follower_Node* curr = 0;
-
- // No followers in queue, return
- if (this->head_ == 0)
- return -1;
-
- for (curr = this->head_;
- curr != 0 && curr != node;
- curr = curr->next_)
- {
- prev = curr;
- }
-
- // Entry not found in the queue
- if (curr == 0)
- return -1;
- // Entry found at the head of the queue
- else if (prev == 0)
- this->head_ = this->head_->next_;
- else
- prev->next_ = curr->next_;
- // Entry at the tail
- if (curr->next_ == 0)
- this->tail_ = prev;
-
- return 0;
-}
-
-
TAO_SYNCH_CONDITION*
TAO_Leader_Follower::get_next_follower (void)
{
- // If the queue is empty return
- if (this->follower_set_.is_empty())
- return 0;
+ ACE_Unbounded_Set_Iterator<TAO_SYNCH_CONDITION *> iterator (
+ this->follower_set_);
- TAO_Follower_Node* next_follower = this->follower_set_.head_;
+ if (iterator.first () == 0)
+ // means set is empty
+ return 0;
- TAO_SYNCH_CONDITION *cond = next_follower->follower_;
+ TAO_SYNCH_CONDITION *cond = *iterator;
#if defined (TAO_DEBUG_LEADER_FOLLOWER)
ACE_DEBUG ((LM_DEBUG,
@@ -115,7 +43,7 @@ TAO_Leader_Follower::get_next_follower (void)
// The follower may not be there if the reply is received while the
// consumer is not yet waiting for it (i.e. it send the request but
// has not blocked to receive the reply yet)
- (void) this->remove_follower (next_follower); // Ignore errors..
+ (void) this->remove_follower (cond); // Ignore errors..
return cond;
}
@@ -225,3 +153,17 @@ TAO_Leader_Follower::reset_client_thread (void)
this->orb_core_->reactor ()->end_reactor_event_loop ();
}
}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+
+template class ACE_Node<TAO_SYNCH_CONDITION*>;
+template class ACE_Unbounded_Set<TAO_SYNCH_CONDITION*>;
+template class ACE_Unbounded_Set_Iterator<TAO_SYNCH_CONDITION*>;
+
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+
+#pragma instantiate ACE_Node<TAO_SYNCH_CONDITION*>
+#pragma instantiate ACE_Unbounded_Set<TAO_SYNCH_CONDITION*>
+#pragma instantiate ACE_Unbounded_Set_Iterator<TAO_SYNCH_CONDITION*>
+
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/TAO/tao/Leader_Follower.h b/TAO/tao/Leader_Follower.h
index 7d17e7d447c..570b4802b17 100644
--- a/TAO/tao/Leader_Follower.h
+++ b/TAO/tao/Leader_Follower.h
@@ -20,6 +20,8 @@
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
+#include "ace/Unbounded_Queue.h"
+
class TAO_Export TAO_Leader_Follower
{
public:
@@ -72,25 +74,13 @@ public:
*/
int elect_new_leader (void);
- /// Node structure for the queue of followers
- struct TAO_Follower_Node
- {
- /// Constructor
- TAO_Follower_Node (TAO_SYNCH_CONDITION* follower_ptr);
-
- /// Follower
- TAO_SYNCH_CONDITION *follower_;
-
- /// Pointer to the next follower
- TAO_Follower_Node *next_;
- };
/**
* adds the a follower to the set of followers in the leader-
* follower model
* returns 0 on success, -1 on failure and 1 if the element is
* already there.
*/
- int add_follower (TAO_Follower_Node *follower_ptr);
+ int add_follower (TAO_SYNCH_CONDITION *follower_ptr);
/// checks for the availablity of a follower
/// returns 1 on available, 0 else
@@ -98,7 +88,7 @@ public:
/// removes a follower from the leader-follower set
/// returns 0 on success, -1 on failure
- int remove_follower (TAO_Follower_Node *follower_ptr);
+ int remove_follower (TAO_SYNCH_CONDITION *follower_ptr);
/// returns randomly a follower from the leader-follower set
/// returns follower on success, else 0
@@ -138,32 +128,8 @@ private:
/// do protect the access to the following three members
ACE_Reverse_Lock<TAO_SYNCH_MUTEX> reverse_lock_;
- /// Queue to store the followers.
- struct TAO_Follower_Queue
- {
- /// Constructor
- TAO_Follower_Queue (void);
-
- /// Checks if the queue is empty.
- int is_empty (void) const;
-
- /// Removes a follower from the queue.
- int remove (TAO_Follower_Node *);
-
- /// Inserts a follower into the queue.
- /// Returns 0 on success, -1 for failure, 1 if the element is already
- /// present.
- int insert (TAO_Follower_Node *);
-
- /// Pointer to the head of the queue.
- TAO_Follower_Node *head_;
-
- /// Pointer to the tail of the queue.
- TAO_Follower_Node *tail_;
- };
-
- /// Queue to keep the followers on the stack.
- TAO_Follower_Queue follower_set_;
+ ACE_Unbounded_Set<TAO_SYNCH_CONDITION *> follower_set_;
+ // keep a set of followers around (protected)
/**
* Count the number of active leaders.
diff --git a/TAO/tao/Leader_Follower.i b/TAO/tao/Leader_Follower.i
index db9324ae84d..08a0a301058 100644
--- a/TAO/tao/Leader_Follower.i
+++ b/TAO/tao/Leader_Follower.i
@@ -156,15 +156,15 @@ TAO_Leader_Follower::is_client_leader_thread (void) const
}
ACE_INLINE int
-TAO_Leader_Follower::add_follower (TAO_Follower_Node *follower_node)
+TAO_Leader_Follower::add_follower (TAO_SYNCH_CONDITION *follower_ptr)
{
- return this->follower_set_.insert (follower_node);
+ return this->follower_set_.insert (follower_ptr);
}
ACE_INLINE int
-TAO_Leader_Follower::remove_follower (TAO_Follower_Node *follower_node)
+TAO_Leader_Follower::remove_follower (TAO_SYNCH_CONDITION *follower_ptr)
{
- return this->follower_set_.remove (follower_node);
+ return this->follower_set_.remove (follower_ptr);
}
ACE_INLINE ACE_Reverse_Lock<TAO_SYNCH_MUTEX> &
@@ -179,12 +179,6 @@ TAO_Leader_Follower::has_clients (void) const
return this->clients_;
}
-ACE_INLINE int
-TAO_Leader_Follower::TAO_Follower_Queue::is_empty (void) const
-{
- return this->head_ == 0;
-}
-
ACE_INLINE
TAO_LF_Client_Thread_Helper::TAO_LF_Client_Thread_Helper (TAO_Leader_Follower &leader_follower)
: leader_follower_ (leader_follower)
diff --git a/TAO/tao/Wait_On_Leader_Follower.cpp b/TAO/tao/Wait_On_Leader_Follower.cpp
index 1028b7ed977..cd4f17d0e3a 100644
--- a/TAO/tao/Wait_On_Leader_Follower.cpp
+++ b/TAO/tao/Wait_On_Leader_Follower.cpp
@@ -91,9 +91,6 @@ TAO_Wait_On_Leader_Follower::wait (ACE_Time_Value *max_wait_time,
this->transport_,
cond));
- // Keep the entry on the stack
- TAO_Leader_Follower::TAO_Follower_Node node (cond);
-
while (!reply_received &&
leader_follower.leader_available ())
{
@@ -121,7 +118,7 @@ TAO_Wait_On_Leader_Follower::wait (ACE_Time_Value *max_wait_time,
// lost.
//
- (void) leader_follower.add_follower (&node);
+ (void) leader_follower.add_follower (cond);
if (max_wait_time == 0)
{
@@ -148,10 +145,10 @@ TAO_Wait_On_Leader_Follower::wait (ACE_Time_Value *max_wait_time,
ACE_TEXT ("cond == 0 || cond->wait (tv) == -1\n"),
this->transport_));
- if (leader_follower.remove_follower (&node) == -1)
+ if (leader_follower.remove_follower (cond) == -1)
ACE_ERROR ((LM_ERROR,
"TAO (%P|%t) TAO_Wait_On_Leader_Follower::wait - "
- "remove_follower failed for <%x>\n", node.follower_));
+ "remove_follower failed for <%x>\n", cond));
return -1;
}
@@ -164,16 +161,16 @@ TAO_Wait_On_Leader_Follower::wait (ACE_Time_Value *max_wait_time,
// Cannot remove the follower here, we *must* remove it when
// we signal it so the same condition is not signalled for
// both wake up as a follower and as the next leader.
- if (leader_follower.remove_follower (&node) == -1)
+ if (leader_follower.remove_follower (cond) == -1)
ACE_ERROR ((LM_ERROR,
"TAO (%P|%t) TAO_Wait_On_Leader_Follower::wait - "
- "remove_follower failed for <%x>\n", node.follower));
+ "remove_follower failed for <%x>\n", cond));
#endif /* 0 */
if (TAO_debug_level >= 5)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("TAO (%P|%t) - done (follower) "
- "on <%x>, reply_received %d\n"),
+ ACE_TEXT ("on <%x>, reply_received %d\n")),
this->transport_, reply_received));
// Now somebody woke us up to become a leader or to handle our
@@ -277,7 +274,7 @@ TAO_Wait_On_Leader_Follower::wait (ACE_Time_Value *max_wait_time,
result = -1;
errno = ETIME;
}
- else if (reply_received == -1)
+ else if (reply_received == -1)
{
// If the time did not expire yet, but we get a failure,
// e.g. the connections closed, we should still return an error.
@@ -319,10 +316,6 @@ TAO_Wait_On_Leader_Follower::reply_dispatched (int &reply_received_flag,
reply_received_flag = 1;
- // The following works as the node is assumed to be on the stack
- // till the thread is alive.
- TAO_Leader_Follower::TAO_Follower_Node node (condition);
-
// We *must* remove it when we signal it so the same condition
// is not signalled for both wake up as a follower and as the
// next leader.
@@ -330,7 +323,7 @@ TAO_Wait_On_Leader_Follower::reply_dispatched (int &reply_received_flag,
// the consumer is not yet waiting for it (i.e. it send the
// request but has not blocked to receive the reply yet).
// Ignore errors.
- (void) leader_follower.remove_follower (&node);
+ (void) leader_follower.remove_follower (condition);
if (condition->signal () == -1)
return -1;
@@ -353,11 +346,7 @@ TAO_Wait_On_Leader_Follower::connection_closed (int &reply_received_flag,
reply_received_flag = -1;
- // The following works as the node is assumed to be on the stack
- // till the thread is alive.
- TAO_Leader_Follower::TAO_Follower_Node node (condition);
-
- (void) leader_follower.remove_follower (&node);
+ (void) leader_follower.remove_follower (condition);
(void) condition->signal ();
}