TAO_Thread_Pool_Manager Class Reference

Class for managing thread pools. More...

#include <Thread_Pool.h>

Collaboration diagram for TAO_Thread_Pool_Manager:

Collaboration graph
[legend]
List of all members.

Accessors

TAO_ORB_Coreorb_core (void) const

Helpers

RTCORBA::ThreadpoolId create_threadpool_i (CORBA::ULong stacksize, CORBA::ULong static_threads, CORBA::ULong dynamic_threads, RTCORBA::Priority default_priority, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, ACE_Time_Value const &dynamic_thread_idle_timeout)
RTCORBA::ThreadpoolId create_threadpool_with_lanes_i (CORBA::ULong stacksize, const RTCORBA::ThreadpoolLanes &lanes, CORBA::Boolean allow_borrowing, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, ACE_Time_Value const &dynamic_thread_idle_timeout)
RTCORBA::ThreadpoolId create_threadpool_helper (TAO_Thread_Pool *thread_pool)

Public Types

typedef ACE_Hash_Map_Manager<
RTCORBA::ThreadpoolId, TAO_Thread_Pool *,
ACE_Null_Mutex
THREAD_POOLS
 Collection of thread pools.


Public Member Functions

 TAO_Thread_Pool_Manager (TAO_ORB_Core &orb_core)
 Constructor.

 ~TAO_Thread_Pool_Manager (void)
 Destructor.

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?

RTCORBA::ThreadpoolId create_threadpool (CORBA::ULong stacksize, CORBA::ULong static_threads, CORBA::ULong dynamic_threads, RTCORBA::Priority default_priority, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, ACE_Time_Value const &dynamic_thread_idle_timeout)
 Create a threadpool without lanes.

RTCORBA::ThreadpoolId create_threadpool_with_lanes (CORBA::ULong stacksize, const RTCORBA::ThreadpoolLanes &lanes, CORBA::Boolean allow_borrowing, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, ACE_Time_Value const &dynamic_thread_idle_timeout)
 Create a threadpool with lanes.

void destroy_threadpool (RTCORBA::ThreadpoolId threadpool)
 Destroy a threadpool.

TAO_Thread_Poolget_threadpool (RTCORBA::ThreadpoolId thread_pool_id)

Private Attributes

TAO_ORB_Coreorb_core_
THREAD_POOLS thread_pools_
RTCORBA::ThreadpoolId thread_pool_id_counter_
ACE_SYNCH_MUTEX lock_

Detailed Description

Class for managing thread pools.

Definition at line 352 of file Thread_Pool.h.


Member Typedef Documentation

typedef ACE_Hash_Map_Manager<RTCORBA::ThreadpoolId, TAO_Thread_Pool *, ACE_Null_Mutex> TAO_Thread_Pool_Manager::THREAD_POOLS
 

Collection of thread pools.

Definition at line 403 of file Thread_Pool.h.


Constructor & Destructor Documentation

TAO_Thread_Pool_Manager::TAO_Thread_Pool_Manager TAO_ORB_Core orb_core  ) 
 

Constructor.

Definition at line 640 of file Thread_Pool.cpp.

00641   : orb_core_ (orb_core),
00642     thread_pools_ (),
00643     thread_pool_id_counter_ (1),
00644     lock_ ()
00645 {
00646 }

TAO_Thread_Pool_Manager::~TAO_Thread_Pool_Manager void   ) 
 

Destructor.

Definition at line 648 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), and thread_pools_.

00649 {
00650   // Delete all the pools.
00651   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00652        iterator != this->thread_pools_.end ();
00653        ++iterator)
00654     delete (*iterator).int_id_;
00655 }


Member Function Documentation

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool CORBA::ULong  stacksize,
CORBA::ULong  static_threads,
CORBA::ULong  dynamic_threads,
RTCORBA::Priority  default_priority,
CORBA::Boolean  allow_request_buffering,
CORBA::ULong  max_buffered_requests,
CORBA::ULong  max_request_buffer_size,
ACE_Time_Value const &  dynamic_thread_idle_timeout
 

