00001 #include "tao/RTCORBA/Thread_Pool.h"
00002
00003 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00004
00005 ACE_RCSID (RTCORBA,
00006 Thread_Pool,
00007 "$Id: Thread_Pool.cpp 84272 2009-01-30 11:58:40Z johnnyw $")
00008
00009 #if ! defined (__ACE_INLINE__)
00010 #include "tao/RTCORBA/Thread_Pool.inl"
00011 #endif
00012
00013 #include "tao/Exception.h"
00014 #include "tao/ORB_Core.h"
00015 #include "tao/ORB_Core_TSS_Resources.h"
00016 #include "tao/TSS_Resources.h"
00017 #include "tao/ORB.h"
00018 #include "tao/Acceptor_Registry.h"
00019 #include "tao/debug.h"
00020 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
00021 #include "tao/LF_Follower.h"
00022 #include "tao/Leader_Follower.h"
00023 #include "ace/Auto_Ptr.h"
00024
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 TAO_RT_New_Leader_Generator::TAO_RT_New_Leader_Generator (
00028 TAO_Thread_Lane &lane)
00029 : lane_ (lane)
00030 {
00031 }
00032
00033 void
00034 TAO_RT_New_Leader_Generator::no_leaders_available (void)
00035 {
00036
00037 this->lane_.new_dynamic_thread ();
00038 }
00039
00040 TAO_Thread_Pool_Threads::TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane)
00041 : ACE_Task_Base (lane.pool ().manager ().orb_core ().thr_mgr ()),
00042 lane_ (lane)
00043 {
00044 }
00045
00046 int
00047 TAO_Thread_Pool_Threads::svc (void)
00048 {
00049 TAO_ORB_Core &orb_core =
00050 this->lane ().pool ().manager ().orb_core ();
00051
00052 if (orb_core.has_shutdown ())
00053 return 0;
00054
00055
00056 TAO_Thread_Pool_Threads::set_tss_resources (orb_core, this->lane_);
00057
00058 try
00059 {
00060
00061 this->run (orb_core);
00062 }
00063 catch (const ::CORBA::Exception& ex)
00064 {
00065
00066 ACE_ERROR ((LM_ERROR,
00067 "orb->run() raised exception for thread %t\n"));
00068
00069 ex._tao_print_exception ("");
00070 }
00071
00072 return 0;
00073 }
00074
00075 int
00076 TAO_Thread_Pool_Threads::run (TAO_ORB_Core &orb_core)
00077 {
00078 CORBA::ORB_ptr orb = orb_core.orb ();
00079
00080
00081 orb->run ();
00082
00083 return 0;
00084 }
00085
00086 void
00087 TAO_Thread_Pool_Threads::set_tss_resources (TAO_ORB_Core &orb_core,
00088 TAO_Thread_Lane &thread_lane)
00089 {
00090
00091 TAO_ORB_Core_TSS_Resources &tss =
00092 *orb_core.get_tss_resources ();
00093
00094
00095 tss.lane_ = &thread_lane;
00096
00097 TAO_TSS_Resources::instance ()->rtcorba_current_priority_
00098 = thread_lane.lane_priority ();
00099 }
00100
00101 TAO_Dynamic_Thread_Pool_Threads::TAO_Dynamic_Thread_Pool_Threads (TAO_Thread_Lane &lane)
00102 : TAO_Thread_Pool_Threads (lane)
00103 {
00104 }
00105
00106 int
00107 TAO_Dynamic_Thread_Pool_Threads::run (TAO_ORB_Core &orb_core)
00108 {
00109 CORBA::ORB_ptr orb = orb_core.orb ();
00110
00111 switch (this->lane_.lifespan ())
00112 {
00113 case TAO_RT_ORBInitializer::TAO_RTCORBA_DT_FIXED :
00114 {
00115 ACE_Time_Value tv_run (this->lane_.dynamic_thread_time ());
00116 orb->run (tv_run);
00117 }
00118 break;
00119 case TAO_RT_ORBInitializer::TAO_RTCORBA_DT_IDLE :
00120 {
00121
00122
00123
00124 ACE_Time_Value tv (this->lane_.dynamic_thread_time ());
00125 while (!orb_core.has_shutdown () && orb->work_pending (tv))
00126 {
00127
00128
00129 tv = this->lane_.dynamic_thread_time ();
00130 orb->run (tv);
00131
00132 tv = this->lane_.dynamic_thread_time ();
00133 }
00134 }
00135 break;
00136 case TAO_RT_ORBInitializer::TAO_RTCORBA_DT_INFINITIVE :
00137 {
00138
00139 orb->run ();
00140 }
00141 break;
00142 }
00143
00144 if (TAO_debug_level > 7)
00145 {
00146 ACE_DEBUG ((LM_DEBUG,
00147 ACE_TEXT ("TAO Process %P Pool %d Lane %d Thread %t\n")
00148 ACE_TEXT ("Current number of dynamic threads left = %d; ")
00149 ACE_TEXT ("RTCorba worker thread is ending!\n"),
00150 this->lane_.pool ().id (),
00151 this->lane_.id (),
00152 this->thr_count () - 1));
00153 }
00154
00155 return 0;
00156 }
00157
00158 TAO_Thread_Lane::TAO_Thread_Lane (TAO_Thread_Pool &pool,
00159 CORBA::ULong id,
00160 CORBA::Short lane_priority,
00161 CORBA::ULong static_threads,
00162 CORBA::ULong dynamic_threads,
00163 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00164 ACE_Time_Value const &dynamic_thread_time)
00165 : pool_ (pool),
00166 id_ (id),
00167 lane_priority_ (lane_priority),
00168 shutdown_ (false),
00169 static_threads_number_ (static_threads),
00170 dynamic_threads_number_ (dynamic_threads),
00171 static_threads_ (*this),
00172 dynamic_threads_ (*this),
00173 new_thread_generator_ (*this),
00174 resources_ (pool.manager ().orb_core (),
00175 &new_thread_generator_),
00176 native_priority_ (TAO_INVALID_PRIORITY),
00177 lifespan_ (lifespan),
00178 dynamic_thread_time_ (dynamic_thread_time)
00179 {
00180 }
00181
00182 bool
00183 TAO_Thread_Lane::new_dynamic_thread (void)
00184 {
00185
00186
00187 if (this->dynamic_threads_.thr_count () >= this->dynamic_threads_number_)
00188 return false;
00189
00190 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00191 mon,
00192 this->lock_,
00193 false);
00194
00195 TAO_Thread_Pool_Manager &manager = this->pool_.manager ();
00196
00197 if (!manager.orb_core ().has_shutdown () && !this->shutdown_&&
00198 this->dynamic_threads_.thr_count () < this->dynamic_threads_number_)
00199 {
00200 if (TAO_debug_level > 0)
00201 ACE_DEBUG ((LM_DEBUG,
00202 ACE_TEXT ("TAO Process %P Pool %d Lane %d Thread %t\n")
00203 ACE_TEXT ("Current number of dynamic threads = %d; ")
00204 ACE_TEXT ("static threads = %d; max dynamic threads = %d\n")
00205 ACE_TEXT ("No leaders available; creating new leader!\n"),
00206 this->pool_.id (),
00207 this->id_,
00208 this->dynamic_threads_.thr_count (),
00209 this->static_threads_number_,
00210 this->dynamic_threads_number_));
00211
00212 int result =
00213 this->create_threads_i (this->dynamic_threads_,
00214 1,
00215 THR_BOUND | THR_DETACHED);
00216
00217 if (result != 0)
00218 ACE_ERROR_RETURN ((LM_ERROR,
00219 ACE_TEXT ("Pool %d Lane %d Thread %t: ")
00220 ACE_TEXT ("cannot create dynamic thread\n"),
00221 this->pool_.id (),
00222 this->id_),
00223 false);
00224 }
00225
00226 return true;
00227 }
00228
00229 void
00230 TAO_Thread_Lane::shutting_down (void)
00231 {
00232 ACE_GUARD (TAO_SYNCH_MUTEX,
00233 mon,
00234 this->lock_);
00235
00236
00237
00238 this->shutdown_ = true;
00239 }
00240
00241 void
00242 TAO_Thread_Lane::validate_and_map_priority (void)
00243 {
00244
00245 if (this->static_threads_number_ == 0)
00246 throw ::CORBA::BAD_PARAM ();
00247
00248
00249 if (this->lane_priority_ < RTCORBA::minPriority
00250
00251
00252
00253
00254 )
00255 {
00256 throw ::CORBA::BAD_PARAM ();
00257 }
00258
00259 CORBA::ORB_ptr orb = this->pool_.manager ().orb_core ().orb ();
00260
00261
00262 CORBA::Object_var obj =
00263 orb->resolve_initial_references (TAO_OBJID_PRIORITYMAPPINGMANAGER);
00264
00265 TAO_Priority_Mapping_Manager_var mapping_manager =
00266 TAO_Priority_Mapping_Manager::_narrow (obj.in ());
00267
00268 RTCORBA::PriorityMapping *pm = mapping_manager.in ()->mapping ();
00269
00270
00271 CORBA::Boolean const result =
00272 pm->to_native (this->lane_priority_, this->native_priority_);
00273
00274 if (!result)
00275 throw ::CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
00276
00277 if (TAO_debug_level > 3)
00278 {
00279 ACE_DEBUG ((LM_DEBUG,
00280 ACE_TEXT ("TAO (%P|%t) - creating thread at ")
00281 ACE_TEXT ("(corba:native) priority %d:%d\n"),
00282 this->lane_priority_,
00283 this->native_priority_));
00284 }
00285 }
00286
00287 void
00288 TAO_Thread_Lane::open (void)
00289 {
00290
00291 this->validate_and_map_priority ();
00292
00293 char pool_lane_id[10];
00294 TAO_ORB_Parameters *params =
00295 this->pool ().manager ().orb_core ().orb_params ();
00296 TAO_EndpointSet endpoint_set;
00297
00298
00299 ACE_OS::sprintf (pool_lane_id,
00300 "*:*");
00301
00302
00303 params->get_endpoint_set (pool_lane_id, endpoint_set);
00304
00305
00306 ACE_OS::sprintf (pool_lane_id,
00307 "%d:*",
00308 this->pool ().id ());
00309
00310
00311 params->get_endpoint_set (pool_lane_id, endpoint_set);
00312
00313
00314 ACE_OS::sprintf (pool_lane_id,
00315 "*:%d",
00316 this->id ());
00317
00318
00319 params->get_endpoint_set (pool_lane_id, endpoint_set);
00320
00321
00322 ACE_OS::sprintf (pool_lane_id,
00323 "%d:%d",
00324 this->pool ().id (),
00325 this->id ());
00326
00327
00328 params->get_endpoint_set (pool_lane_id, endpoint_set);
00329
00330 bool ignore_address = false;
00331
00332 if (endpoint_set.is_empty ())
00333 {
00334
00335
00336
00337 params->get_endpoint_set (TAO_DEFAULT_LANE, endpoint_set);
00338
00339 ignore_address = true;
00340 }
00341 else
00342 {
00343
00344
00345 ignore_address = false;
00346 }
00347
00348
00349 int const result =
00350 this->resources_.open_acceptor_registry (endpoint_set, ignore_address);
00351
00352 if (result == -1)
00353 throw ::CORBA::INTERNAL (
00354 CORBA::SystemException::_tao_minor_code (
00355 TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00356 0),
00357 CORBA::COMPLETED_NO);
00358 }
00359
00360 TAO_Thread_Lane::~TAO_Thread_Lane (void)
00361 {
00362 }
00363
00364 void
00365 TAO_Thread_Lane::finalize (void)
00366 {
00367
00368 this->resources_.finalize ();
00369 }
00370
00371 void
00372 TAO_Thread_Lane::shutdown_reactor (void)
00373 {
00374 this->resources_.shutdown_reactor ();
00375 }
00376
00377 void
00378 TAO_Thread_Lane::wait (void)
00379 {
00380 this->static_threads_.wait ();
00381 this->dynamic_threads_.wait ();
00382 }
00383
00384 int
00385 TAO_Thread_Lane::is_collocated (const TAO_MProfile &mprofile)
00386 {
00387 return this->resources_.is_collocated (mprofile);
00388 }
00389
00390 CORBA::ULong
00391 TAO_Thread_Lane::current_threads (void) const
00392 {
00393 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00394 mon,
00395 this->lock_,
00396 0);
00397
00398 return (this->static_threads_.thr_count () +
00399 this->dynamic_threads_.thr_count ());
00400 }
00401
00402
00403 int
00404 TAO_Thread_Lane::create_static_threads (void)
00405 {
00406 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00407 mon,
00408 this->lock_,
00409 0);
00410
00411
00412 return this->create_threads_i (this->static_threads_,
00413 this->static_threads_number_,
00414 THR_NEW_LWP | THR_JOINABLE);
00415 }
00416
00417 int
00418 TAO_Thread_Lane::create_dynamic_threads (CORBA::ULong number_of_threads)
00419 {
00420 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00421 mon,
00422 this->lock_,
00423 0);
00424
00425 return this->create_threads_i (this->dynamic_threads_,
00426 number_of_threads,
00427 THR_BOUND | THR_DETACHED);
00428 }
00429
00430 int
00431 TAO_Thread_Lane::create_threads_i (TAO_Thread_Pool_Threads &thread_pool,
00432 CORBA::ULong number_of_threads,
00433 long thread_flags)
00434 {
00435
00436 int force_active = 1;
00437
00438
00439 int default_grp_id = -1;
00440 ACE_Task_Base *default_task = 0;
00441 ACE_hthread_t *default_thread_handles = 0;
00442 void **default_stack = 0;
00443
00444
00445 size_t *stack_size_array = 0;
00446 ACE_NEW_RETURN (stack_size_array,
00447 size_t[number_of_threads],
00448 -1);
00449 size_t index;
00450 for (index = 0;
00451 index != number_of_threads;
00452 ++index)
00453 stack_size_array[index] =
00454 this->pool ().stack_size ();
00455
00456
00457
00458 ACE_Auto_Basic_Array_Ptr<size_t> auto_stack_size_array (stack_size_array);
00459
00460 TAO_ORB_Core &orb_core =
00461 this->pool ().manager ().orb_core ();
00462
00463 long flags =
00464 thread_flags |
00465 orb_core.orb_params ()->thread_creation_flags ();
00466
00467
00468 int result =
00469 thread_pool.activate (flags,
00470 number_of_threads,
00471 force_active,
00472 this->native_priority_,
00473 default_grp_id,
00474 default_task,
00475 default_thread_handles,
00476 default_stack,
00477 stack_size_array);
00478
00479 if (result != 0)
00480 return result;
00481
00482 return result;
00483 }
00484
00485 TAO_Thread_Pool::TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager,
00486 CORBA::ULong id,
00487 CORBA::ULong stack_size,
00488 CORBA::ULong static_threads,
00489 CORBA::ULong dynamic_threads,
00490 CORBA::Short default_priority,
00491 CORBA::Boolean allow_request_buffering,
00492 CORBA::ULong max_buffered_requests,
00493 CORBA::ULong max_request_buffer_size,
00494 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00495 ACE_Time_Value const &dynamic_thread_time)
00496 : manager_ (manager),
00497 id_ (id),
00498 stack_size_ (stack_size),
00499 allow_borrowing_ (0),
00500 allow_request_buffering_ (allow_request_buffering),
00501 max_buffered_requests_ (max_buffered_requests),
00502 max_request_buffer_size_ (max_request_buffer_size),
00503 lifespan_ (lifespan),
00504 dynamic_thread_time_ (dynamic_thread_time),
00505 lanes_ (0),
00506 number_of_lanes_ (1),
00507 with_lanes_ (false)
00508 {
00509
00510 if (allow_request_buffering)
00511 throw ::CORBA::NO_IMPLEMENT ();
00512
00513
00514 ACE_NEW (this->lanes_,
00515 TAO_Thread_Lane *[this->number_of_lanes_]);
00516 ACE_NEW (this->lanes_[0],
00517 TAO_Thread_Lane (*this,
00518 0,
00519 default_priority,
00520 static_threads,
00521 dynamic_threads,
00522 lifespan,
00523 dynamic_thread_time
00524 ));
00525 }
00526
00527 TAO_Thread_Pool::TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager,
00528 CORBA::ULong id,
00529 CORBA::ULong stack_size,
00530 const RTCORBA::ThreadpoolLanes &lanes,
00531 CORBA::Boolean allow_borrowing,
00532 CORBA::Boolean allow_request_buffering,
00533 CORBA::ULong max_buffered_requests,
00534 CORBA::ULong max_request_buffer_size,
00535 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00536 ACE_Time_Value const &dynamic_thread_time)
00537 : manager_ (manager),
00538 id_ (id),
00539 stack_size_ (stack_size),
00540 allow_borrowing_ (allow_borrowing),
00541 allow_request_buffering_ (allow_request_buffering),
00542 max_buffered_requests_ (max_buffered_requests),
00543 max_request_buffer_size_ (max_request_buffer_size),
00544 lifespan_ (lifespan),
00545 dynamic_thread_time_ (dynamic_thread_time),
00546 lanes_ (0),
00547 number_of_lanes_ (lanes.length ()),
00548 with_lanes_ (true)
00549 {
00550
00551 if (allow_borrowing ||
00552 allow_request_buffering)
00553 throw ::CORBA::NO_IMPLEMENT ();
00554
00555
00556 ACE_NEW (this->lanes_,
00557 TAO_Thread_Lane *[this->number_of_lanes_]);
00558 for (CORBA::ULong i = 0;
00559 i != this->number_of_lanes_;
00560 ++i)
00561 ACE_NEW (this->lanes_[i],
00562 TAO_Thread_Lane (*this,
00563 i,
00564 lanes[i].lane_priority,
00565 lanes[i].static_threads,
00566 lanes[i].dynamic_threads,
00567 lifespan,
00568 dynamic_thread_time
00569 ));
00570 }
00571
00572 void
00573 TAO_Thread_Pool::open (void)
00574 {
00575
00576 for (CORBA::ULong i = 0;
00577 i != this->number_of_lanes_;
00578 ++i)
00579 {
00580 this->lanes_[i]->open ();
00581 }
00582 }
00583
00584 TAO_Thread_Pool::~TAO_Thread_Pool (void)
00585 {
00586
00587 for (CORBA::ULong i = 0;
00588 i != this->number_of_lanes_;
00589 ++i)
00590 delete this->lanes_[i];
00591
00592 delete[] this->lanes_;
00593 }
00594
00595 void
00596 TAO_Thread_Pool::finalize (void)
00597 {
00598
00599 for (CORBA::ULong i = 0;
00600 i != this->number_of_lanes_;
00601 ++i)
00602 this->lanes_[i]->finalize ();
00603 }
00604
00605 void
00606 TAO_Thread_Pool::shutdown_reactor (void)
00607 {
00608
00609 for (CORBA::ULong i = 0;
00610 i != this->number_of_lanes_;
00611 ++i)
00612 this->lanes_[i]->shutdown_reactor ();
00613 }
00614
00615 void
00616 TAO_Thread_Pool::shutting_down (void)
00617 {
00618
00619 for (CORBA::ULong i = 0;
00620 i != this->number_of_lanes_;
00621 ++i)
00622 this->lanes_[i]->shutting_down ();
00623 }
00624
00625
00626 void
00627 TAO_Thread_Pool::wait (void)
00628 {
00629
00630 for (CORBA::ULong i = 0;
00631 i != this->number_of_lanes_;
00632 ++i)
00633 this->lanes_[i]->wait ();
00634 }
00635
00636 int
00637 TAO_Thread_Pool::is_collocated (const TAO_MProfile &mprofile)
00638 {
00639
00640 for (CORBA::ULong i = 0;
00641 i != this->number_of_lanes_;
00642 ++i)
00643 {
00644 int result =
00645 this->lanes_[i]->is_collocated (mprofile);
00646
00647 if (result)
00648 return result;
00649 }
00650
00651 return 0;
00652 }
00653
00654 int
00655 TAO_Thread_Pool::create_static_threads (void)
00656 {
00657 for (CORBA::ULong i = 0;
00658 i != this->number_of_lanes_;
00659 ++i)
00660 {
00661
00662 int const result = this->lanes_[i]->create_static_threads ();
00663
00664
00665 if (result != 0)
00666 return result;
00667 }
00668
00669
00670 return 0;
00671 }
00672
00673 #define TAO_THREAD_POOL_MANAGER_GUARD \
00674 ACE_GUARD_THROW_EX ( \
00675 TAO_SYNCH_MUTEX, \
00676 mon, \
00677 this->lock_, \
00678 CORBA::INTERNAL ( \
00679 CORBA::SystemException::_tao_minor_code ( \
00680 TAO_GUARD_FAILURE, \
00681 0), \
00682 CORBA::COMPLETED_NO));
00683
00684 TAO_Thread_Pool_Manager::TAO_Thread_Pool_Manager (TAO_ORB_Core &orb_core)
00685 : orb_core_ (orb_core),
00686 thread_pools_ (),
00687 thread_pool_id_counter_ (1),
00688 lock_ ()
00689 {
00690 }
00691
00692 TAO_Thread_Pool_Manager::~TAO_Thread_Pool_Manager (void)
00693 {
00694
00695 for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00696 iterator != this->thread_pools_.end ();
00697 ++iterator)
00698 delete (*iterator).int_id_;
00699 }
00700
00701 void
00702 TAO_Thread_Pool_Manager::finalize (void)
00703 {
00704
00705 for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00706 iterator != this->thread_pools_.end ();
00707 ++iterator)
00708 (*iterator).int_id_->finalize ();
00709 }
00710
00711 void
00712 TAO_Thread_Pool_Manager::shutdown_reactor (void)
00713 {
00714
00715 for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00716 iterator != this->thread_pools_.end ();
00717 ++iterator)
00718 (*iterator).int_id_->shutdown_reactor ();
00719 }
00720
00721 void
00722 TAO_Thread_Pool_Manager::wait (void)
00723 {
00724
00725 for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00726 iterator != this->thread_pools_.end ();
00727 ++iterator)
00728 (*iterator).int_id_->wait ();
00729 }
00730
00731 int
00732 TAO_Thread_Pool_Manager::is_collocated (const TAO_MProfile &mprofile)
00733 {
00734
00735 for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin ();
00736 iterator != this->thread_pools_.end ();
00737 ++iterator)
00738 {
00739 int const result = (*iterator).int_id_->is_collocated (mprofile);
00740
00741 if (result)
00742 return result;
00743 }
00744
00745 return 0;
00746 }
00747
00748 RTCORBA::ThreadpoolId
00749 TAO_Thread_Pool_Manager::create_threadpool (CORBA::ULong stacksize,
00750 CORBA::ULong static_threads,
00751 CORBA::ULong dynamic_threads,
00752 RTCORBA::Priority default_priority,
00753 CORBA::Boolean allow_request_buffering,
00754 CORBA::ULong max_buffered_requests,
00755 CORBA::ULong max_request_buffer_size,
00756 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00757 ACE_Time_Value const &dynamic_thread_time)
00758 {
00759 TAO_THREAD_POOL_MANAGER_GUARD;
00760
00761 return this->create_threadpool_i (stacksize,
00762 static_threads,
00763 dynamic_threads,
00764 default_priority,
00765 allow_request_buffering,
00766 max_buffered_requests,
00767 max_request_buffer_size,
00768 lifespan,
00769 dynamic_thread_time);
00770 }
00771
00772 RTCORBA::ThreadpoolId
00773 TAO_Thread_Pool_Manager::create_threadpool_with_lanes (CORBA::ULong stacksize,
00774 const RTCORBA::ThreadpoolLanes & lanes,
00775 CORBA::Boolean allow_borrowing,
00776 CORBA::Boolean allow_request_buffering,
00777 CORBA::ULong max_buffered_requests,
00778 CORBA::ULong max_request_buffer_size,
00779 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00780 ACE_Time_Value const &dynamic_thread_time)
00781 {
00782 TAO_THREAD_POOL_MANAGER_GUARD;
00783
00784 return this->create_threadpool_with_lanes_i (stacksize,
00785 lanes,
00786 allow_borrowing,
00787 allow_request_buffering,
00788 max_buffered_requests,
00789 max_request_buffer_size,
00790 lifespan,
00791 dynamic_thread_time);
00792 }
00793
00794 void
00795 TAO_Thread_Pool_Manager::destroy_threadpool (RTCORBA::ThreadpoolId threadpool)
00796 {
00797 TAO_Thread_Pool *tao_thread_pool = 0;
00798
00799
00800
00801
00802
00803 {
00804 TAO_THREAD_POOL_MANAGER_GUARD;
00805
00806
00807 int const result = this->thread_pools_.unbind (threadpool, tao_thread_pool);
00808
00809
00810 if (result != 0)
00811 throw RTCORBA::RTORB::InvalidThreadpool ();
00812 }
00813
00814
00815 tao_thread_pool->shutting_down ();
00816
00817
00818 tao_thread_pool->shutdown_reactor ();
00819
00820
00821 tao_thread_pool->wait ();
00822
00823
00824 tao_thread_pool->finalize ();
00825
00826
00827 delete tao_thread_pool;
00828
00829 }
00830
00831 RTCORBA::ThreadpoolId
00832 TAO_Thread_Pool_Manager::create_threadpool_i (CORBA::ULong stacksize,
00833 CORBA::ULong static_threads,
00834 CORBA::ULong dynamic_threads,
00835 RTCORBA::Priority default_priority,
00836 CORBA::Boolean allow_request_buffering,
00837 CORBA::ULong max_buffered_requests,
00838 CORBA::ULong max_request_buffer_size,
00839 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00840 ACE_Time_Value const &dynamic_thread_time)
00841 {
00842
00843 TAO_Thread_Pool *thread_pool = 0;
00844
00845 ACE_NEW_THROW_EX (thread_pool,
00846 TAO_Thread_Pool (*this,
00847 this->thread_pool_id_counter_,
00848 stacksize,
00849 static_threads,
00850 dynamic_threads,
00851 default_priority,
00852 allow_request_buffering,
00853 max_buffered_requests,
00854 max_request_buffer_size,
00855 lifespan,
00856 dynamic_thread_time
00857 ),
00858 CORBA::NO_MEMORY ());
00859
00860 return this->create_threadpool_helper (thread_pool);
00861 }
00862
00863 RTCORBA::ThreadpoolId
00864 TAO_Thread_Pool_Manager::create_threadpool_with_lanes_i (CORBA::ULong stacksize,
00865 const RTCORBA::ThreadpoolLanes &lanes,
00866 CORBA::Boolean allow_borrowing,
00867 CORBA::Boolean allow_request_buffering,
00868 CORBA::ULong max_buffered_requests,
00869 CORBA::ULong max_request_buffer_size,
00870 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00871 ACE_Time_Value const &dynamic_thread_time)
00872 {
00873
00874 TAO_Thread_Pool *thread_pool = 0;
00875
00876 ACE_NEW_THROW_EX (thread_pool,
00877 TAO_Thread_Pool (*this,
00878 this->thread_pool_id_counter_,
00879 stacksize,
00880 lanes,
00881 allow_borrowing,
00882 allow_request_buffering,
00883 max_buffered_requests,
00884 max_request_buffer_size,
00885 lifespan,
00886 dynamic_thread_time
00887 ),
00888 CORBA::NO_MEMORY ());
00889
00890 return this->create_threadpool_helper (thread_pool);
00891 }
00892
00893 RTCORBA::ThreadpoolId
00894 TAO_Thread_Pool_Manager::create_threadpool_helper (TAO_Thread_Pool *thread_pool)
00895 {
00896
00897 auto_ptr<TAO_Thread_Pool> safe_thread_pool (thread_pool);
00898
00899
00900 thread_pool->open ();
00901
00902
00903 int result = thread_pool->create_static_threads ();
00904
00905
00906 if (result != 0)
00907 {
00908
00909 thread_pool->finalize ();
00910
00911 throw ::CORBA::INTERNAL (
00912 CORBA::SystemException::_tao_minor_code (
00913 TAO_RTCORBA_THREAD_CREATION_LOCATION_CODE,
00914 errno),
00915 CORBA::COMPLETED_NO);
00916 }
00917
00918
00919 result =
00920 this->thread_pools_.bind (this->thread_pool_id_counter_,
00921 thread_pool);
00922
00923
00924 if (result != 0)
00925 throw ::CORBA::INTERNAL ();
00926
00927
00928
00929
00930
00931
00932 safe_thread_pool.release ();
00933
00934
00935 return this->thread_pool_id_counter_++;
00936 }
00937
00938 TAO_Thread_Pool *
00939 TAO_Thread_Pool_Manager::get_threadpool (RTCORBA::ThreadpoolId thread_pool_id )
00940 {
00941 TAO_THREAD_POOL_MANAGER_GUARD;
00942
00943 TAO_Thread_Pool *thread_pool = 0;
00944 int const result = thread_pools_.find (thread_pool_id, thread_pool);
00945
00946 ACE_UNUSED_ARG (result);
00947
00948 return thread_pool;
00949 }
00950
00951 TAO_ORB_Core &
00952 TAO_Thread_Pool_Manager::orb_core (void) const
00953 {
00954 return this->orb_core_;
00955 }
00956
00957 TAO_END_VERSIONED_NAMESPACE_DECL
00958
00959 #endif