Public Member Functions | Private Member Functions | Private Attributes

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.

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.

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

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 
)
TAO_Thread_Lane::~TAO_Thread_Lane ( void   ) 

Destructor.

Definition at line 360 of file Thread_Pool.cpp.

{
}


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

{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    mon,
                    this->lock_,
                    0);

  return this->create_threads_i (this->dynamic_threads_,
                                 number_of_threads,
                                 THR_BOUND | THR_DETACHED);
}

int TAO_Thread_Lane::create_static_threads ( void   ) 

Create the static threads - only called once.

Definition at line 404 of file Thread_Pool.cpp.

{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    mon,
                    this->lock_,
                    0);

  // Create static threads.
  return this->create_threads_i (this->static_threads_,
                                 this->static_threads_number_,
                                 THR_NEW_LWP | THR_JOINABLE);
}

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

{
  // Overwritten parameters.
  int force_active = 1;

  // Default parameters.
  int default_grp_id = -1;
  ACE_Task_Base *default_task = 0;
  ACE_hthread_t *default_thread_handles = 0;
  void **default_stack = 0;

  // Setting stack size.
  size_t *stack_size_array = 0;
  ACE_NEW_RETURN (stack_size_array,
                  size_t[number_of_threads],
                  -1);
  size_t index;
  for (index = 0;
       index != number_of_threads;
       ++index)
    stack_size_array[index] =
      this->pool ().stack_size ();

  // Make sure the dynamically created stack size array is properly
  // deleted.
  ACE_Auto_Basic_Array_Ptr<size_t> auto_stack_size_array (stack_size_array);

  TAO_ORB_Core &orb_core =
    this->pool ().manager ().orb_core ();

  long flags =
    thread_flags |
    orb_core.orb_params ()->thread_creation_flags ();

  // Activate the threads.
  int result =
    thread_pool.activate (flags,
                          number_of_threads,
                          force_active,
                          this->native_priority_,
                          default_grp_id,
                          default_task,
                          default_thread_handles,
                          default_stack,
                          stack_size_array);

  if (result != 0)
    return result;

  return result;
}

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

Definition at line 391 of file Thread_Pool.cpp.

{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    mon,
                    this->lock_,
                    0);

  return (this->static_threads_.thr_count () +
         this->dynamic_threads_.thr_count ());
}

ACE_Time_Value const & TAO_Thread_Lane::dynamic_thread_time ( void   )  const

Definition at line 72 of file Thread_Pool.inl.

{
  return this->dynamic_thread_time_;
}

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

Definition at line 51 of file Thread_Pool.inl.

{
  return this->dynamic_threads_number_;
}

void TAO_Thread_Lane::finalize ( void   ) 

Finalize the resources.

Definition at line 365 of file Thread_Pool.cpp.

{
  // Finalize resources.
  this->resources_.finalize ();
}

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

Definition at line 16 of file Thread_Pool.inl.

{
  return this->id_;
}

int TAO_Thread_Lane::is_collocated ( const TAO_MProfile mprofile  ) 

Does mprofile belong to us?

Definition at line 385 of file Thread_Pool.cpp.

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

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

Definition at line 30 of file Thread_Pool.inl.

{
  return this->lane_priority_;
}

TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan TAO_Thread_Lane::lifespan ( void   )  const

Definition at line 65 of file Thread_Pool.inl.

{
  return this->lifespan_;
}

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

Definition at line 37 of file Thread_Pool.inl.

{
  return this->native_priority_;
}

bool TAO_Thread_Lane::new_dynamic_thread ( void   ) 

Called by the TAO_RT_New_Leader_Generator to request a new dynamic thread. 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 183 of file Thread_Pool.cpp.

{
  // Note that we are checking this condition below without the lock
  // held.
  if (this->dynamic_threads_.thr_count () >= this->dynamic_threads_number_)
    return false;

  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    mon,
                    this->lock_,
                    false);

  TAO_Thread_Pool_Manager &manager = this->pool_.manager ();

  if (!manager.orb_core ().has_shutdown () && !this->shutdown_&&
      this->dynamic_threads_.thr_count () < this->dynamic_threads_number_)
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO Process %P Pool %d Lane %d Thread %t\n")
                    ACE_TEXT ("Current number of dynamic threads = %d; ")
                    ACE_TEXT ("static threads = %d; max dynamic threads = %d\n")
                    ACE_TEXT ("No leaders available; creating new leader!\n"),
                    this->pool_.id (),
                    this->id_,
                    this->dynamic_threads_.thr_count (),
                    this->static_threads_number_,
                    this->dynamic_threads_number_));

      int result =
        this->create_threads_i (this->dynamic_threads_,
                                1,
                                THR_BOUND | THR_DETACHED);

      if (result != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                          ACE_TEXT ("Pool %d Lane %d Thread %t: ")
                          ACE_TEXT ("cannot create dynamic thread\n"),
                          this->pool_.id (),
                          this->id_),
                          false);
    }

  return true;
}

void TAO_Thread_Lane::open ( void   ) 

Open the lane.

Definition at line 288 of file Thread_Pool.cpp.

