00001 // $Id: Non_Servant_Upcall.cpp 76687 2007-01-29 19:18:13Z johnnyw $ 00002 00003 #include "tao/PortableServer/Non_Servant_Upcall.h" 00004 #include "tao/PortableServer/Object_Adapter.h" 00005 #include "tao/PortableServer/Root_POA.h" 00006 00007 #if !defined (__ACE_INLINE__) 00008 # include "tao/PortableServer/Non_Servant_Upcall.inl" 00009 #endif /* __ACE_INLINE__ */ 00010 00011 ACE_RCSID (PortableServer, 00012 Non_Servant_Upcall, 00013 "$Id: Non_Servant_Upcall.cpp 76687 2007-01-29 19:18:13Z johnnyw $") 00014 00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00016 00017 namespace TAO 00018 { 00019 namespace Portable_Server 00020 { 00021 Non_Servant_Upcall::Non_Servant_Upcall (::TAO_Root_POA &poa) 00022 : object_adapter_ (poa.object_adapter ()), 00023 poa_ (poa), 00024 previous_ (0) 00025 { 00026 // Check if this is a nested non_servant_upcall. 00027 if (this->object_adapter_.non_servant_upcall_nesting_level_ != 0) 00028 { 00029 // Remember previous instance of non_servant_upcall. 00030 this->previous_ = 00031 this->object_adapter_.non_servant_upcall_in_progress_; 00032 00033 // Assert that the thread is the same as the one before. 00034 ACE_ASSERT (ACE_OS::thr_equal ( 00035 this->object_adapter_.non_servant_upcall_thread_, 00036 ACE_OS::thr_self ())); 00037 } 00038 00039 // Remember which thread is calling the adapter activators. 00040 this->object_adapter_.non_servant_upcall_thread_ = ACE_OS::thr_self (); 00041 00042 // Mark the fact that a non-servant upcall is in progress. 00043 this->object_adapter_.non_servant_upcall_in_progress_ = this; 00044 00045 // Adjust the nesting level. 00046 this->object_adapter_.non_servant_upcall_nesting_level_++; 00047 00048 // We always release 00049 this->object_adapter_.lock ().release (); 00050 } 00051 00052 Non_Servant_Upcall::~Non_Servant_Upcall (void) 00053 { 00054 // Reacquire the Object Adapter lock. 00055 this->object_adapter_.lock ().acquire (); 00056 00057 // Adjust the nesting level. 00058 this->object_adapter_.non_servant_upcall_nesting_level_--; 00059 00060 // We are done with this nested upcall. 00061 this->object_adapter_.non_servant_upcall_in_progress_ = this->previous_; 00062 00063 // If we are at the outer nested upcall. 00064 if (this->object_adapter_.non_servant_upcall_nesting_level_ == 0) 00065 { 00066 // Reset thread id. 00067 this->object_adapter_.non_servant_upcall_thread_ = 00068 ACE_OS::NULL_thread; 00069 00070 // Check if all pending requests are over. 00071 if (this->poa_.waiting_destruction () && 00072 this->poa_.outstanding_requests () == 0) 00073 { 00074 try 00075 { 00076 this->poa_.complete_destruction_i (); 00077 } 00078 catch (const::CORBA::Exception&ex) 00079 { 00080 // Ignore exceptions 00081 ex._tao_print_exception ("TAO_POA::complete_destruction_i"); 00082 } 00083 } 00084 00085 // If locking is enabled. 00086 if (this->object_adapter_.enable_locking_) 00087 // Wakeup all waiting threads. 00088 this->object_adapter_.non_servant_upcall_condition_.broadcast (); 00089 } 00090 } 00091 } 00092 } 00093 00094 TAO_END_VERSIONED_NAMESPACE_DECL