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)
TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan (void) const
ACE_Time_Value const & dynamic_thread_time (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, TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan, ACE_Time_Value const &dynamic_thread_time)
 Constructor.
 ~TAO_Thread_Lane (void)
 Destructor.
void open (void)
 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 (void)
 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_
TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan
const 
lifespan_
ACE_Time_Value const dynamic_thread_time_
TAO_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 126 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,
TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan  lifespan,
ACE_Time_Value const &  dynamic_thread_time 
)

Constructor.

Definition at line 155 of file Thread_Pool.cpp.

TAO_Thread_Lane::~TAO_Thread_Lane ( void   ) 

Destructor.

Definition at line 357 of file Thread_Pool.cpp.

00358 {
00359 }


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 415 of file Thread_Pool.cpp.

References ACE_GUARD_RETURN, create_threads_i(), TAO_SYNCH_MUTEX, THR_BOUND, and THR_DETACHED.

00416 {
00417   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00418                     mon,
00419                     this->lock_,
00420                     0);
00421 
00422   return this->create_threads_i (this->dynamic_threads_,
00423                                  number_of_threads,
00424                                  THR_BOUND | THR_DETACHED);
00425 }

int TAO_Thread_Lane::create_static_threads ( void   ) 

Create the static threads - only called once.

Definition at line 401 of file Thread_Pool.cpp.

References ACE_GUARD_RETURN, create_threads_i(), TAO_SYNCH_MUTEX, THR_JOINABLE, and THR_NEW_LWP.

00402 {
00403   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00404                     mon,
00405                     this->lock_,
00406                     0);
00407 
00408   // Create static threads.
00409   return this->create_threads_i (this->static_threads_,
00410                                  this->static_threads_number_,
00411                                  THR_NEW_LWP | THR_JOINABLE);
00412 }

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 428 of file Thread_Pool.cpp.

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

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

00431 {
00432   // Overwritten parameters.
00433   int force_active = 1;
00434 
00435   // Default parameters.
00436   int default_grp_id = -1;
00437   ACE_Task_Base *default_task = 0;
00438   ACE_hthread_t *default_thread_handles = 0;
00439   void **default_stack = 0;
00440 
00441   // Setting stack size.
00442   size_t *stack_size_array = 0;
00443   ACE_NEW_RETURN (stack_size_array,
00444                   size_t[number_of_threads],
00445                   -1);
00446   size_t index;
00447   for (index = 0;
00448        index != number_of_threads;
00449        ++index)
00450     stack_size_array[index] =
00451       this->pool ().stack_size ();
00452 
00453   // Make sure the dynamically created stack size array is properly
00454   // deleted.
00455   ACE_Auto_Basic_Array_Ptr<size_t> auto_stack_size_array (stack_size_array);
00456 
00457   TAO_ORB_Core &orb_core =
00458     this->pool ().manager ().orb_core ();
00459 
00460   long flags =
00461     thread_flags |
00462     orb_core.orb_params ()->thread_creation_flags ();
00463 
00464   // Activate the threads.
00465   int result =
00466     thread_pool.activate (flags,
00467                           number_of_threads,
00468                           force_active,
00469                           this->native_priority_,
00470                           default_grp_id,
00471                           default_task,
00472                           default_thread_handles,
00473                           default_stack,
00474                           stack_size_array);
00475 
00476   if (result != 0)
00477     return result;
00478 
00479   return result;
00480 }

CORBA::ULong TAO_Thread_Lane::current_threads ( void   )  const

Definition at line 388 of file Thread_Pool.cpp.

References ACE_GUARD_RETURN, dynamic_threads_, TAO_SYNCH_MUTEX, and ACE_Task_Base::thr_count().

00389 {
00390   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00391                     mon,
00392                     this->lock_,
00393                     0);
00394 
00395   return (this->static_threads_.thr_count () +
00396          this->dynamic_threads_.thr_count ());
00397 }

ACE_INLINE ACE_Time_Value const & TAO_Thread_Lane::dynamic_thread_time ( void   )  const

Definition at line 72 of file Thread_Pool.inl.

References dynamic_thread_time_.

Referenced by TAO_Dynamic_Thread_Pool_Threads::run().

00073 {
00074   return this->dynamic_thread_time_;
00075 }

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 362 of file Thread_Pool.cpp.

References TAO_Thread_Lane_Resources::finalize(), and resources_.

00363 {
00364   // Finalize resources.
00365   this->resources_.finalize ();
00366 }

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

Definition at line 16 of file Thread_Pool.inl.

References id_.

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 382 of file Thread_Pool.cpp.

References TAO_Thread_Lane_Resources::is_collocated(), and resources_.

00383 {
00384   return this->resources_.is_collocated (mprofile);
00385 }

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 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan TAO_Thread_Lane::lifespan ( void   )  const

Definition at line 65 of file Thread_Pool.inl.

References lifespan_.

00066 {
00067   return this->lifespan_;
00068 }

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 180 of file Thread_Pool.cpp.

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

Referenced by TAO_RT_New_Leader_Generator::no_leaders_available().

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

void TAO_Thread_Lane::open ( void   ) 

Open the lane.

Definition at line 285 of file Thread_Pool.cpp.

References CORBA::SystemException::_tao_minor_code(), CORBA::COMPLETED_NO, 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().