Create a threadpool without lanes.

Definition at line 706 of file Thread_Pool.cpp.

References create_threadpool_i(), RTCORBA::Priority, and TAO_THREAD_POOL_MANAGER_GUARD.

Referenced by TAO_RT_ORB::create_threadpool().

00715 {
00716   TAO_THREAD_POOL_MANAGER_GUARD;
00717 
00718   return this->create_threadpool_i (stacksize,
00719                                     static_threads,
00720                                     dynamic_threads,
00721                                     default_priority,
00722                                     allow_request_buffering,
00723                                     max_buffered_requests,
00724                                     max_request_buffer_size,
00725                                     dynamic_thread_idle_timeout
00726                                    );
00727 }

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool_helper TAO_Thread_Pool thread_pool  )  [private]
 

Definition at line 852 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::bind(), TAO_Thread_Pool::create_static_threads(), TAO_Thread_Pool::finalize(), TAO_Thread_Pool::open(), ACE_Auto_Basic_Ptr< X >::release(), TAO_RTCORBA_THREAD_CREATION_LOCATION_CODE, thread_pool_id_counter_, and thread_pools_.

Referenced by create_threadpool_i(), and create_threadpool_with_lanes_i().

00853 {
00854   // Make sure of safe deletion in case of errors.
00855   auto_ptr<TAO_Thread_Pool> safe_thread_pool (thread_pool);
00856 
00857   // Open the pool.
00858   thread_pool->open ();
00859 
00860   // Create the static threads.
00861   int result = thread_pool->create_static_threads ();
00862 
00863   // Throw exception in case of errors.
00864   if (result != 0)
00865     {
00866       // Finalize thread pool related resources.
00867       thread_pool->finalize ();
00868 
00869       throw ::CORBA::INTERNAL (
00870         CORBA::SystemException::_tao_minor_code (
00871           TAO_RTCORBA_THREAD_CREATION_LOCATION_CODE,
00872           errno),
00873         CORBA::COMPLETED_NO);
00874     }
00875 
00876   // Bind thread to internal table.
00877   result =
00878     this->thread_pools_.bind (this->thread_pool_id_counter_,
00879                               thread_pool);
00880 
00881   // Throw exceptin in case of errors.
00882   if (result != 0)
00883     throw ::CORBA::INTERNAL ();
00884 
00885   //
00886   // Success.
00887   //
00888 
00889   // No need to delete thread pool.
00890   safe_thread_pool.release ();
00891 
00892   // Return current counter and perform post-increment.
00893   return this->thread_pool_id_counter_++;
00894 }

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool_i CORBA::ULong  stacksize,
CORBA::ULong  static_threads,
CORBA::ULong  dynamic_threads,
RTCORBA::Priority  default_priority,
CORBA::Boolean  allow_request_buffering,
CORBA::ULong  max_buffered_requests,
CORBA::ULong  max_request_buffer_size,
ACE_Time_Value const &  dynamic_thread_idle_timeout
[private]
 

Definition at line 790 of file Thread_Pool.cpp.

References ACE_NEW_THROW_EX, create_threadpool_helper(), and RTCORBA::Priority.

Referenced by create_threadpool().

00799 {
00800   // Create the thread pool.
00801   TAO_Thread_Pool *thread_pool = 0;
00802 
00803   ACE_NEW_THROW_EX (thread_pool,
00804                     TAO_Thread_Pool (*this,
00805                                      this->thread_pool_id_counter_,
00806                                      stacksize,
00807                                      static_threads,
00808                                      dynamic_threads,
00809                                      default_priority,
00810                                      allow_request_buffering,
00811                                      max_buffered_requests,
00812                                      max_request_buffer_size,
00813                                      dynamic_thread_idle_timeout
00814                                     ),
00815                     CORBA::NO_MEMORY ());
00816 
00817   return this->create_threadpool_helper (thread_pool
00818                                         );
00819 }

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool_with_lanes CORBA::ULong  stacksize,
const RTCORBA::ThreadpoolLanes lanes,
CORBA::Boolean  allow_borrowing,
CORBA::Boolean  allow_request_buffering,
CORBA::ULong  max_buffered_requests,
CORBA::ULong  max_request_buffer_size,
ACE_Time_Value const &  dynamic_thread_idle_timeout
 

