summaryrefslogtreecommitdiff
path: root/TAO/tao/Leader_Follower.i
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-08-30 20:51:16 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-08-30 20:51:16 +0000
commit44201fbd210a380f97b9d9faa2688a0a4632a445 (patch)
tree3a2e955790abe4cac5291c72827ebcde8150e805 /TAO/tao/Leader_Follower.i
parent80dfbff0a8be9a69b768c30fc7fceb1495454eea (diff)
downloadATCD-44201fbd210a380f97b9d9faa2688a0a4632a445.tar.gz
ChangeLogTag:Mon Aug 30 15:15:39 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
Diffstat (limited to 'TAO/tao/Leader_Follower.i')
-rw-r--r--TAO/tao/Leader_Follower.i162
1 files changed, 162 insertions, 0 deletions
diff --git a/TAO/tao/Leader_Follower.i b/TAO/tao/Leader_Follower.i
new file mode 100644
index 00000000000..26e02e1d710
--- /dev/null
+++ b/TAO/tao/Leader_Follower.i
@@ -0,0 +1,162 @@
+// $Id$
+
+// ****************************************************************
+
+ACE_INLINE
+TAO_Leader_Follower::TAO_Leader_Follower (TAO_ORB_Core* orb_core)
+ : orb_core_ (orb_core),
+ reverse_lock_ (lock_),
+ leaders_ (0),
+ clients_ (0),
+ reactor_ (0)
+{
+}
+
+ACE_INLINE TAO_ORB_Core_TSS_Resources *
+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)
+{
+ // 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_;
+}
+
+ACE_INLINE void
+TAO_Leader_Follower::reset_server_thread (void)
+{
+ // 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_ = 0;
+
+ --this->leaders_;
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::leader_available (void) const
+{
+ return this->leaders_ != 0;
+}
+
+ACE_INLINE void
+TAO_Leader_Follower::set_client_thread (void)
+{
+ // Set the TSS flag to remember that we are a leader thread...
+ TAO_ORB_Core_TSS_Resources *tss = this->get_tss_resources ();
+ if (tss->is_server_thread_)
+ {
+ --this->leaders_;
+ }
+
+ if (this->clients_ == 0
+ && this->orb_core_->has_shutdown ())
+ {
+ // The ORB has shutdown and we are the first client after
+ // that. This means that the reactor is disabled, we must
+ // re-enable it if we want to receive any replys...
+ this->orb_core_->reactor ()->reset_reactor_event_loop ();
+ }
+ this->clients_++;
+}
+
+ACE_INLINE void
+TAO_Leader_Follower::reset_client_thread (void)
+{
+ // Set the TSS flag to remember that we are a leader thread...
+ TAO_ORB_Core_TSS_Resources *tss = this->get_tss_resources ();
+ if (tss->is_server_thread_)
+ {
+ ++this->leaders_;
+ }
+ this->clients_--;
+ if (this->clients_ == 0 && this->orb_core_->has_shutdown ())
+ {
+ // The ORB has shutdown and we are the last client thread, we
+ // must stop the reactor to ensure that any server threads go
+ // away.
+ this->orb_core_->reactor ()->end_reactor_event_loop ();
+ }
+}
+
+ACE_INLINE void
+TAO_Leader_Follower::set_leader_thread (void)
+{
+ TAO_ORB_Core_TSS_Resources *tss = this->get_tss_resources ();
+ if (tss->is_leader_thread_ == 0)
+ {
+ ++this->leaders_;
+ }
+ ++tss->is_leader_thread_;
+}
+
+ACE_INLINE void
+TAO_Leader_Follower::reset_leader_thread (void)
+{
+ TAO_ORB_Core_TSS_Resources *tss = this->get_tss_resources ();
+ --tss->is_leader_thread_;
+ if (tss->is_leader_thread_ == 0)
+ {
+ --this->leaders_;
+ }
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::is_leader_thread (void) const
+{
+ TAO_ORB_Core_TSS_Resources *tss = this->get_tss_resources ();
+ return tss->is_leader_thread_ != 0;
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::follower_available (void) const
+{
+ return !this->follower_set_.is_empty ();
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::elect_new_leader (void)
+{
+ if (this->leaders_ == 0 && this->follower_available ())
+ {
+ ACE_SYNCH_CONDITION* condition_ptr = this->get_next_follower ();
+ if (condition_ptr == 0 || condition_ptr->signal () == -1)
+ return -1;
+ }
+ return 0;
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::add_follower (ACE_SYNCH_CONDITION *follower_ptr)
+{
+ return this->follower_set_.insert (follower_ptr);
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::remove_follower (ACE_SYNCH_CONDITION *follower_ptr)
+{
+ return this->follower_set_.remove (follower_ptr);
+}
+
+ACE_INLINE ACE_SYNCH_MUTEX &
+TAO_Leader_Follower::lock (void)
+{
+ return this->lock_;
+}
+
+ACE_INLINE ACE_Reverse_Lock<ACE_SYNCH_MUTEX> &
+TAO_Leader_Follower::reverse_lock (void)
+{
+ return this->reverse_lock_;
+}
+
+ACE_INLINE int
+TAO_Leader_Follower::has_clients (void) const
+{
+ return this->clients_;
+}