{
  // Validate and map priority.
  this->validate_and_map_priority ();

  char pool_lane_id[10];
  TAO_ORB_Parameters *params =
    this->pool ().manager ().orb_core ().orb_params ();
  TAO_EndpointSet endpoint_set;

  // Create a string just *:* which means all pools all thread id's
  ACE_OS::sprintf (pool_lane_id,
                   "*:*");

  // Get the endpoints for all
  params->get_endpoint_set (pool_lane_id, endpoint_set);

  // Create a string with pool:* which means all lanes for this pool
  ACE_OS::sprintf (pool_lane_id,
                   "%d:*",
                   this->pool ().id ());

  // Get the endpoints for this pool.
  params->get_endpoint_set (pool_lane_id, endpoint_set);

  // Create a string with *:lane which means a lan of all pools
  ACE_OS::sprintf (pool_lane_id,
                   "*:%d",
                   this->id ());

  // Get the endpoints for this lane.
  params->get_endpoint_set (pool_lane_id, endpoint_set);

  // Create a string with the pool:thread id.
  ACE_OS::sprintf (pool_lane_id,
                   "%d:%d",
                   this->pool ().id (),
                   this->id ());

  // Get the endpoints for this lane.
  params->get_endpoint_set (pool_lane_id, endpoint_set);

  bool ignore_address = false;

  if (endpoint_set.is_empty ())
    {
      // If endpoints are not specified for this lane, use the
      // endpoints specified for the default lane but ignore their
      // addresses.
      params->get_endpoint_set (TAO_DEFAULT_LANE, endpoint_set);

      ignore_address = true;
    }
  else
    {
      // If endpoints are specified for this lane, use them with their
      // addresses.
      ignore_address = false;
    }

  // Open the acceptor registry.
  int const result =
    this->resources_.open_acceptor_registry (endpoint_set, ignore_address);

  if (result == -1)
    throw ::CORBA::INTERNAL (
                 CORBA::SystemException::_tao_minor_code (
                   TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
                   0),
                 CORBA::COMPLETED_NO);
}

TAO_Thread_Pool & TAO_Thread_Lane::pool ( void   )  const

Definition at line 23 of file Thread_Pool.inl.

{
  return this->pool_;
}

TAO_Thread_Lane_Resources & TAO_Thread_Lane::resources ( void   ) 

Definition at line 58 of file Thread_Pool.inl.

{
  return this->resources_;
}

void TAO_Thread_Lane::shutdown_reactor ( void   ) 

Shutdown the reactor.

Definition at line 372 of file Thread_Pool.cpp.

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

{
  ACE_GUARD (TAO_SYNCH_MUTEX,
             mon,
             this->lock_);

  // We are shutting down, this way we are not creating any more new dynamic
  // threads
  this->shutdown_ = true;
}

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

Definition at line 44 of file Thread_Pool.inl.

{
  return this->static_threads_number_;
}

void TAO_Thread_Lane::validate_and_map_priority ( void   )  [private]

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

Definition at line 242 of file Thread_Pool.cpp.

{
  // Make sure that static_threads_number_ is not zero.
  if (this->static_threads_number_ == 0)
    throw ::CORBA::BAD_PARAM ();

  // Check that the priority is in bounds.
  if (this->lane_priority_ < RTCORBA::minPriority
           // The line below will always be false unless the value of
           // RTCORBA::maxPriority, which is now assigned the value of
           // 32767, is changed in RTCORBA.pidl.
//      || this->lane_priority_ > RTCORBA::maxPriority
     )
    {
      throw ::CORBA::BAD_PARAM ();
    }

  CORBA::ORB_ptr orb = this->pool_.manager ().orb_core ().orb ();

  // Get the priority mapping manager.
  CORBA::Object_var obj =
    orb->resolve_initial_references (TAO_OBJID_PRIORITYMAPPINGMANAGER);

  TAO_Priority_Mapping_Manager_var mapping_manager =
    TAO_Priority_Mapping_Manager::_narrow (obj.in ());

  RTCORBA::PriorityMapping *pm = mapping_manager.in ()->mapping ();

  // Map CORBA priority to native priority.
  CORBA::Boolean const result =
    pm->to_native (this->lane_priority_, this->native_priority_);

  if (!result)
    throw ::CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);

  if (TAO_debug_level > 3)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - creating thread at ")
                  ACE_TEXT ("(corba:native) priority %d:%d\n"),
                  this->lane_priority_,
                  this->native_priority_));
    }
}

void TAO_Thread_Lane::wait ( void   ) 

Wait for threads to exit.

Definition at line 378 of file Thread_Pool.cpp.

{
  this->static_threads_.wait ();
  this->dynamic_threads_.wait ();
}


Member Data Documentation

Definition at line 241 of file Thread_Pool.h.

Array with all dynamic threads.

Definition at line 231 of file Thread_Pool.h.

Maximum number of threads we are allowed to create.

Definition at line 225 of file Thread_Pool.h.

The id of this lane.

Definition at line 213 of file Thread_Pool.h.

Definition at line 215 of file Thread_Pool.h.

Definition at line 239 of file Thread_Pool.h.

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.

Definition at line 237 of file Thread_Pool.h.

Definition at line 233 of file Thread_Pool.h.

The Thread Pool to which this lane belongs.

Definition at line 210 of file Thread_Pool.h.

Definition at line 235 of file Thread_Pool.h.

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.

Array with all static threads.

Definition at line 228 of file Thread_Pool.h.

Number of static threads.

Definition at line 222 of file Thread_Pool.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines