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) throw (CORBA::SystemException)
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) throw (CORBA::SystemException)
RTCORBA::ThreadpoolId create_threadpool_helper (TAO_Thread_Pool *thread_pool) throw (CORBA::SystemException)

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) throw (CORBA::SystemException)
 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) throw (CORBA::SystemException)
 Create a threadpool with lanes.

void destroy_threadpool (RTCORBA::ThreadpoolId threadpool) throw (CORBA::SystemException, RTCORBA::RTORB::InvalidThreadpool)
 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 358 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 414 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 655 of file Thread_Pool.cpp.

00656   : orb_core_ (orb_core),
00657     thread_pools_ (),
00658     thread_pool_id_counter_ (1),
00659     lock_ ()
00660 {
00661 }

TAO_Thread_Pool_Manager::~TAO_Thread_Pool_Manager void   ) 
 

Destructor.

Definition at line 663 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_.

00664 {
00665   // Delete all the pools.
00666   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00667        iterator != this->thread_pools_.end ();
00668        ++iterator)
00669     delete (*iterator).int_id_;
00670 }


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
throw (CORBA::SystemException)
 

Create a threadpool without lanes.

Definition at line 721 of file Thread_Pool.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, RTCORBA::Priority, and TAO_THREAD_POOL_MANAGER_GUARD.

00731 {
00732   TAO_THREAD_POOL_MANAGER_GUARD;
00733   ACE_CHECK_RETURN (0);
00734 
00735   return this->create_threadpool_i (stacksize,
00736                                     static_threads,
00737                                     dynamic_threads,
00738                                     default_priority,
00739                                     allow_request_buffering,
00740                                     max_buffered_requests,
00741                                     max_request_buffer_size,
00742                                     dynamic_thread_idle_timeout
00743                                     ACE_ENV_ARG_PARAMETER);
00744 }

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool_helper TAO_Thread_Pool thread_pool  )  throw (CORBA::SystemException) [private]
 

Definition at line 880 of file Thread_Pool.cpp.

References ACE_CHECK_RETURN, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_THROW_RETURN, ACE_Auto_Basic_Ptr< X >::release(), and TAO_RTCORBA_THREAD_CREATION_LOCATION_CODE.

00883 {
00884   // Make sure of safe deletion in case of errors.
00885   auto_ptr<TAO_Thread_Pool> safe_thread_pool (thread_pool);
00886 
00887   // Open the pool.
00888   thread_pool->open (ACE_ENV_SINGLE_ARG_PARAMETER);
00889   ACE_CHECK_RETURN (0);
00890 
00891   // Create the static threads.
00892   int result =
00893     thread_pool->create_static_threads ();
00894 
00895   // Throw exception in case of errors.
00896   if (result != 0)
00897     {
00898       // Finalize thread pool related resources.
00899       thread_pool->finalize ();
00900 
00901       ACE_THROW_RETURN (
00902         CORBA::INTERNAL (
00903           CORBA::SystemException::_tao_minor_code (
00904             TAO_RTCORBA_THREAD_CREATION_LOCATION_CODE,
00905             errno),
00906           CORBA::COMPLETED_NO),
00907         result);
00908     }
00909 
00910   // Bind thread to internal table.
00911   result =
00912     this->thread_pools_.bind (this->thread_pool_id_counter_,
00913                               thread_pool);
00914 
00915   // Throw exceptin in case of errors.
00916   if (result != 0)
00917     ACE_THROW_RETURN (CORBA::INTERNAL (),
00918                       result);
00919 
00920   //
00921   // Success.
00922   //
00923 
00924   // No need to delete thread pool.
00925   safe_thread_pool.release ();
00926 
00927   // Return current counter and perform post-increment.
00928   return this->thread_pool_id_counter_++;
00929 }

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
throw (CORBA::SystemException) [private]
 

Definition at line 814 of file Thread_Pool.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_NEW_THROW_EX, and RTCORBA::Priority.

00824 {
00825   // Create the thread pool.
00826   TAO_Thread_Pool *thread_pool = 0;
00827 
00828   ACE_NEW_THROW_EX (thread_pool,
00829                     TAO_Thread_Pool (*this,
00830                                      this->thread_pool_id_counter_,
00831                                      stacksize,
00832                                      static_threads,
00833                                      dynamic_threads,
00834                                      default_priority,
00835                                      allow_request_buffering,
00836                                      max_buffered_requests,
00837                                      max_request_buffer_size,
00838                                      dynamic_thread_idle_timeout
00839                                      ACE_ENV_ARG_PARAMETER),
00840                     CORBA::NO_MEMORY ());
00841   ACE_CHECK_RETURN (0);
00842 
00843   return this->create_threadpool_helper (thread_pool
00844                                          ACE_ENV_ARG_PARAMETER);
00845 }

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
throw (CORBA::SystemException)
 

Create a threadpool with lanes.

Definition at line 747 of file Thread_Pool.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, and TAO_THREAD_POOL_MANAGER_GUARD.

00756 {
00757   TAO_THREAD_POOL_MANAGER_GUARD;
00758   ACE_CHECK_RETURN (0);
00759 
00760   return this->create_threadpool_with_lanes_i (stacksize,
00761                                                lanes,
00762                                                allow_borrowing,
00763                                                allow_request_buffering,
00764                                                max_buffered_requests,
00765                                                max_request_buffer_size,
00766                                                dynamic_thread_idle_timeout
00767                                                ACE_ENV_ARG_PARAMETER);
00768 }

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
throw (CORBA::SystemException) [private]
 

Definition at line 848 of file Thread_Pool.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, and ACE_NEW_THROW_EX.

00857 {
00858   // Create the thread pool.
00859   TAO_Thread_Pool *thread_pool = 0;
00860 
00861   ACE_NEW_THROW_EX (thread_pool,
00862                     TAO_Thread_Pool (*this,
00863                                      this->thread_pool_id_counter_,
00864                                      stacksize,
00865                                      lanes,
00866                                      allow_borrowing,
00867                                      allow_request_buffering,
00868                                      max_buffered_requests,
00869                                      max_request_buffer_size,
00870                                      dynamic_thread_idle_timeout
00871                                      ACE_ENV_ARG_PARAMETER),
00872                     CORBA::NO_MEMORY ());
00873   ACE_CHECK_RETURN (0);
00874 
00875   return this->create_threadpool_helper (thread_pool
00876                                          ACE_ENV_ARG_PARAMETER);
00877 }

void TAO_Thread_Pool_Manager::destroy_threadpool RTCORBA::ThreadpoolId  threadpool  )  throw (CORBA::SystemException, RTCORBA::RTORB::InvalidThreadpool)
 

Destroy a threadpool.

Definition at line 771 of file Thread_Pool.cpp.

References ACE_CHECK, ACE_THROW, TAO_Thread_Pool::finalize(), TAO_Thread_Pool::shutdown_reactor(), TAO_Thread_Pool::shutting_down(), TAO_THREAD_POOL_MANAGER_GUARD, RTCORBA::ThreadpoolId, and TAO_Thread_Pool::wait().

00775 {
00776   TAO_Thread_Pool *tao_thread_pool = 0;
00777 
00778   // The guard is just for the map, don't do a wait inside the guard, because
00779   // during the wait other threads can try to access the thread pool manager
00780   // also, this can be one of the threads we are waiting for, which then
00781   // results in a deadlock
00782   {
00783     TAO_THREAD_POOL_MANAGER_GUARD;
00784     ACE_CHECK;
00785 
00786     // Unbind the thread pool from the map.
00787     int result =
00788       this->thread_pools_.unbind (threadpool,
00789                                   tao_thread_pool);
00790 
00791     // If the thread pool is not found in our map.
00792     if (result != 0)
00793       ACE_THROW (RTCORBA::RTORB::InvalidThreadpool ());
00794   }
00795 
00796   // Mark the thread pool that we are shutting down.
00797   tao_thread_pool->shutting_down ();
00798 
00799   // Shutdown reactor.
00800   tao_thread_pool->shutdown_reactor ();
00801 
00802   // Wait for the threads.
00803   tao_thread_pool->wait ();
00804 
00805   // Finalize resources.
00806   tao_thread_pool->finalize ();
00807 
00808   // Delete the thread pool.
00809   delete tao_thread_pool;
00810 
00811 }

void TAO_Thread_Pool_Manager::finalize void   ) 
 

Finalize the resources.

Definition at line 673 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().

00674 {
00675   // Finalize all the pools.
00676   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00677        iterator != this->thread_pools_.end ();
00678        ++iterator)
00679     (*iterator).int_id_->finalize ();
00680 }

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

Definition at line 932 of file Thread_Pool.cpp.

References ACE_CHECK_RETURN, 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.

00933 {
00934   TAO_THREAD_POOL_MANAGER_GUARD;
00935   ACE_CHECK_RETURN (0);
00936 
00937   TAO_Thread_Pool *thread_pool = 0;
00938   int result =
00939     thread_pools_.find (thread_pool_id,
00940                         thread_pool);
00941 
00942   ACE_UNUSED_ARG (result);
00943 
00944   return thread_pool;
00945 }

int TAO_Thread_Pool_Manager::is_collocated const TAO_MProfile mprofile  ) 
 

Does mprofile belong to us?

Definition at line 703 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().

00704 {
00705   // Finalize all the pools.
00706   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00707        iterator != this->thread_pools_.end ();
00708        ++iterator)
00709     {
00710       int result =
00711         (*iterator).int_id_->is_collocated (mprofile);
00712 
00713       if (result)
00714         return result;
00715     }
00716 
00717   return 0;
00718 }

TAO_ORB_Core & TAO_Thread_Pool_Manager::orb_core void   )  const
 

Definition at line 948 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().

00949 {
00950   return this->orb_core_;
00951 }

void TAO_Thread_Pool_Manager::shutdown_reactor void   ) 
 

Shutdown the reactor.

Definition at line 683 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().

00684 {
00685   // Finalize all the pools.
00686   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00687        iterator != this->thread_pools_.end ();
00688        ++iterator)
00689     (*iterator).int_id_->shutdown_reactor ();
00690 }

void TAO_Thread_Pool_Manager::wait void   ) 
 

Wait for threads to exit.

Definition at line 693 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_.

00694 {
00695   // Finalize all the pools.
00696   for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00697        iterator != this->thread_pools_.end ();
00698        ++iterator)
00699     (*iterator).int_id_->wait ();
00700 }


Member Data Documentation

ACE_SYNCH_MUTEX TAO_Thread_Pool_Manager::lock_ [private]
 

Definition at line 464 of file Thread_Pool.h.

TAO_ORB_Core& TAO_Thread_Pool_Manager::orb_core_ [private]
 

Definition at line 460 of file Thread_Pool.h.

RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::thread_pool_id_counter_ [private]
 

Definition at line 463 of file Thread_Pool.h.

THREAD_POOLS TAO_Thread_Pool_Manager::thread_pools_ [private]
 

Definition at line 462 of file Thread_Pool.h.

Referenced by 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 Thu Nov 9 13:00:10 2006 for TAO_RTCORBA by doxygen 1.3.6