summaryrefslogtreecommitdiff
path: root/TAO/tao/ORB.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tao/ORB.cpp')
-rw-r--r--TAO/tao/ORB.cpp68
1 files changed, 59 insertions, 9 deletions
diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp
index c62216f6b74..416b39f276a 100644
--- a/TAO/tao/ORB.cpp
+++ b/TAO/tao/ORB.cpp
@@ -88,6 +88,8 @@ CORBA_ORB::CORBA_ORB (void)
event_service_ (CORBA_Object::_nil ()),
trading_service_ (CORBA_Object::_nil ())
{
+ this->cond_become_leader_ =
+ new ACE_SYNCH_CONDITION (TAO_ORB_Core_instance ()->leader_follower_lock ());
}
CORBA_ORB::~CORBA_ORB (void)
@@ -121,6 +123,9 @@ CORBA_ORB::~CORBA_ORB (void)
CORBA::release (this->event_service_);
if (!CORBA::is_nil (this->trading_service_))
CORBA::release (this->trading_service_);
+
+ if (this->cond_become_leader_ != 0)
+ this->cond_become_leader_;
}
// Set up listening endpoints.
@@ -229,6 +234,34 @@ CORBA_ORB::run (ACE_Time_Value *tv)
{
ACE_FUNCTION_TIMEPROBE (TAO_CORBA_ORB_RUN_START);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "CORBA_ORB::run: (%d) Trying to become the leader.\n",
+ ACE_Thread::self ()));
+
+ {
+ //ACE_Guard<ACE_SYNCH_MUTEX> g (TAO_ORB_Core_instance ()->leader_follower_lock ());
+ TAO_ORB_Core_instance ()->leader_follower_lock ().acquire();
+
+ while (TAO_ORB_Core_instance ()->leader_available ())
+ {
+ if (TAO_ORB_Core_instance ()->add_follower (this->cond_become_leader_) == -1)
+ ACE_ERROR ((LM_ERROR,
+ "(%P|%t) ORB::run: Failed to add a follower thread\n"));
+ this->cond_become_leader_->wait ();
+ }
+ TAO_ORB_Core_instance ()->set_leader_thread ();
+ TAO_ORB_Core_instance ()->leader_follower_lock ().release ();
+ }
+
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P|%t) CORBA_ORB::run: is the leader.\n"));
+
+ if (this->shutdown_lock_ == 0)
+ this->shutdown_lock_ =
+ TAO_ORB_Core_instance ()->server_factory ()->create_event_loop_lock ();
+
+
if (this->shutdown_lock_ == 0)
this->shutdown_lock_ =
TAO_ORB_Core_instance ()->server_factory ()->create_event_loop_lock ();
@@ -255,43 +288,60 @@ CORBA_ORB::run (ACE_Time_Value *tv)
// while blocked on I/O.
ACE_GUARD_RETURN (ACE_Lock, monitor, *this->shutdown_lock_, -1);
+ int result = 1;
+ // 1 to detect that nothing went wrong
+
// Loop "forever" handling client requests.
while (this->should_shutdown_ == 0)
- {
+ {
if (monitor.release () == -1)
return -1;
#if 0
counter++;
if (counter == max_iterations)
- {
+ {
ACE_TIMEPROBE_PRINT;
ACE_TIMEPROBE_RESET;
counter = 0;
- }
+ }
ACE_FUNCTION_TIMEPROBE (TAO_CORBA_ORB_RUN_START);
#endif /* 0 */
switch (r->handle_events (tv))
- {
+ {
case 0: // Timed out, so we return to caller.
- return 0;
+ result = 0;
+ break;
/* NOTREACHED */
case -1: // Something else has gone wrong, so return to caller.
- return -1;
+ result = -1;
+ break;
/* NOTREACHED */
default: // Some handlers were dispatched, so keep on processing
// requests until we're told to shutdown .
break;
/* NOTREACHED */
- }
+ }
+ if (result == 0 || result == -1)
+ break;
if (monitor.acquire () == -1)
return -1;
- }
+ }
- return 0;
+ if (result != -1)
+ {
+ if (TAO_ORB_Core_instance ()->unset_leader_wake_up_follower () == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%P|%t) ORB::run: Failed to add a follower thread\n"),
+ -1);
+ return 0;
+ // nothing went wrong
+ }
+ else
+ return result;
}
int