TAO_Thread_Lane Class Reference

Class representing the thread lane inside a thread pool. More...

#include <Thread_Pool.h>

Collaboration diagram for TAO_Thread_Lane:

Collaboration graph
[legend]
List of all members.

Accessors

TAO_Thread_Poolpool (void) const
CORBA::ULong id (void) const
CORBA::Short lane_priority (void) const
CORBA::ULong static_threads (void) const
CORBA::ULong dynamic_threads (void) const
CORBA::ULong current_threads (void) const
CORBA::Short native_priority (void) const
TAO_Thread_Lane_Resourcesresources (void)
ACE_Time_Value const & dynamic_thread_idle_timeout (void) const

Public Member Functions

 TAO_Thread_Lane (TAO_Thread_Pool &pool, CORBA::ULong id, CORBA::Short lane_priority, CORBA::ULong static_threads, CORBA::ULong dynamic_threads, ACE_Time_Value const &dynamic_thread_idle_timeout)
 Constructor.

 ~TAO_Thread_Lane (void)
 Destructor.

void open ()
 Open the lane.

void finalize (void)
 Finalize the resources.

void shutdown_reactor (void)
 Shutdown the reactor.

void wait (void)
 Wait for threads to exit.

int is_collocated (const TAO_MProfile &mprofile)
 Does mprofile belong to us?

int create_static_threads (void)
 Create the static threads - only called once.

void shutting_down (void)
bool new_dynamic_thread (void)

Private Member Functions

void validate_and_map_priority ()
 Validate lane's priority and map it to a native value.

int create_threads_i (TAO_Thread_Pool_Threads &thread_pool, CORBA::ULong number_of_threads, long thread_flags)
int create_dynamic_threads (CORBA::ULong number_of_threads)

Private Attributes

TAO_Thread_Poolpool_
 The Thread Pool to which this lane belongs.

CORBA::ULong const  id_
 The id of this lane.

CORBA::Short lane_priority_
bool shutdown_
CORBA::ULong const  static_threads_number_
 Number of static threads.

CORBA::ULong const  dynamic_threads_number_
 Maximum number of threads we are allowed to create.

TAO_Thread_Pool_Threads static_threads_
 Array with all static threads.

TAO_Dynamic_Thread_Pool_Threads dynamic_threads_
 Array with all dynamic threads.

TAO_RT_New_Leader_Generator new_thread_generator_
TAO_Thread_Lane_Resources resources_
CORBA::Short native_priority_
ACE_Time_Value const  dynamic_thread_idle_timeout_
ACE_SYNCH_MUTEX lock_
 Lock to guard all members of the lane.


Detailed Description

Class representing the thread lane inside a thread pool.

Definition at line 128 of file Thread_Pool.h.


Constructor & Destructor Documentation

TAO_Thread_Lane::TAO_Thread_Lane TAO_Thread_Pool pool,
CORBA::ULong  id,
CORBA::Short  lane_priority,
CORBA::ULong  static_threads,
CORBA::ULong  dynamic_threads,
ACE_Time_Value const &  dynamic_thread_idle_timeout
 

Constructor.

Definition at line 143 of file Thread_Pool.cpp.

References TAO_INVALID_PRIORITY.

00150   : pool_ (pool),
00151     id_ (id),
00152     lane_priority_ (lane_priority),
00153     shutdown_ (false),
00154     static_threads_number_ (static_threads),
00155     dynamic_threads_number_ (dynamic_threads),
00156     static_threads_ (*this),
00157     dynamic_threads_ (*this),
00158     new_thread_generator_ (*this),
00159     resources_ (pool.manager ().orb_core (),
00160                 &new_thread_generator_),
00161     native_priority_ (TAO_INVALID_PRIORITY),
00162     dynamic_thread_idle_timeout_ (dynamic_thread_idle_timeout)
00163 {
00164 }

TAO_Thread_Lane::~TAO_Thread_Lane void   ) 
 

Destructor.

Definition at line 336 of file Thread_Pool.cpp.

00337 {
00338 }


Member Function Documentation

int TAO_Thread_Lane::create_dynamic_threads CORBA::ULong  number_of_threads  )  [private]
 

Create number_of_threads of dynamic threads. Can be called multiple times.

Definition at line 394 of file Thread_Pool.cpp.

References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, and create_threads_i().

00395 {
00396   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
00397                     mon,
00398                     this->lock_,
00399                     0);
00400 
00401   return this->create_threads_i (this->dynamic_threads_,
00402                                  number_of_threads,
00403                                  THR_BOUND | THR_DETACHED);
00404 }

int TAO_Thread_Lane::create_static_threads void   ) 
 

Create the static threads - only called once.

Definition at line 380 of file Thread_Pool.cpp.

References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, and create_threads_i().

Referenced by TAO_Thread_Pool::create_static_threads().

00381 {
00382   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
00383                     mon,
00384                     this->lock_,
00385                     0);
00386 
00387   // Create static threads.
00388   return this->create_threads_i (this->static_threads_,
00389                                  this->static_threads_number_,
00390                                  THR_NEW_LWP | THR_JOINABLE);
00391 }

int TAO_Thread_Lane::create_threads_i TAO_Thread_Pool_Threads thread_pool,
CORBA::ULong  number_of_threads,
long  thread_flags
[private]
 

Definition at line 407 of file Thread_Pool.cpp.

References ACE_hthread_t, ACE_NEW_RETURN, ACE_Task_Base::activate(), TAO_Thread_Pool::manager(), TAO_Thread_Pool_Manager::orb_core(), TAO_ORB_Core::orb_params(), pool(), TAO_Thread_Pool::stack_size(), and TAO_ORB_Parameters::thread_creation_flags().

Referenced by create_dynamic_threads(), create_static_threads(), and new_dynamic_thread().

00410 {
00411   // Overwritten parameters.
00412   int force_active = 1;
00413 
00414   // Default parameters.
00415   int default_grp_id = -1;
00416   ACE_Task_Base *default_task = 0;
00417   ACE_hthread_t *default_thread_handles = 0;
00418   void **default_stack = 0;
00419 
00420   // Setting stack size.
00421   size_t *stack_size_array = 0;
00422   ACE_NEW_RETURN (stack_size_array,
00423                   size_t[number_of_threads],
00424                   -1);
00425   size_t index;
00426   for (index = 0;
00427        index != number_of_threads;
00428        ++index)
00429     stack_size_array[index] =
00430       this->pool ().stack_size ();
00431 
00432   // Make sure the dynamically created stack size array is properly
00433   // deleted.
00434   ACE_Auto_Basic_Array_Ptr<size_t> auto_stack_size_array (stack_size_array);
00435 
00436   TAO_ORB_Core &orb_core =
00437     this->pool ().manager ().orb_core ();
00438 
00439   long flags =
00440     thread_flags |
00441     orb_core.orb_params ()->thread_creation_flags ();
00442 
00443   // Activate the threads.
00444   int result =
00445     thread_pool.activate (flags,
00446                           number_of_threads,
00447                           force_active,
00448                           this->native_priority_,
00449                           default_grp_id,
00450                           default_task,
00451                           default_thread_handles,
00452                           default_stack,
00453                           stack_size_array);
00454 
00455   if (result != 0)
00456     return result;
00457 
00458   return result;
00459 }

CORBA::ULong TAO_Thread_Lane::current_threads void   )  const
 

Definition at line 367 of file Thread_Pool.cpp.

References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, dynamic_threads_, static_threads_, and ACE_Task_Base::thr_count().

00368 {
00369   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
00370                     mon,
00371                     this->lock_,
00372                     0);
00373 
00374   return (this->static_threads_.thr_count () +
00375          this->dynamic_threads_.thr_count ());
00376 }

ACE_INLINE ACE_Time_Value const & TAO_Thread_Lane::dynamic_thread_idle_timeout void   )  const
 

Definition at line 65 of file Thread_Pool.inl.

Referenced by TAO_Dynamic_Thread_Pool_Threads::run().

00066 {
00067   return this->dynamic_thread_idle_timeout_;
00068 }

ACE_INLINE CORBA::ULong TAO_Thread_Lane::dynamic_threads void   )  const
 

Definition at line 51 of file Thread_Pool.inl.

References dynamic_threads_number_.

00052 {
00053   return this->dynamic_threads_number_;
00054 }

void TAO_Thread_Lane::finalize void   ) 
 

Finalize the resources.

Definition at line 341 of file Thread_Pool.cpp.

References TAO_Thread_Lane_Resources::finalize(), and resources_.

Referenced by TAO_Thread_Pool::finalize().

00342 {
00343   // Finalize resources.
00344   this->resources_.finalize ();
00345 }

ACE_INLINE CORBA::ULong TAO_Thread_Lane::id void   )  const
 

Definition at line 16 of file Thread_Pool.inl.

Referenced by open(), and TAO_Dynamic_Thread_Pool_Threads::run().

00017 {
00018   return this->id_;
00019 }

int TAO_Thread_Lane::is_collocated const TAO_MProfile mprofile  ) 
 

Does mprofile belong to us?

