diff options
author | dai_y <dai_y@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-11-10 06:04:53 +0000 |
---|---|---|
committer | dai_y <dai_y@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-11-10 06:04:53 +0000 |
commit | 9f6a1de034a521f9aebc481639856fcfd8d0620d (patch) | |
tree | 3cf98d0879e4c297ae71f664009e6ff6c33a09a7 /TAO/tao/CSD_ThreadPool | |
parent | 6a27c85f38b53a203a60be11ce3f5a55d88d4d11 (diff) | |
download | ATCD-9f6a1de034a521f9aebc481639856fcfd8d0620d.tar.gz |
Wed Nov 9 22:54:43 USMST 2005 Yan Dai <dai_y@ociweb.com>
Diffstat (limited to 'TAO/tao/CSD_ThreadPool')
-rw-r--r-- | TAO/tao/CSD_ThreadPool/CSD_TP_Request.inl | 18 | ||||
-rw-r--r-- | TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.cpp | 61 | ||||
-rw-r--r-- | TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h | 35 | ||||
-rw-r--r-- | TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl | 18 | ||||
-rw-r--r-- | TAO/tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.cpp | 42 |
5 files changed, 139 insertions, 35 deletions
diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Request.inl b/TAO/tao/CSD_ThreadPool/CSD_TP_Request.inl index 28df573bf15..341a449091e 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Request.inl +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Request.inl @@ -49,6 +49,14 @@ ACE_INLINE bool TAO::CSD::TP_Request::is_ready() const { + if (this->servant_state_.is_nil()) + { + // This means that the serialization of servants is off. + // We always answer true here to indicate that the servant is + // never busy. + return true; + } + return !this->servant_state_->busy_flag(); } @@ -57,7 +65,10 @@ ACE_INLINE void TAO::CSD::TP_Request::mark_as_busy() { - this->servant_state_->busy_flag(true); + if (!this->servant_state_.is_nil()) + { + this->servant_state_->busy_flag(true); + } } @@ -65,7 +76,10 @@ ACE_INLINE void TAO::CSD::TP_Request::mark_as_ready() { - this->servant_state_->busy_flag(false); + if (!this->servant_state_.is_nil()) + { + this->servant_state_->busy_flag(false); + } } diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.cpp b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.cpp index bb705279b1e..9f33bbc5b4b 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.cpp +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.cpp @@ -29,8 +29,9 @@ TAO::CSD::TP_Strategy::CustomRequestOutcome TAO::CSD::TP_Strategy::custom_synch_request(TP_Custom_Request_Operation* op ACE_ENV_ARG_DECL) { - TP_Servant_State::HandleType servant_state - = this->servant_state_map_.find(op->servant() ACE_ENV_ARG_PARAMETER); + TP_Servant_State::HandleType servant_state = + this->get_servant_state(op->servant() + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (REQUEST_REJECTED); TP_Custom_Synch_Request_Handle request = new @@ -51,8 +52,9 @@ TAO::CSD::TP_Strategy::CustomRequestOutcome TAO::CSD::TP_Strategy::custom_asynch_request(TP_Custom_Request_Operation* op ACE_ENV_ARG_DECL) { - TP_Servant_State::HandleType servant_state - = this->servant_state_map_.find(op->servant() ACE_ENV_ARG_PARAMETER); + TP_Servant_State::HandleType servant_state = + this->get_servant_state(op->servant() + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (REQUEST_REJECTED); TP_Custom_Asynch_Request_Handle request = new @@ -92,12 +94,9 @@ TAO::CSD::TP_Strategy::dispatch_remote_request_i PortableServer::Servant servant ACE_ENV_ARG_DECL) { - // Obtain the TP_Servant_State object associated with the servant object. - // The find() either return a non nil handle or already thrown - // ServantNotActive exception. - - TP_Servant_State::HandleType servant_state - = this->servant_state_map_.find(servant ACE_ENV_ARG_PARAMETER); + TP_Servant_State::HandleType servant_state = + this->get_servant_state(servant + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (DISPATCH_REJECTED); // Now we can create the TP_Remote_Request object, and then add it to our @@ -136,12 +135,9 @@ TAO::CSD::TP_Strategy::dispatch_collocated_request_i PortableServer::Servant servant ACE_ENV_ARG_DECL) { - // Obtain the TP_Servant_State object associated with the servant object. - // The find() either return a non nil handle or already thrown - // ServantNotActive exception. - - TP_Servant_State::HandleType servant_state - = this->servant_state_map_.find(servant ACE_ENV_ARG_PARAMETER); + TP_Servant_State::HandleType servant_state = + this->get_servant_state(servant + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (DISPATCH_REJECTED); bool is_sync_with_server = server_request.sync_with_server(); @@ -236,9 +232,12 @@ TAO::CSD::TP_Strategy::servant_activated_event_i { ACE_UNUSED_ARG(oid); - // Add the servant to the servant state map. - this->servant_state_map_.insert(servant ACE_ENV_ARG_PARAMETER); - ACE_CHECK; + if (this->serialize_servants_) + { + // Add the servant to the servant state map. + this->servant_state_map_.insert(servant ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } } @@ -254,9 +253,12 @@ TAO::CSD::TP_Strategy::servant_deactivated_event_i this->task_.cancel_servant(servant ACE_ENV_ARG_PARAMETER); ACE_CHECK; - // Remove the servant from the servant state map. - this->servant_state_map_.remove(servant ACE_ENV_ARG_PARAMETER); - ACE_CHECK; + if (this->serialize_servants_) + { + // Remove the servant from the servant state map. + this->servant_state_map_.remove(servant ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } } @@ -269,4 +271,19 @@ TAO::CSD::TP_Strategy::cancel_requests(PortableServer::Servant servant ACE_CHECK; } + +TAO::CSD::TP_Servant_State::HandleType +TAO::CSD::TP_Strategy::get_servant_state(PortableServer::Servant servant + ACE_ENV_ARG_DECL) +{ + TP_Servant_State::HandleType servant_state; + + if (this->serialize_servants_) + { + servant_state = this->servant_state_map_.find(servant + ACE_ENV_ARG_PARAMETER); + } + + return servant_state; +} TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h index 792dfde8131..66031d7df6e 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h @@ -60,13 +60,17 @@ namespace TAO public: /// Constructor. - TP_Strategy(unsigned num_threads = 1); + TP_Strategy(unsigned int num_threads = 1, + bool serialize_servants = true); /// Virtual Destructor. virtual ~TP_Strategy(); /// Set the number of threads in the pool (must be > 0). - void set_num_threads(unsigned num_threads); + void set_num_threads(unsigned int num_threads); + + /// Turn on/off serialization of servants. + void set_servant_serialization(bool serialize_servants); /// Return codes for the custom dispatch_request() methods. enum CustomRequestOutcome @@ -155,6 +159,25 @@ namespace TAO private: + /** + * Helper method that is responsible for looking up the servant + * state object in the servant state map *if* the "serialize + * servants" flag is set to true. In the case where the + * "serialize servants" flag is set to false, then a "nil" + * servant state handle object is returned. + * + * @param servant - input - a pointer to the servant object. + * + * @returns a handle to a servant state object. + * + * @throw PortableServer::POA::ServantNotActive if the servant + * state cannot be determined. + */ + TP_Servant_State::HandleType get_servant_state + (PortableServer::Servant servant + ACE_ENV_ARG_DECL); + + /// This is the active object used by the worker threads. /// The request queue is owned/managed by the task object. /// The strategy object puts requests into the task's request @@ -163,9 +186,13 @@ namespace TAO TP_Task task_; /// The number of worker threads to use for the task. - unsigned num_threads_; + unsigned int num_threads_; + + /// The "serialize servants" flag. + bool serialize_servants_; - /// The map of servant state objects. + /// The map of servant state objects - only used when the + /// "serialize servants" flag is set to true. TP_Servant_State_Map servant_state_map_; }; diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl index ef18cdba918..a0d9ef37fad 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl @@ -5,8 +5,10 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE -TAO::CSD::TP_Strategy::TP_Strategy(unsigned num_threads) - : num_threads_(num_threads) +TAO::CSD::TP_Strategy::TP_Strategy(unsigned int num_threads, + bool serialize_servants) + : num_threads_(num_threads), + serialize_servants_(serialize_servants) { // Assumes that num_threads > 0. } @@ -14,10 +16,20 @@ TAO::CSD::TP_Strategy::TP_Strategy(unsigned num_threads) ACE_INLINE void -TAO::CSD::TP_Strategy::set_num_threads(unsigned num_threads) +TAO::CSD::TP_Strategy::set_num_threads(unsigned int num_threads) { // Simple Mutator. Assumes that num_threads > 0. this->num_threads_ = num_threads; } + +ACE_INLINE +void +TAO::CSD::TP_Strategy::set_servant_serialization(bool serialize_servants) +{ + // Simple Mutator. + this->serialize_servants_ = serialize_servants; +} + + TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.cpp b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.cpp index 04934081678..f3234ce5568 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.cpp +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.cpp @@ -45,6 +45,7 @@ TAO::CSD::TP_Strategy_Factory::init (int argc, ACE_CString poa_name; unsigned long num_threads = 1; + bool serialize_servants = true; // Parse any service configurator parameters. for (int curarg = 0; curarg < argc; curarg++) @@ -57,8 +58,7 @@ TAO::CSD::TP_Strategy_Factory::init (int argc, // Parse the parameter ACE_CString arg ((const char *)argv[curarg]); ssize_t pos = arg.find (':'); - // If the number of threads is not specified then use the default value - // which is 1. + if (pos == ACE_CString::npos) { poa_name = arg; @@ -66,13 +66,47 @@ TAO::CSD::TP_Strategy_Factory::init (int argc, else { poa_name = arg.substr (0, pos); - ACE_CString num_thread_str = arg.substr (pos + 1, arg.length () - pos); + + ACE_CString arg_remainder = + arg.substr (pos + 1, arg.length () - pos); + + ACE_CString num_thread_str; + + pos = arg_remainder.find (':'); + + if (pos == ACE_CString::npos) + { + num_thread_str = arg_remainder; + } + else + { + num_thread_str = arg_remainder.substr (0, pos); + + ACE_CString off_str = + arg.substr (pos + 1, arg.length () - pos); + + // Case-insensitive string comparison. + if (ACE_OS::strcasecmp (off_str.c_str(), + ACE_TEXT("OFF")) == 0) + { + serialize_servants = false; + } + } + num_threads = ACE_OS::strtoul (num_thread_str.c_str (), 0, 10); + + if (num_threads == 0) + { + // Minimum of 1 thread required. + num_threads = 1; + } } // Create the ThreadPool strategy for each named poa. TP_Strategy* strategy = 0; - ACE_NEW_RETURN (strategy, TP_Strategy (num_threads), -1); + ACE_NEW_RETURN (strategy, + TP_Strategy (num_threads, serialize_servants), + -1); CSD_Framework::Strategy_var objref = strategy; TAO_CSD_Strategy_Repository *repo = |