Create a threadpool with lanes.

Definition at line 730 of file Thread_Pool.cpp.

References create_threadpool_with_lanes_i(), TAO_THREAD_POOL_MANAGER_GUARD, and RTCORBA::ThreadpoolLanes.

Referenced by TAO_RT_ORB::create_threadpool_with_lanes().

00738 {
00739   TAO_THREAD_POOL_MANAGER_GUARD;
00740 
00741   return this->create_threadpool_with_lanes_i (stacksize,
00742                                                lanes,
00743                                                allow_borrowing,
00744                                                allow_request_buffering,
00745                                                max_buffered_requests,
00746                                                max_request_buffer_size,
00747                                                dynamic_thread_idle_timeout);
00748 }

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool_with_lanes_i CORBA::ULong  stacksize,
const RTCORBA::ThreadpoolLanes lanes,
CORBA::Boolean  allow_borrowing,
CORBA::Boolean  allow_request_buffering,
CORBA::ULong  max_buffered_requests,
CORBA::ULong  max_request_buffer_size,
ACE_Time_Value const &  dynamic_thread_idle_timeout
[private]
 

Definition at line 822 of file Thread_Pool.cpp.

References ACE_NEW_THROW_EX, create_threadpool_helper(), and RTCORBA::ThreadpoolLanes.

Referenced by create_threadpool_with_lanes().

00830 {
00831   // Create the thread pool.
00832   TAO_Thread_Pool *thread_pool = 0;
00833 
00834   ACE_NEW_THROW_EX (thread_pool,
00835                     TAO_Thread_Pool (*this,
00836                                      this->thread_pool_id_counter_,
00837                                      stacksize,
00838                                      lanes,
00839                                      allow_borrowing,
00840                                      allow_request_buffering,
00841                                      max_buffered_requests,
00842                                      max_request_buffer_size,
00843                                      dynamic_thread_idle_timeout
00844                                     ),
00845                     CORBA::NO_MEMORY ());
00846 
00847   return this->create_threadpool_helper (thread_pool
00848                                         );
00849 }

void TAO_Thread_Pool_Manager::destroy_threadpool RTCORBA::ThreadpoolId  threadpool  ) 
 

Destroy a threadpool.

Definition at line 751 of file Thread_Pool.cpp.

References TAO_Thread_Pool::finalize(), TAO_Thread_Pool::shutdown_reactor(), TAO_Thread_Pool::shutting_down(), TAO_THREAD_POOL_MANAGER_GUARD, thread_pools_, RTCORBA::ThreadpoolId, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::unbind(), and TAO_Thread_Pool::wait().

Referenced by TAO_RT_ORB::destroy_threadpool().

00752 {
00753   TAO_Thread_Pool *tao_thread_pool = 0;
00754 
00755   // The guard is just for the map, don't do a wait inside the guard, because
00756   // during the wait other threads can try to access the thread pool manager
00757   // also, this can be one of the threads we are waiting for, which then
00758   // results in a deadlock
00759   {
00760     TAO_THREAD_POOL_MANAGER_GUARD;
00761 
00762     // Unbind the thread pool from the map.
00763     int result =
00764       this->thread_pools_.unbind (threadpool,
00765                                   tao_thread_pool);
00766 
00767     // If the thread pool is not found in our map.
00768     if (result != 0)
00769       throw RTCORBA::RTORB::InvalidThreadpool ();
00770   }
00771 
00772   // Mark the thread pool that we are shutting down.
00773   tao_thread_pool->shutting_down ();
00774 
00775   // Shutdown reactor.
00776   tao_thread_pool->shutdown_reactor ();
00777 
00778   // Wait for the threads.
00779   tao_thread_pool->wait ();
00780 
00781   // Finalize resources.
00782   tao_thread_pool->finalize ();
00783 
00784   // Delete the thread pool.
00785   delete tao_thread_pool;
00786 
00787 }