Definition at line 361 of file Thread_Pool.cpp.

References TAO_Thread_Lane_Resources::is_collocated(), and resources_.

Referenced by TAO_Thread_Pool::is_collocated().

00362 {
00363   return this->resources_.is_collocated (mprofile);
00364 }

ACE_INLINE CORBA::Short TAO_Thread_Lane::lane_priority void   )  const
 

Definition at line 30 of file Thread_Pool.inl.

References lane_priority_.

00031 {
00032   return this->lane_priority_;
00033 }

ACE_INLINE CORBA::Short TAO_Thread_Lane::native_priority void   )  const
 

Definition at line 37 of file Thread_Pool.inl.

References native_priority_.

00038 {
00039   return this->native_priority_;
00040 }

bool TAO_Thread_Lane::new_dynamic_thread void   ) 
 

It can be that no thread can be created because the number of threads is equal to the maximum we can have or the Thread Lane is shutting down.

Return values:
true A new thread is created
false No thread could be created

Definition at line 167 of file Thread_Pool.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, ACE_TEXT, create_threads_i(), dynamic_threads_, dynamic_threads_number_, TAO_ORB_Core::has_shutdown(), LM_DEBUG, LM_ERROR, TAO_Thread_Pool::manager(), TAO_Thread_Pool_Manager::orb_core(), shutdown_, static_threads_number_, TAO_debug_level, and ACE_Task_Base::thr_count().

Referenced by TAO_RT_New_Leader_Generator::no_leaders_available().

00168 {
00169   // Note that we are checking this condition below without the lock
00170   // held.
00171   if (this->dynamic_threads_.thr_count () >= this->dynamic_threads_number_)
00172     return false;
00173 
00174   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
00175                     mon,
00176                     this->lock_,
00177                     false);
00178 
00179   TAO_Thread_Pool_Manager &manager =
00180     this->pool_.manager ();
00181 
00182   if (!manager.orb_core ().has_shutdown () && !this->shutdown_&&
00183       this->dynamic_threads_.thr_count () < this->dynamic_threads_number_)
00184     {
00185       if (TAO_debug_level > 0)
00186         ACE_DEBUG ((LM_DEBUG,
00187                     ACE_TEXT ("TAO Process %P Pool %d Lane %d Thread %t\n")
00188                     ACE_TEXT ("Current number of dynamic threads = %d; ")
00189                     ACE_TEXT ("static threads = %d; max dynamic threads = %d\n")
00190                     ACE_TEXT ("No leaders available; creating new leader!\n"),
00191                     this->pool_.id (),
00192                     this->id_,
00193                     this->dynamic_threads_.thr_count (),
00194                     this->static_threads_number_,
00195                     this->dynamic_threads_number_));
00196 
00197       int result =
00198         this->create_threads_i (this->dynamic_threads_,
00199                                 1,
00200                                 THR_BOUND | THR_DETACHED);
00201 
00202       if (result != 0)
00203         ACE_ERROR_RETURN ((LM_ERROR,
00204                           ACE_TEXT ("Pool %d Lane %d Thread %t: ")
00205                           ACE_TEXT ("cannot create dynamic thread\n"),
00206                           this->pool_.id (),
00207                           this->id_),
00208                           false);
00209     }
00210 
00211   return true;
00212 }

void TAO_Thread_Lane::open  ) 
 

Open the lane.

Definition at line 280 of file Thread_Pool.cpp.

References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_THROW, TAO_ORB_Parameters::get_endpoint_set(), id(), TAO_Thread_Pool::manager(), TAO_Thread_Lane_Resources::open_acceptor_registry(), TAO_Thread_Pool_Manager::orb_core(), TAO_ORB_Core::orb_params(), pool(), resources_, ACE_OS::sprintf(), TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE, TAO_DEFAULT_LANE, TAO_EndpointSet, and validate_and_map_priority().

Referenced by TAO_Thread_Pool::open().

