summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-01-26 02:34:55 +0000
committerirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-01-26 02:34:55 +0000
commit00814bd49c0a4ddac4f53924aca723a1f7aff590 (patch)
treecec94f491276648b74ffd67bed6670573a891a4a
parent058614abbaf5b468773deedd5165036401f136f4 (diff)
downloadATCD-00814bd49c0a4ddac4f53924aca723a1f7aff590.tar.gz
Change:Tue Jan 25 20:33:28 2000 Irfan Pyarali <irfan@cs.wustl.edu>
-rw-r--r--TAO/tao/Leader_Follower.cpp45
-rw-r--r--TAO/tao/Leader_Follower.h33
-rw-r--r--TAO/tao/Leader_Follower.i66
-rw-r--r--TAO/tao/ORB_Core.cpp27
-rw-r--r--TAO/tao/Reply_Dispatcher.cpp2
-rw-r--r--TAO/tao/Wait_Strategy.cpp4
6 files changed, 156 insertions, 21 deletions
diff --git a/TAO/tao/Leader_Follower.cpp b/TAO/tao/Leader_Follower.cpp
index a16dd4b3979..a16ccc369dc 100644
--- a/TAO/tao/Leader_Follower.cpp
+++ b/TAO/tao/Leader_Follower.cpp
@@ -44,6 +44,51 @@ TAO_Leader_Follower::get_next_follower (void)
return cond;
}
+int
+TAO_Leader_Follower::wait_for_client_leader_to_complete (ACE_Time_Value *max_wait_time)
+{
+ ACE_Countdown_Time countdown (max_wait_time);
+
+ while (this->client_thread_is_leader_)
+ {
+ ACE_SYNCH_CONDITION *condition_variable =
+ this->orb_core_->leader_follower_condition_variable ();
+
+ if (this->add_follower (condition_variable) == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot add to condition variable collection\n"),
+ -1);
+ }
+
+ if (max_wait_time == 0)
+ {
+ if (condition_variable->wait () == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Condition variable wait failed\n"),
+ -1);
+ }
+ }
+ else
+ {
+ countdown.update ();
+ ACE_Time_Value tv = ACE_OS::gettimeofday ();
+ tv += *max_wait_time;
+ if (condition_variable->wait (&tv) == -1)
+ {
+ if (errno != ETIME)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Condition variable wait failed\n"),
+ -1);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
ACE_Reactor *
TAO_Leader_Follower::reactor (void)
{
diff --git a/TAO/tao/Leader_Follower.h b/TAO/tao/Leader_Follower.h
index b88839fc1cf..6d6f37d8637 100644
--- a/TAO/tao/Leader_Follower.h
+++ b/TAO/tao/Leader_Follower.h
@@ -33,7 +33,7 @@ public:
~TAO_Leader_Follower (void);
// Destructor
- void set_server_thread (void);
+ int set_server_thread (ACE_Time_Value *max_wait_time);
// The current thread has become a server thread (i.e. called
// ORB::run), update any flags and counters.
@@ -102,6 +102,9 @@ private:
TAO_ORB_Core_TSS_Resources *get_tss_resources (void) const;
// Shortcut to obtain the TSS resources of the orb core.
+ int wait_for_client_leader_to_complete (ACE_Time_Value *max_wait_time);
+ // Wait for the client leader to complete.
+
private:
TAO_ORB_Core *orb_core_;
// The orb core
@@ -127,6 +130,9 @@ private:
ACE_Reactor *reactor_;
// The reactor
+
+ int client_thread_is_leader_;
+ // Is a client thread the current leader?
};
class TAO_Export TAO_LF_Client_Thread_Helper
@@ -157,6 +163,31 @@ private:
// Reference to leader/followers object.
};
+class TAO_Export TAO_LF_Server_Thread_Helper
+{
+public:
+ TAO_LF_Server_Thread_Helper (TAO_Leader_Follower &leader_follower);
+ // Constructor
+
+ ~TAO_LF_Server_Thread_Helper (void);
+ // Destructor
+
+ int set_server_thread (ACE_Time_Value *max_wait_time);
+ // Calls <set_server_thread> on the leader/followers object.
+
+ int reset_server_thread (void);
+ // Calls <reset_server_thread> and <elect_new_leader> on the
+ // leader/followers object.
+
+private:
+ TAO_Leader_Follower &leader_follower_;
+ // Reference to leader/followers object.
+
+ int auto_reset_;
+ // Remembers whether we have to call the reset method in the
+ // destructor.
+};
+
#if defined (__ACE_INLINE__)
# include "tao/Leader_Follower.i"
#endif /* __ACE_INLINE__ */
diff --git a/TAO/tao/Leader_Follower.i b/TAO/tao/Leader_Follower.i
index f9fe04716b6..0309806d6d2 100644
--- a/TAO/tao/Leader_Follower.i
+++ b/TAO/tao/Leader_Follower.i
@@ -9,7 +9,8 @@ TAO_Leader_Follower::TAO_Leader_Follower (TAO_ORB_Core* orb_core)
reverse_lock_ (lock_),
leaders_ (0),
clients_ (0),
- reactor_ (0)
+ reactor_ (0),
+ client_thread_is_leader_ (0)
{
}
@@ -19,14 +20,25 @@ TAO_Leader_Follower::get_tss_resources (void) const
return this->orb_core_->get_tss_resources ();
}
-ACE_INLINE void
-TAO_Leader_Follower::set_server_thread (void)
+ACE_INLINE int
+TAO_Leader_Follower::set_server_thread (ACE_Time_Value *max_wait_time)
{
+ if (this->client_thread_is_leader_)
+ {
+ int result =
+ this->wait_for_client_leader_to_complete (max_wait_time);
+
+ if (result != 0)
+ return result;
+ }
+
// Set the TSS flag to remember that we are a leader thread...
TAO_ORB_Core_TSS_Resources *tss = this->get_tss_resources ();
tss->is_server_thread_ = 1;
++this->leaders_;
+
+ return 0;
}
ACE_INLINE void
@@ -92,6 +104,7 @@ TAO_Leader_Follower::set_leader_thread (void)
if (tss->is_leader_thread_ == 0)
{
++this->leaders_;
+ this->client_thread_is_leader_ = 1;
}
++tss->is_leader_thread_;
}
@@ -104,6 +117,7 @@ TAO_Leader_Follower::reset_leader_thread (void)
if (tss->is_leader_thread_ == 0)
{
--this->leaders_;
+ this->client_thread_is_leader_ = 0;
}
}
@@ -162,24 +176,70 @@ TAO_Leader_Follower::has_clients (void) const
return this->clients_;
}
+ACE_INLINE
TAO_LF_Client_Thread_Helper::TAO_LF_Client_Thread_Helper (TAO_Leader_Follower &leader_follower)
: leader_follower_ (leader_follower)
{
this->leader_follower_.set_client_thread ();
}
+ACE_INLINE
TAO_LF_Client_Thread_Helper::~TAO_LF_Client_Thread_Helper (void)
{
this->leader_follower_.reset_client_thread ();
}
+ACE_INLINE
TAO_LF_Leader_Thread_Helper::TAO_LF_Leader_Thread_Helper (TAO_Leader_Follower &leader_follower)
: leader_follower_ (leader_follower)
{
this->leader_follower_.set_leader_thread ();
}
+ACE_INLINE
TAO_LF_Leader_Thread_Helper::~TAO_LF_Leader_Thread_Helper (void)
{
this->leader_follower_.reset_leader_thread ();
}
+
+ACE_INLINE
+TAO_LF_Server_Thread_Helper::TAO_LF_Server_Thread_Helper (TAO_Leader_Follower &leader_follower)
+ : leader_follower_ (leader_follower),
+ auto_reset_ (0)
+{
+}
+
+ACE_INLINE
+TAO_LF_Server_Thread_Helper::~TAO_LF_Server_Thread_Helper (void)
+{
+ if (this->auto_reset_)
+ this->reset_server_thread ();
+}
+
+ACE_INLINE int
+TAO_LF_Server_Thread_Helper::set_server_thread (ACE_Time_Value *max_wait_time)
+{
+ ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->leader_follower_.lock (), -1);
+
+ int result =
+ this->leader_follower_.set_server_thread (max_wait_time);
+
+ // If successful, reset has to be called.
+ if (result == 0)
+ this->auto_reset_ = 1;
+
+ return result;
+}
+
+ACE_INLINE int
+TAO_LF_Server_Thread_Helper::reset_server_thread (void)
+{
+ // Reset has been called explicitly, no need to auto reset.
+ this->auto_reset_ = 0;
+
+ ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->leader_follower_.lock (), -1);
+
+ this->leader_follower_.reset_server_thread ();
+
+ return this->leader_follower_.elect_new_leader ();
+}
diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp
index c1ccfba9f18..98e3d64f74b 100644
--- a/TAO/tao/ORB_Core.cpp
+++ b/TAO/tao/ORB_Core.cpp
@@ -1647,12 +1647,16 @@ TAO_ORB_Core::run (ACE_Time_Value *tv,
ASYS_TEXT ("TAO (%P|%t) - start of run/perform_work\n")));
TAO_Leader_Follower &leader_follower = this->leader_follower ();
- {
- ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon,
- leader_follower.lock (), -1);
+ TAO_LF_Server_Thread_Helper server_thread_helper (leader_follower);
- leader_follower.set_server_thread ();
- }
+ int result = server_thread_helper.set_server_thread (tv);
+ if (result != 0)
+ {
+ if (errno == ETIME)
+ return 0;
+ else
+ return result;
+ }
ACE_Reactor *r = this->reactor ();
@@ -1672,7 +1676,7 @@ TAO_ORB_Core::run (ACE_Time_Value *tv,
if (ret == -1)
return -1;
- int result = 1;
+ result = 1;
// 1 to detect that nothing went wrong
// Loop handling client requests until the ORB is shutdown.
@@ -1712,18 +1716,13 @@ TAO_ORB_Core::run (ACE_Time_Value *tv,
break;
}
- {
- ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon,
- leader_follower.lock (), -1);
-
- leader_follower.reset_server_thread ();
-
- if (leader_follower.elect_new_leader () == -1)
+ if (server_thread_helper.reset_server_thread () == -1)
+ {
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("TAO (%P|%t) Failed to wake up ")
ASYS_TEXT ("a follower thread\n")),
-1);
- }
+ }
if (TAO_debug_level >= 3)
ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("TAO (%P|%t) - end of run/perform_work %d\n"), result));
diff --git a/TAO/tao/Reply_Dispatcher.cpp b/TAO/tao/Reply_Dispatcher.cpp
index 72ba7534fbb..88a74281179 100644
--- a/TAO/tao/Reply_Dispatcher.cpp
+++ b/TAO/tao/Reply_Dispatcher.cpp
@@ -86,7 +86,7 @@ TAO_Synch_Reply_Dispatcher::dispatch_reply (CORBA::ULong reply_status,
}
// If condition variable is present, then we are doing leader
- // follower model. Do all the nessary things.
+ // follower model. Do all the necessary things.
if (this->leader_follower_condition_variable_ != 0)
{
TAO_Leader_Follower& leader_follower =
diff --git a/TAO/tao/Wait_Strategy.cpp b/TAO/tao/Wait_Strategy.cpp
index 87dc5813023..39165bd8fec 100644
--- a/TAO/tao/Wait_Strategy.cpp
+++ b/TAO/tao/Wait_Strategy.cpp
@@ -406,8 +406,8 @@ TAO_Exclusive_Wait_On_Leader_Follower::wait (ACE_Time_Value *max_wait_time,
if (result == -1)
ACE_ERROR_RETURN ((LM_ERROR,
- ASYS_TEXT ("TAO (%P|%t): TAO_Wait_On_LF::wait - ")
- ASYS_TEXT ("handle_events failed.\n")),
+ ASYS_TEXT ("TAO (%P|%t): TAO_Wait_On_LF::wait: %p.\n"),
+ ASYS_TEXT ("handle_events failed")),
-1);
// Return an error if there was a problem receiving the reply...