00286 {
00287   // Validate and map priority.
00288   this->validate_and_map_priority ();
00289 
00290   char pool_lane_id[10];
00291   TAO_ORB_Parameters *params =
00292     this->pool ().manager ().orb_core ().orb_params ();
00293   TAO_EndpointSet endpoint_set;
00294 
00295   // Create a string just *:* which means all pools all thread id's
00296   ACE_OS::sprintf (pool_lane_id,
00297                    "*:*");
00298 
00299   // Get the endpoints for all
00300   params->get_endpoint_set (pool_lane_id, endpoint_set);
00301 
00302   // Create a string with pool:* which means all lanes for this pool
00303   ACE_OS::sprintf (pool_lane_id,
00304                    "%d:*",
00305                    this->pool ().id ());
00306 
00307   // Get the endpoints for this pool.
00308   params->get_endpoint_set (pool_lane_id, endpoint_set);
00309 
00310   // Create a string with *:lane which means a lan of all pools
00311   ACE_OS::sprintf (pool_lane_id,
00312                    "*:%d",
00313                    this->id ());
00314 
00315   // Get the endpoints for this lane.
00316   params->get_endpoint_set (pool_lane_id, endpoint_set);
00317 
00318   // Create a string with the pool:thread id.
00319   ACE_OS::sprintf (pool_lane_id,
00320                    "%d:%d",
00321                    this->pool ().id (),
00322                    this->id ());
00323 
00324   // Get the endpoints for this lane.
00325   params->get_endpoint_set (pool_lane_id, endpoint_set);
00326 
00327   bool ignore_address = false;
00328 
00329   if (endpoint_set.is_empty ())
00330     {
00331       // If endpoints are not specified for this lane, use the
00332       // endpoints specified for the default lane but ignore their
00333       // addresses.
00334       params->get_endpoint_set (TAO_DEFAULT_LANE, endpoint_set);
00335 
00336       ignore_address = true;
00337     }
00338   else
00339     {
00340       // If endpoints are specified for this lane, use them with their
00341       // addresses.
00342       ignore_address = false;
00343     }
00344 
00345   // Open the acceptor registry.
00346   int const result =
00347     this->resources_.open_acceptor_registry (endpoint_set, ignore_address);
00348 
00349   if (result == -1)
00350     throw ::CORBA::INTERNAL (
00351                  CORBA::SystemException::_tao_minor_code (
00352                    TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00353                    0),
00354                  CORBA::COMPLETED_NO);
00355 }

ACE_INLINE TAO_Thread_Pool & TAO_Thread_Lane::pool ( void   )  const

Definition at line 23 of file Thread_Pool.inl.

References pool_.

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 369 of file Thread_Pool.cpp.

References resources_, and TAO_Thread_Lane_Resources::shutdown_reactor().

00370 {
00371   this->resources_.shutdown_reactor ();
00372 }

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 227 of file Thread_Pool.cpp.

References ACE_GUARD, shutdown_, and TAO_SYNCH_MUTEX.

00228 {
00229   ACE_GUARD (TAO_SYNCH_MUTEX,
00230              mon,
00231              this->lock_);
00232 
00233   // We are shutting down, this way we are not creating any more new dynamic
00234   // threads
00235   this->shutdown_ = true;
00236 }

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 ( void   )  [private]

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

Definition at line 239 of file Thread_Pool.cpp.

References TAO_Priority_Mapping_Manager::_narrow(), ACE_DEBUG, ACE_TEXT, TAO_Priority_Mapping_Manager_var::in(), TAO_Pseudo_Var_T< T >::in(), LM_DEBUG, TAO_Thread_Pool::manager(), TAO_Priority_Mapping_Manager::mapping(), TAO_ORB_Core::orb(), TAO_Thread_Pool_Manager::orb_core(), pool_, CORBA::ORB::resolve_initial_references(), TAO_debug_level, and TAO_OBJID_PRIORITYMAPPINGMANAGER.

Referenced by open().

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

void TAO_Thread_Lane::wait ( void   ) 

Wait for threads to exit.

Definition at line 375 of file Thread_Pool.cpp.

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

00376 {
00377   this->static_threads_.wait ();
00378   this->dynamic_threads_.wait ();
00379 }


Member Data Documentation

ACE_Time_Value const TAO_Thread_Lane::dynamic_thread_time_ [private]

Definition at line 241 of file Thread_Pool.h.

Referenced by dynamic_thread_time().

TAO_Dynamic_Thread_Pool_Threads TAO_Thread_Lane::dynamic_threads_ [private]

Array with all dynamic threads.

Definition at line 231 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 225 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 213 of file Thread_Pool.h.

Referenced by id(), and new_dynamic_thread().

CORBA::Short TAO_Thread_Lane::lane_priority_ [private]

Definition at line 215 of file Thread_Pool.h.

Referenced by lane_priority().

TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan const TAO_Thread_Lane::lifespan_ [private]

Definition at line 239 of file Thread_Pool.h.

Referenced by lifespan().

TAO_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 237 of file Thread_Pool.h.

Referenced by native_priority().

TAO_RT_New_Leader_Generator TAO_Thread_Lane::new_thread_generator_ [private]

Definition at line 233 of file Thread_Pool.h.

TAO_Thread_Pool& TAO_Thread_Lane::pool_ [private]

The Thread Pool to which this lane belongs.

Definition at line 210 of file Thread_Pool.h.

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

TAO_Thread_Lane_Resources TAO_Thread_Lane::resources_ [private]

Definition at line 235 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 219 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 228 of file Thread_Pool.h.

Referenced by wait().

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

Number of static threads.

Definition at line 222 of file Thread_Pool.h.

Referenced by new_dynamic_thread(), and static_threads().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:43:03 2010 for TAO_RTCORBA by  doxygen 1.4.7