From 2291b0bf1e6488c3db579bf240dee601404111bb Mon Sep 17 00:00:00 2001 From: mk1 Date: Wed, 15 Jul 1998 17:26:39 +0000 Subject: Formatting. --- TAO/tao/Connect.cpp | 392 +++++++++++++++++++++++++-------------------------- TAO/tao/Connect.h | 8 +- TAO/tao/ORB.cpp | 60 ++++---- TAO/tao/ORB_Core.cpp | 54 +++---- TAO/tao/ORB_Core.h | 2 +- 5 files changed, 257 insertions(+), 259 deletions(-) diff --git a/TAO/tao/Connect.cpp b/TAO/tao/Connect.cpp index fd9dc8b87d5..60010eb3937 100644 --- a/TAO/tao/Connect.cpp +++ b/TAO/tao/Connect.cpp @@ -579,128 +579,128 @@ TAO_Client_Connection_Handler::send_request (TAO_OutputCDR &stream, if (!is_twoway) { int success = (int) TAO_GIOP::send_request (this, stream); - + if (!success) return -1; } else // is_twoway - { - if (TAO_ORB_Core_instance ()->leader_follower_lock ().acquire() == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::send_request: " - "Failed to get the lock.\n"), - -1); - - // Set the state so that we know we're looking for a response. - this->expecting_response_ = 1; - // remember in which thread the client connection handler was running - this->calling_thread_ = ACE_Thread::self (); - - - int success = (int) TAO_GIOP::send_request (this, stream); - - if (!success) { - TAO_ORB_Core_instance ()->leader_follower_lock ().release (); - return -1; - } - - // check if there is a leader, but the leader is not us - if (TAO_ORB_Core_instance ()->leader_available () - && !TAO_ORB_Core_instance ()->I_am_the_leader_thread ()) - { - // wait as long as no input is available and/or - // no leader is available - while (!this->input_available_ - && TAO_ORB_Core_instance ()->leader_available ()) - { - if (TAO_ORB_Core_instance ()->add_follower (this->cond_response_available_) == -1) - ACE_ERROR ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::send_request: " - "Failed to add a follower thread\n")); - this->cond_response_available_->wait (); - } - // now somebody woke us up to become a leader or - // to handle our input. We are already removed from the - // follower queue - if (this->input_available_) - { - // there is input waiting for me - if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::send_request: " - "Failed to release the lock.\n"), - -1); - - int ret = 0; - if (ret < 0) - { - ACE_DEBUG ((LM_DEBUG, - "Client_Connection_Handler::send_request: (%d) " - "failure faking handle_input\n", - ACE_Thread::self ())); - TAO_ORB_Core_instance ()->reactor ()->remove_handler (this, + if (TAO_ORB_Core_instance ()->leader_follower_lock ().acquire() == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::send_request: " + "Failed to get the lock.\n"), + -1); + + // Set the state so that we know we're looking for a response. + this->expecting_response_ = 1; + // remember in which thread the client connection handler was running + this->calling_thread_ = ACE_Thread::self (); + + + int success = (int) TAO_GIOP::send_request (this, stream); + + if (!success) + { + TAO_ORB_Core_instance ()->leader_follower_lock ().release (); + return -1; + } + + // check if there is a leader, but the leader is not us + if (TAO_ORB_Core_instance ()->leader_available () + && !TAO_ORB_Core_instance ()->I_am_the_leader_thread ()) + { + // wait as long as no input is available and/or + // no leader is available + while (!this->input_available_ + && TAO_ORB_Core_instance ()->leader_available ()) + { + if (TAO_ORB_Core_instance ()->add_follower (this->cond_response_available_) == -1) + ACE_ERROR ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::send_request: " + "Failed to add a follower thread\n")); + this->cond_response_available_->wait (); + } + // now somebody woke us up to become a leader or + // to handle our input. We are already removed from the + // follower queue + if (this->input_available_) + { + // there is input waiting for me + if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::send_request: " + "Failed to release the lock.\n"), + -1); + + int ret = 0; + if (ret < 0) + { + ACE_DEBUG ((LM_DEBUG, + "Client_Connection_Handler::send_request: (%d) " + "failure faking handle_input\n", + ACE_Thread::self ())); + TAO_ORB_Core_instance ()->reactor ()->remove_handler (this, ACE_Event_Handler::ALL_EVENTS_MASK); - // failure handling - return -1; - } - /* else if (ret > 0) - // we have to reschedule, not implemented yet - */ - - // the following variables are safe, because we are not registered with - // the reactor any more. - this->input_available_ = 0; - this->expecting_response_ = 0; - this->calling_thread_ = 0; - return 0; - } + // failure handling + return -1; + } + /* else if (ret > 0) + // we have to reschedule, not implemented yet + */ + + // the following variables are safe, because we are not registered with + // the reactor any more. + this->input_available_ = 0; + this->expecting_response_ = 0; + this->calling_thread_ = 0; + return 0; + } + } + + // become a leader, because there is no leader or we have to update to a leader + // or we are doing nested upcalls in this case we do increase the refcount + // on the leader in TAO_ORB_Core. + + TAO_ORB_Core_instance ()->set_leader_thread (); + // this might increase the recount of the leader + + if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::send_request: " + "Failed to release the lock.\n"), + -1); + + ACE_Reactor *r = TAO_ORB_Core_instance ()->reactor (); + r->owner (ACE_Thread::self ()); + + int ret = 0; + + while (ret != -1 && !this->input_available_) + ret = r->handle_events (); + + if (ret == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::send_request: " + "handle_events failed.\n"), + -1); + + + // wake up the next leader, we cannot do that in handle_input, + // because the woken up thread would try to get into handle_events, + // which is at the time in handle_input still occupied. + + if (TAO_ORB_Core_instance ()->unset_leader_wake_up_follower () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::send_request: " + "Failed to unset the leader and wake up a new follower.\n"), + -1); + + // Make use reusable + this->input_available_ = 0; + this->expecting_response_ = 0; + this->calling_thread_ = 0; } - - // become a leader, because there is no leader or we have to update to a leader - // or we are doing nested upcalls in this case we do increase the refcount - // on the leader in TAO_ORB_Core. - - TAO_ORB_Core_instance ()->set_leader_thread (); - // this might increase the recount of the leader - - if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::send_request: " - "Failed to release the lock.\n"), - -1); - - ACE_Reactor *r = TAO_ORB_Core_instance ()->reactor (); - r->owner (ACE_Thread::self ()); - - int ret = 0; - - while (ret != -1 && !this->input_available_) - ret = r->handle_events (); - - if (ret == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::send_request: " - "handle_events failed.\n"), - -1); - - - // wake up the next leader, we cannot do that in handle_input, - // because the woken up thread would try to get into handle_events, - // which is at the time in handle_input still occupied. - - if (TAO_ORB_Core_instance ()->unset_leader_wake_up_follower () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::send_request: " - "Failed to unset the leader and wake up a new follower.\n"), - -1); - - // Make use reusable - this->input_available_ = 0; - this->expecting_response_ = 0; - this->calling_thread_ = 0; - } - + return 0; } @@ -708,31 +708,31 @@ int TAO_Client_Connection_Handler::handle_input (ACE_HANDLE) { if (TAO_ORB_Core_instance ()->leader_follower_lock ().acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::handle_input: " - "Failed to get the lock.\n"), - -1); - + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::handle_input: " + "Failed to get the lock.\n"), + -1); + if (!this->expecting_response_) - { - // we got something, but did not want - // @@ wake up an other thread, we are lost - - if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::handle_input: " - "Failed to release the lock.\n"), - -1); - - // We're a client, so we're not expecting to see input. Still - // we better check what it is! - char ignored; - ssize_t ret; - + { + // we got something, but did not want + // @@ wake up an other thread, we are lost + + if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::handle_input: " + "Failed to release the lock.\n"), + -1); + + // We're a client, so we're not expecting to see input. Still + // we better check what it is! + char ignored; + ssize_t ret; + ret = this->peer().recv_n (&ignored, sizeof ignored); - + switch (ret) - { + { case -1: // Error...but we weren't expecting input, either...what // should we do? @@ -740,7 +740,7 @@ TAO_Client_Connection_Handler::handle_input (ACE_HANDLE) "Client_Connection_Handler::handle_input: closing connection on fd %d\n", this->peer().get_handle ())); break; - + case 1: // We weren't expecting input, so what should we do with it? // Log an error, and close the connection. @@ -749,76 +749,74 @@ TAO_Client_Connection_Handler::handle_input (ACE_HANDLE) "input while not expecting a response; closing connection on fd %d\n", this->peer().get_handle ())); break; - + case 0: // This is an EOF, so we will return -1 and let // handle_close() take over. As long as handle_close() // calls the Svc_Handler<>::handle_close(), the socket will // be shutdown properly. break; - } - + } + // We're not expecting input at this time, so we'll always // return -1 for now. return -1; - } - - if (this->calling_thread_ == ACE_Thread::self ()) - { - // we are now a leader getting its response - // or a follower faking the handle_input + } - this->input_available_ = 1; - - if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::handle_input: " - "Failed to release the lock.\n"), - -1); - - TAO_ORB_Core_instance ()->reactor ()->suspend_handler (this); - // resume_handler is called in TAO_GIOP_Invocation::invoke - - return 0; - } + if (this->calling_thread_ == ACE_Thread::self ()) + { + // we are now a leader getting its response + // or a follower faking the handle_input + + this->input_available_ = 1; + + if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::handle_input: " + "Failed to release the lock.\n"), + -1); + + TAO_ORB_Core_instance ()->reactor ()->suspend_handler (this); + // resume_handler is called in TAO_GIOP_Invocation::invoke + + return 0; + } else - { - // we are a leader, which got a response for one of the followers, - // which means we are now a thread running the wrong Client_Connection_Handler - - TAO_ORB_Core_instance ()->remove_follower (this->cond_response_available_); - - if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::handle_input: " - "Failed to release the lock.\n"), - -1); - - - TAO_ORB_Core_instance ()->reactor ()->suspend_handler (this); - // @@ Michael: we should wake suspend the thread before we wake him up. - // resume_handler is called in TAO_GIOP_Invocation::invoke - - if (TAO_ORB_Core_instance ()->leader_follower_lock ().acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::handle_input: " - "Failed to acquire the lock.\n"), - -1); - - // the thread was already selected to become a leader, - // so we will be called again. - this->input_available_ = 1; - this->cond_response_available_->signal (); - - if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) TAO_Client_Connection_Handler::handle_input: " - "Failed to release the lock.\n"), - -1); - - - return 0; - } + { + // we are a leader, which got a response for one of the followers, + // which means we are now a thread running the wrong Client_Connection_Handler + + TAO_ORB_Core_instance ()->remove_follower (this->cond_response_available_); + + if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::handle_input: " + "Failed to release the lock.\n"), + -1); + + + TAO_ORB_Core_instance ()->reactor ()->suspend_handler (this); + // @@ Michael: we should wake suspend the thread before we wake him up. + // resume_handler is called in TAO_GIOP_Invocation::invoke + + if (TAO_ORB_Core_instance ()->leader_follower_lock ().acquire () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::handle_input: " + "Failed to acquire the lock.\n"), + -1); + + // the thread was already selected to become a leader, + // so we will be called again. + this->input_available_ = 1; + this->cond_response_available_->signal (); + + if (TAO_ORB_Core_instance ()->leader_follower_lock ().release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Client_Connection_Handler::handle_input: " + "Failed to release the lock.\n"), + -1); + return 0; + } } int diff --git a/TAO/tao/Connect.h b/TAO/tao/Connect.h index 8f9c1e5c5db..6edb110c8ae 100644 --- a/TAO/tao/Connect.h +++ b/TAO/tao/Connect.h @@ -67,19 +67,19 @@ public: private: typedef TAO_SVC_HANDLER BASECLASS; // Trait indicating the base class. - + int expecting_response_; // State flag which, if non-zero, indicates that this handler is // looking to get input. Otherwise, any input received is // unexpected. - + int input_available_; // Flag indicating whether or not input is available. Only valid // when is non-zero. - + ACE_thread_t calling_thread_; // the thread ID of the thread we were running in. - + ACE_SYNCH_CONDITION* cond_response_available_; // wait on reponse if the leader-follower model is active }; diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index ed012e6e1ff..3852369f26d 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -241,20 +241,20 @@ CORBA_ORB::run (ACE_Time_Value *tv) { ACE_Guard g (TAO_ORB_Core_instance ()->leader_follower_lock ()); - + 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 (); - } + { + 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 (); } - + 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 (); @@ -288,27 +288,27 @@ CORBA_ORB::run (ACE_Time_Value *tv) 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. result = 0; break; @@ -318,26 +318,26 @@ CORBA_ORB::run (ACE_Time_Value *tv) break; /* NOTREACHED */ default: // Some handlers were dispatched, so keep on processing - // requests until we're told to shutdown . + // requests until we're told to shutdown . break; /* NOTREACHED */ - } + } if (result == 0 || result == -1) break; - + if (monitor.acquire () == -1) return -1; - } - + } + 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 - } + { + 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; } diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp index d9a8bce01d5..607c4859af3 100644 --- a/TAO/tao/ORB_Core.cpp +++ b/TAO/tao/ORB_Core.cpp @@ -922,16 +922,16 @@ TAO_ORB_Core::get_collocated_poa (ACE_INET_Addr &addr) int TAO_ORB_Core::leader_available (void) -// returns the value of the flag indicating if a leader -// is available in the leader-follower model + // returns the value of the flag indicating if a leader + // is available in the leader-follower model { return this->leaders_; } int TAO_ORB_Core::I_am_the_leader_thread (void) -// returns 1 if we are the leader thread, -// else 0 + // returns 1 if we are the leader thread, + // else 0 { if (this->leaders_) return (this->leader_thread_ID_ == ACE_Thread::self ()); @@ -941,39 +941,39 @@ TAO_ORB_Core::I_am_the_leader_thread (void) void TAO_ORB_Core::set_leader_thread (void) -// sets the thread ID of the leader thread in the leader-follower -// model + // sets the thread ID of the leader thread in the leader-follower + // model { ACE_ASSERT ((this->leaders_ >= 1 && this->leader_thread_ID_ == ACE_Thread::self ()) - || this->leaders_ == 0); + || this->leaders_ == 0); this->leaders_++; this->leader_thread_ID_ = ACE_Thread::self (); } int TAO_ORB_Core::unset_leader_wake_up_follower (void) -// sets the leader_available flag to false and tries to wake up a follower + // sets the leader_available flag to false and tries to wake up a follower { ACE_Guard g (TAO_ORB_Core_instance ()->leader_follower_lock ()); this->unset_leader_thread (); - + if (TAO_ORB_Core_instance ()->follower_available () - && !this->leader_available ()) - // do it only if a follower is available and no leader is available - { - ACE_SYNCH_CONDITION* condition_ptr = this->get_next_follower (); - if (this->remove_follower (condition_ptr) == -1) - return -1; - condition_ptr->signal (); - } + && !this->leader_available ()) + // do it only if a follower is available and no leader is available + { + ACE_SYNCH_CONDITION* condition_ptr = this->get_next_follower (); + if (this->remove_follower (condition_ptr) == -1) + return -1; + condition_ptr->signal (); + } return 0; } void TAO_ORB_Core::unset_leader_thread (void) -// sets the flag in the leader-follower model to false + // sets the flag in the leader-follower model to false { ACE_ASSERT ((this->leaders_ > 1 && this->leader_thread_ID_ == ACE_Thread::self ()) || this->leaders_ == 1); @@ -983,16 +983,16 @@ TAO_ORB_Core::unset_leader_thread (void) ACE_SYNCH_MUTEX & TAO_ORB_Core::leader_follower_lock (void) -// returns the leader-follower lock + // returns the leader-follower lock { return this->leader_follower_lock_; } int TAO_ORB_Core::add_follower (ACE_SYNCH_CONDITION *follower_ptr) -// adds the a follower to the set of followers in the leader- -// follower model -// returns 0 on success, -1 on failure + // adds the a follower to the set of followers in the leader- + // follower model + // returns 0 on success, -1 on failure { if (this->follower_set_.insert (follower_ptr) != 0) return -1; @@ -1002,23 +1002,23 @@ TAO_ORB_Core::add_follower (ACE_SYNCH_CONDITION *follower_ptr) int TAO_ORB_Core::follower_available (void) // checks for the availablity of a follower -// returns 1 on available, 0 else + // returns 1 on available, 0 else { return !this->follower_set_.is_empty (); } int TAO_ORB_Core::remove_follower (ACE_SYNCH_CONDITION *follower_ptr) -// removes a follower from the leader-follower set -// returns 0 on success, -1 on failure + // removes a follower from the leader-follower set + // returns 0 on success, -1 on failure { return this->follower_set_.remove (follower_ptr); } ACE_SYNCH_CONDITION* TAO_ORB_Core::get_next_follower (void) -// returns randomly a follower from the leader-follower set -// returns follower on success, else 0 + // returns randomly a follower from the leader-follower set + // returns follower on success, else 0 { ACE_Unbounded_Set_Iterator iterator (this->follower_set_); if (iterator.first () == 0) diff --git a/TAO/tao/ORB_Core.h b/TAO/tao/ORB_Core.h index 6ed9e011133..1d286c5c7ea 100644 --- a/TAO/tao/ORB_Core.h +++ b/TAO/tao/ORB_Core.h @@ -161,7 +161,7 @@ public: int I_am_the_leader_thread (void); // returns 1 if we are the leader thread, // else 0 - + void set_leader_thread (void) ; // sets the thread_available flag and the thread ID of the leader // thread in the leader-follower model -- cgit v1.2.1