00281 {
00282   // Validate and map priority.
00283   this->validate_and_map_priority (ACE_ENV_SINGLE_ARG_PARAMETER);
00284   ACE_CHECK;
00285 
00286   // Create a string with the pool:thread id.
00287   char pool_lane_id[10];
00288   ACE_OS::sprintf (pool_lane_id,
00289                    "%d:%d",
00290                    this->pool ().id (),
00291                    this->id ());
00292 
00293   TAO_ORB_Parameters *params =
00294     this->pool ().manager ().orb_core ().orb_params ();
00295 
00296   TAO_EndpointSet endpoint_set;
00297   bool ignore_address;
00298 
00299   // Get the endpoints for this lane.
00300   params->get_endpoint_set (pool_lane_id,
00301                             endpoint_set);
00302 
00303   if (endpoint_set.is_empty ())
00304     {
00305       // If endpoints are not specified for this lane, use the
00306       // endpoints specified for the default lane but ignore their
00307       // addresses.
00308       params->get_endpoint_set (TAO_DEFAULT_LANE,
00309                                 endpoint_set);
00310 
00311       ignore_address = true;
00312     }
00313   else
00314     {
00315       // If endpoints are specified for this lane, use them with thier
00316       // addresses.
00317       ignore_address = false;
00318     }
00319 
00320   // Open the acceptor registry.
00321   int result = 0;
00322   result =
00323     this->resources_.open_acceptor_registry (endpoint_set,
00324                                              ignore_address
00325                                              ACE_ENV_ARG_PARAMETER);
00326   ACE_CHECK;
00327 
00328   if (result == -1)
00329     ACE_THROW (CORBA::INTERNAL (
00330                  CORBA::SystemException::_tao_minor_code (
00331                    TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00332                    0),
00333                  CORBA::COMPLETED_NO));
00334 }

ACE_INLINE TAO_Thread_Pool & TAO_Thread_Lane::pool void   )  const
 

Definition at line 23 of file Thread_Pool.inl.

Referenced by create_threads_i(), open(), and TAO_Thread_Pool_Threads::svc().

00024 {
00025   return this->pool_;
00026 }

ACE_INLINE TAO_Thread_Lane_Resources & TAO_Thread_Lane::resources void   ) 
 

Definition at line 58 of file Thread_Pool.inl.

References resources_.

Referenced by TAO_RT_Thread_Lane_Resources_Manager::lane_resources().

00059 {
00060   return this->resources_;
00061 }

void TAO_Thread_Lane::shutdown_reactor void   ) 
 

Shutdown the reactor.

Definition at line 348 of file Thread_Pool.cpp.

References resources_, and TAO_Thread_Lane_Resources::shutdown_reactor().

Referenced by TAO_Thread_Pool::shutdown_reactor().

00349 {
00350   this->resources_.shutdown_reactor ();
00351 }

void TAO_Thread_Lane::shutting_down void   ) 
 

Mark that this lane is shutting down, we then don't create any dynamic threads anymore. When the pool is shutting down the leader follower loop is called which can cause a request to create a new dynamic thread but we shouldn't create a new one.

Definition at line 215 of file Thread_Pool.cpp.

References ACE_GUARD, ACE_SYNCH_MUTEX, and shutdown_.

Referenced by TAO_Thread_Pool::shutting_down().

00216 {
00217   ACE_GUARD (ACE_SYNCH_MUTEX,
00218              mon,
00219              this->lock_);
00220 
00221   // We are shutting down, this way we are not creating any more new dynamic
00222   // threads
00223   this->shutdown_ = true;
00224 }

ACE_INLINE CORBA::ULong TAO_Thread_Lane::static_threads void   )  const
 

Definition at line 44 of file Thread_Pool.inl.

References static_threads_number_.

00045 {
00046   return this->static_threads_number_;
00047 }

void TAO_Thread_Lane::validate_and_map_priority  )  [private]
 

Validate lane's priority and map it to a native value.

Definition at line 227 of file Thread_Pool.cpp.

References TAO_Priority_Mapping_Manager::_narrow(), ACE_CHECK, ACE_DEBUG, ACE_ENV_ARG_PARAMETER, ACE_TEXT, ACE_THROW, TAO_Priority_Mapping_Manager_var::in(), lane_priority_, LM_DEBUG, TAO_Thread_Pool::manager(), TAO_Priority_Mapping_Manager::mapping(), TAO_ORB_Core::orb(), TAO_Thread_Pool_Manager::orb_core(), static_threads_number_, TAO_debug_level, and TAO_OBJID_PRIORITYMAPPINGMANAGER.

Referenced by open().