void TAO_Thread_Pool_Manager::finalize void   ) 
 

Finalize the resources.

Definition at line 658 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), and thread_pools_.

Referenced by TAO_RT_Thread_Lane_Resources_Manager::finalize().

00659 {
00660   // Finalize all the pools.
00661   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00662        iterator != this->thread_pools_.end ();
00663        ++iterator)
00664     (*iterator).int_id_->finalize ();
00665 }

TAO_Thread_Pool * TAO_Thread_Pool_Manager::get_threadpool RTCORBA::ThreadpoolId  thread_pool_id  ) 
 

Definition at line 897 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::find(), TAO_THREAD_POOL_MANAGER_GUARD, thread_pools_, and RTCORBA::ThreadpoolId.

00898 {
00899   TAO_THREAD_POOL_MANAGER_GUARD;
00900 
00901   TAO_Thread_Pool *thread_pool = 0;
00902   int const result = thread_pools_.find (thread_pool_id, thread_pool);
00903 
00904   ACE_UNUSED_ARG (result);
00905 
00906   return thread_pool;
00907 }

int TAO_Thread_Pool_Manager::is_collocated const TAO_MProfile mprofile  ) 
 

Does mprofile belong to us?

Definition at line 688 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), and thread_pools_.

Referenced by TAO_RT_Thread_Lane_Resources_Manager::is_collocated().

00689 {
00690   // Finalize all the pools.
00691   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00692        iterator != this->thread_pools_.end ();
00693        ++iterator)
00694     {
00695       int result =
00696         (*iterator).int_id_->is_collocated (mprofile);
00697 
00698       if (result)
00699         return result;
00700     }
00701 
00702   return 0;
00703 }

TAO_ORB_Core & TAO_Thread_Pool_Manager::orb_core void   )  const
 

Definition at line 910 of file Thread_Pool.cpp.

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

00911 {
00912   return this->orb_core_;
00913 }

void TAO_Thread_Pool_Manager::shutdown_reactor void   ) 
 

Shutdown the reactor.

Definition at line 668 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), and thread_pools_.

Referenced by TAO_RT_Thread_Lane_Resources_Manager::shutdown_reactor().

00669 {
00670   // Finalize all the pools.
00671   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00672        iterator != this->thread_pools_.end ();
00673        ++iterator)
00674     (*iterator).int_id_->shutdown_reactor ();
00675 }

void TAO_Thread_Pool_Manager::wait void   ) 
 

Wait for threads to exit.

Definition at line 678 of file Thread_Pool.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), and thread_pools_.

00679 {
00680   // Finalize all the pools.
00681   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00682        iterator != this->thread_pools_.end ();
00683        ++iterator)
00684     (*iterator).int_id_->wait ();
00685 }


Member Data Documentation

ACE_SYNCH_MUTEX TAO_Thread_Pool_Manager::lock_ [private]
 

Definition at line 448 of file Thread_Pool.h.

TAO_ORB_Core& TAO_Thread_Pool_Manager::orb_core_ [private]
 

Definition at line 444 of file Thread_Pool.h.

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::thread_pool_id_counter_ [private]
 

Definition at line 447 of file Thread_Pool.h.

Referenced by create_threadpool_helper().

THREAD_POOLS TAO_Thread_Pool_Manager::thread_pools_ [private]
 

Definition at line 446 of file Thread_Pool.h.

Referenced by create_threadpool_helper(), destroy_threadpool(), finalize(), get_threadpool(), is_collocated(), shutdown_reactor(), wait(), and ~TAO_Thread_Pool_Manager().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 13:35:13 2008 for TAO_RTCORBA by doxygen 1.3.6