00228 {
00229   // Make sure that static_threads_number_ is not zero.
00230   if (this->static_threads_number_ == 0)
00231     ACE_THROW (CORBA::BAD_PARAM ());
00232 
00233   // Check that the priority is in bounds.
00234   if (this->lane_priority_ < RTCORBA::minPriority
00235            // The line below will always be false unless the value of
00236            // RTCORBA::maxPriority, which is now assigned the value of
00237            // 32767, is changed in RTCORBA.pidl.
00238 //      || this->lane_priority_ > RTCORBA::maxPriority
00239      )
00240     {
00241       ACE_THROW (CORBA::BAD_PARAM ());
00242     }
00243 
00244   CORBA::ORB_ptr orb =
00245     this->pool_.manager ().orb_core ().orb ();
00246 
00247   // Get the priority mapping manager.
00248   CORBA::Object_var obj =
00249     orb->resolve_initial_references (TAO_OBJID_PRIORITYMAPPINGMANAGER
00250                                      ACE_ENV_ARG_PARAMETER);
00251   ACE_CHECK;
00252 
00253   TAO_Priority_Mapping_Manager_var mapping_manager =
00254     TAO_Priority_Mapping_Manager::_narrow (obj.in ()
00255                                            ACE_ENV_ARG_PARAMETER);
00256   ACE_CHECK;
00257 
00258   RTCORBA::PriorityMapping *pm =
00259     mapping_manager.in ()->mapping ();
00260 
00261   // Map CORBA priority to native priority.
00262   CORBA::Boolean result =
00263     pm->to_native (this->lane_priority_,
00264                    this->native_priority_);
00265 
00266   if (!result)
00267     ACE_THROW (CORBA::DATA_CONVERSION ());
00268 
00269   if (TAO_debug_level > 3)
00270     {
00271       ACE_DEBUG ((LM_DEBUG,
00272                   ACE_TEXT ("TAO (%P|%t) - creating thread at ")
00273                   ACE_TEXT ("(corba:native) priority %d:%d\n"),
00274                   this->lane_priority_,
00275                   this->native_priority_));
00276     }
00277 }

void TAO_Thread_Lane::wait void   ) 
 

Wait for threads to exit.

Definition at line 354 of file Thread_Pool.cpp.

References dynamic_threads_, static_threads_, and ACE_Task_Base::wait().

Referenced by TAO_Thread_Pool::wait().

00355 {
00356   this->static_threads_.wait ();
00357   this->dynamic_threads_.wait ();
00358 }


Member Data Documentation

ACE_Time_Value const TAO_Thread_Lane::dynamic_thread_idle_timeout_ [private]
 

Definition at line 241 of file Thread_Pool.h.

TAO_Dynamic_Thread_Pool_Threads TAO_Thread_Lane::dynamic_threads_ [private]
 

Array with all dynamic threads.

Definition at line 233 of file Thread_Pool.h.

Referenced by current_threads(), new_dynamic_thread(), and wait().

CORBA::ULong const TAO_Thread_Lane::dynamic_threads_number_ [private]
 

Maximum number of threads we are allowed to create.

Definition at line 227 of file Thread_Pool.h.

Referenced by dynamic_threads(), and new_dynamic_thread().

CORBA::ULong const TAO_Thread_Lane::id_ [private]
 

The id of this lane.

Definition at line 215 of file Thread_Pool.h.

CORBA::Short TAO_Thread_Lane::lane_priority_ [private]
 

Definition at line 217 of file Thread_Pool.h.

Referenced by lane_priority(), and validate_and_map_priority().

ACE_SYNCH_MUTEX TAO_Thread_Lane::lock_ [mutable, private]
 

Lock to guard all members of the lane.

Definition at line 244 of file Thread_Pool.h.

CORBA::Short TAO_Thread_Lane::native_priority_ [private]
 

Definition at line 239 of file Thread_Pool.h.

Referenced by native_priority().

TAO_RT_New_Leader_Generator TAO_Thread_Lane::new_thread_generator_ [private]
 

Definition at line 235 of file Thread_Pool.h.

TAO_Thread_Pool& TAO_Thread_Lane::pool_ [private]
 

The Thread Pool to which this lane belongs.

Definition at line 212 of file Thread_Pool.h.

TAO_Thread_Lane_Resources TAO_Thread_Lane::resources_ [private]
 

Definition at line 237 of file Thread_Pool.h.

Referenced by finalize(), is_collocated(), open(), resources(), and shutdown_reactor().

bool TAO_Thread_Lane::shutdown_ [private]
 

This boolean is set when we are shutting down, then we will not create any new dynamic threads

Definition at line 221 of file Thread_Pool.h.

Referenced by new_dynamic_thread(), and shutting_down().

TAO_Thread_Pool_Threads TAO_Thread_Lane::static_threads_ [private]
 

Array with all static threads.

Definition at line 230 of file Thread_Pool.h.

Referenced by current_threads(), and wait().

CORBA::ULong const TAO_Thread_Lane::static_threads_number_ [private]
 

Number of static threads.

Definition at line 224 of file Thread_Pool.h.

Referenced by new_dynamic_thread(), static_threads(), and validate_and_map_priority().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:00:05 2006 for TAO_RTCORBA by doxygen 1.3.6