00001
00002
00003 #include "tao/RTCORBA/RT_ORB.h"
00004
00005 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00006
00007 #include "tao/RTCORBA/RT_Policy_i.h"
00008 #include "tao/RTCORBA/RT_Mutex.h"
00009 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
00010 #include "tao/ORB_Core.h"
00011 #include "tao/ORB.h"
00012 #include "tao/RTCORBA/Thread_Pool.h"
00013 #include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h"
00014 #include "ace/Sched_Params.h"
00015
00016 ACE_RCSID(RTCORBA,
00017 RT_ORB,
00018 "RT_ORB.cpp,v 1.20 2006/03/10 07:19:16 jtc Exp")
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 TAO_RT_ORB::TAO_RT_ORB (TAO_ORB_Core *orb_core,
00023 ACE_Time_Value const &dynamic_thread_idle_timeout)
00024 : orb_core_ (orb_core),
00025 mutex_mgr_ (),
00026 tp_manager_ (0),
00027 dynamic_thread_idle_timeout_ (dynamic_thread_idle_timeout)
00028 {
00029 TAO_Thread_Lane_Resources_Manager *thread_lane_resources_manager =
00030 &this->orb_core_->thread_lane_resources_manager ();
00031
00032 TAO_RT_Thread_Lane_Resources_Manager *rt_thread_lane_resources_manager =
00033 dynamic_cast <TAO_RT_Thread_Lane_Resources_Manager *> (thread_lane_resources_manager);
00034
00035 this->tp_manager_ =
00036 &rt_thread_lane_resources_manager->tp_manager ();
00037 }
00038
00039 TAO_RT_ORB::~TAO_RT_ORB (void)
00040 {
00041 }
00042
00043 RTCORBA::Mutex_ptr
00044 TAO_RT_ORB::create_mutex (ACE_ENV_SINGLE_ARG_DECL)
00045 ACE_THROW_SPEC ((CORBA::SystemException))
00046 {
00047 return this->mutex_mgr_.create_mutex (ACE_ENV_SINGLE_ARG_PARAMETER);
00048 }
00049
00050 void
00051 TAO_RT_ORB::destroy_mutex (RTCORBA::Mutex_ptr mutex
00052 ACE_ENV_ARG_DECL)
00053 ACE_THROW_SPEC ((CORBA::SystemException))
00054 {
00055 this->mutex_mgr_.destroy_mutex (mutex
00056 ACE_ENV_ARG_PARAMETER);
00057 }
00058
00059
00060 RTCORBA::Mutex_ptr
00061 TAO_RT_ORB::create_named_mutex (const char *name,
00062 CORBA::Boolean_out created_flag
00063 ACE_ENV_ARG_DECL)
00064 ACE_THROW_SPEC ((CORBA::SystemException))
00065 {
00066 return this->mutex_mgr_.create_named_mutex (name,
00067 created_flag
00068 ACE_ENV_ARG_PARAMETER);
00069 }
00070
00071 RTCORBA::Mutex_ptr
00072 TAO_RT_ORB::open_named_mutex (const char *name
00073 ACE_ENV_ARG_DECL)
00074 ACE_THROW_SPEC ((CORBA::SystemException,
00075 RTCORBA::RTORB::MutexNotFound))
00076 {
00077 return this->mutex_mgr_.open_named_mutex (name
00078 ACE_ENV_ARG_PARAMETER);
00079 }
00080
00081
00082
00083 TAO_Named_RT_Mutex_Manager::TAO_Named_RT_Mutex_Manager (void)
00084 {
00085 }
00086
00087 TAO_Named_RT_Mutex_Manager::~TAO_Named_RT_Mutex_Manager (void)
00088 {
00089 }
00090
00091 RTCORBA::Mutex_ptr
00092 TAO_Named_RT_Mutex_Manager::create_mutex (ACE_ENV_SINGLE_ARG_DECL)
00093 ACE_THROW_SPEC ((CORBA::SystemException))
00094 {
00095 TAO_RT_Mutex *mutex = 0;
00096 ACE_NEW_THROW_EX (mutex,
00097 TAO_RT_Mutex (),
00098 CORBA::NO_MEMORY (
00099 CORBA::SystemException::_tao_minor_code (
00100 TAO::VMCID,
00101 ENOMEM),
00102 CORBA::COMPLETED_NO));
00103 ACE_CHECK_RETURN (RTCORBA::Mutex::_nil ());
00104
00105 return mutex;
00106 }
00107
00108
00109
00110 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00111 void
00112 TAO_Named_RT_Mutex_Manager::destroy_mutex (RTCORBA::Mutex_ptr mutex
00113 ACE_ENV_ARG_DECL)
00114 ACE_THROW_SPEC ((CORBA::SystemException))
00115 {
00116 TAO_RT_Mutex *tao_mutex =
00117 dynamic_cast<TAO_RT_Mutex *> (mutex);
00118
00119
00120
00121 const char *name = tao_mutex->name ();
00122 if (name != 0)
00123 {
00124
00125 ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
00126 monitor,
00127 this->lock_,
00128 CORBA::INTERNAL ());
00129 ACE_CHECK;
00130
00131 int result =
00132 this->map_.unbind (name);
00133
00134 if (result != 0)
00135 ACE_THROW (CORBA::INTERNAL ());
00136 }
00137 }
00138 #else
00139 void
00140 TAO_Named_RT_Mutex_Manager::destroy_mutex (RTCORBA::Mutex_ptr
00141 ACE_ENV_ARG_DECL_NOT_USED)
00142 ACE_THROW_SPEC ((CORBA::SystemException))
00143 {
00144 }
00145 #endif
00146
00147 RTCORBA::Mutex_ptr
00148 TAO_Named_RT_Mutex_Manager::create_named_mutex (const char *name,
00149 CORBA::Boolean_out created_flag
00150 ACE_ENV_ARG_DECL)
00151 ACE_THROW_SPEC ((CORBA::SystemException))
00152 {
00153 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00154
00155 ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
00156 monitor,
00157 this->lock_,
00158 CORBA::INTERNAL ());
00159 ACE_CHECK_RETURN (RTCORBA::Mutex::_nil ());
00160
00161
00162 created_flag = 0;
00163
00164
00165 RTCORBA::Mutex_var mutex;
00166 if (this->map_.find (name,
00167 mutex) != 0)
00168 {
00169
00170 created_flag = 1;
00171
00172 RTCORBA::Mutex_ptr tmp_mutex;
00173
00174
00175 ACE_NEW_THROW_EX (tmp_mutex,
00176 TAO_Named_RT_Mutex (name),
00177 CORBA::NO_MEMORY (
00178 CORBA::SystemException::_tao_minor_code (
00179 TAO::VMCID,
00180 ENOMEM),
00181 CORBA::COMPLETED_NO));
00182 ACE_CHECK_RETURN (RTCORBA::Mutex::_nil ());
00183
00184 mutex = tmp_mutex;
00185
00186
00187 int result =
00188 this->map_.bind (name,
00189 mutex);
00190
00191 if (result != 0)
00192 ACE_THROW_RETURN (CORBA::INTERNAL (),
00193 RTCORBA::Mutex::_nil ());
00194 }
00195
00196
00197 return mutex._retn ();
00198 #else
00199 ACE_UNUSED_ARG (name);
00200 ACE_UNUSED_ARG (created_flag);
00201 ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (),
00202 RTCORBA::Mutex::_nil ());
00203 #endif
00204 }
00205
00206 RTCORBA::Mutex_ptr
00207 TAO_Named_RT_Mutex_Manager::open_named_mutex (const char *name
00208 ACE_ENV_ARG_DECL)
00209 ACE_THROW_SPEC ((CORBA::SystemException,
00210 RTCORBA::RTORB::MutexNotFound))
00211 {
00212 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00213
00214 ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
00215 monitor,
00216 this->lock_,
00217 CORBA::INTERNAL ());
00218 ACE_CHECK_RETURN (RTCORBA::Mutex::_nil ());
00219
00220
00221 RTCORBA::Mutex_var mutex;
00222 if (this->map_.find (name,
00223 mutex) != 0)
00224 ACE_THROW_RETURN (RTCORBA::RTORB::MutexNotFound (),
00225 RTCORBA::Mutex::_nil ());
00226
00227
00228 return mutex._retn ();
00229 #else
00230 ACE_UNUSED_ARG (name);
00231 ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (),
00232 RTCORBA::Mutex::_nil ());
00233 #endif
00234 }
00235
00236
00237
00238 RTCORBA::TCPProtocolProperties_ptr
00239 TAO_RT_ORB::create_tcp_protocol_properties (CORBA::Long send_buffer_size,
00240 CORBA::Long recv_buffer_size,
00241 CORBA::Boolean keep_alive,
00242 CORBA::Boolean dont_route,
00243 CORBA::Boolean no_delay,
00244 CORBA::Boolean enable_network_priority
00245 ACE_ENV_ARG_DECL)
00246 ACE_THROW_SPEC ((CORBA::SystemException ))
00247 {
00248 TAO_TCP_Protocol_Properties *tmp = 0;
00249 ACE_NEW_THROW_EX (tmp,
00250 TAO_TCP_Protocol_Properties (send_buffer_size,
00251 recv_buffer_size,
00252 keep_alive,
00253 dont_route,
00254 no_delay,
00255 enable_network_priority),
00256 CORBA::NO_MEMORY (TAO::VMCID,
00257 CORBA::COMPLETED_NO));
00258 ACE_CHECK_RETURN (RTCORBA::TCPProtocolProperties::_nil ());
00259
00260 return tmp;
00261 }
00262
00263 RTCORBA::UnixDomainProtocolProperties_ptr
00264 TAO_RT_ORB::create_unix_domain_protocol_properties (
00265 CORBA::Long send_buffer_size,
00266 CORBA::Long recv_buffer_size
00267 ACE_ENV_ARG_DECL)
00268 ACE_THROW_SPEC ((CORBA::SystemException))
00269 {
00270 TAO_UnixDomain_Protocol_Properties *tmp = 0;
00271 ACE_NEW_THROW_EX (tmp,
00272 TAO_UnixDomain_Protocol_Properties (
00273 send_buffer_size,
00274 recv_buffer_size),
00275 CORBA::NO_MEMORY (TAO::VMCID,
00276 CORBA::COMPLETED_NO));
00277 ACE_CHECK_RETURN (RTCORBA::UnixDomainProtocolProperties::_nil ());
00278
00279 return tmp;
00280 }
00281
00282 RTCORBA::SharedMemoryProtocolProperties_ptr
00283 TAO_RT_ORB::create_shared_memory_protocol_properties (
00284 CORBA::Long send_buffer_size,
00285 CORBA::Long recv_buffer_size,
00286 CORBA::Boolean keep_alive,
00287 CORBA::Boolean dont_route,
00288 CORBA::Boolean no_delay,
00289 CORBA::Long preallocate_buffer_size,
00290 const char *mmap_filename,
00291 const char *mmap_lockname
00292 ACE_ENV_ARG_DECL)
00293 ACE_THROW_SPEC ((CORBA::SystemException))
00294 {
00295 TAO_SharedMemory_Protocol_Properties *tmp = 0;
00296 ACE_NEW_THROW_EX (tmp,
00297 TAO_SharedMemory_Protocol_Properties (send_buffer_size,
00298 recv_buffer_size,
00299 keep_alive,
00300 dont_route,
00301 no_delay,
00302 preallocate_buffer_size,
00303 mmap_filename,
00304 mmap_lockname),
00305 CORBA::NO_MEMORY (TAO::VMCID,
00306 CORBA::COMPLETED_NO));
00307 ACE_CHECK_RETURN (RTCORBA::SharedMemoryProtocolProperties::_nil ());
00308
00309 return tmp;
00310 }
00311
00312 RTCORBA::UserDatagramProtocolProperties_ptr
00313 TAO_RT_ORB::create_user_datagram_protocol_properties (
00314 CORBA::Boolean enable_network_priority
00315 ACE_ENV_ARG_DECL)
00316 ACE_THROW_SPEC ((CORBA::SystemException))
00317 {
00318 TAO_UserDatagram_Protocol_Properties *tmp = 0;
00319 ACE_NEW_THROW_EX (tmp,
00320 TAO_UserDatagram_Protocol_Properties (
00321 enable_network_priority),
00322 CORBA::NO_MEMORY (TAO::VMCID,
00323 CORBA::COMPLETED_NO));
00324 ACE_CHECK_RETURN (RTCORBA::UserDatagramProtocolProperties::_nil ());
00325
00326 return tmp;
00327 }
00328
00329 RTCORBA::StreamControlProtocolProperties_ptr
00330 TAO_RT_ORB::create_stream_control_protocol_properties (
00331 CORBA::Long send_buffer_size,
00332 CORBA::Long recv_buffer_size,
00333 CORBA::Boolean keep_alive,
00334 CORBA::Boolean dont_route,
00335 CORBA::Boolean no_delay,
00336 CORBA::Boolean enable_network_priority
00337 ACE_ENV_ARG_DECL)
00338 ACE_THROW_SPEC ((CORBA::SystemException))
00339 {
00340 TAO_StreamControl_Protocol_Properties *tmp = 0;
00341 ACE_NEW_THROW_EX (tmp,
00342 TAO_StreamControl_Protocol_Properties (
00343 send_buffer_size,
00344 recv_buffer_size,
00345 keep_alive,
00346 dont_route,
00347 no_delay,
00348 enable_network_priority),
00349 CORBA::NO_MEMORY (TAO::VMCID,
00350 CORBA::COMPLETED_NO));
00351 ACE_CHECK_RETURN (RTCORBA::StreamControlProtocolProperties::_nil ());
00352
00353 return tmp;
00354 }
00355
00356 RTCORBA::ThreadpoolId
00357 TAO_RT_ORB::create_threadpool (CORBA::ULong stacksize,
00358 CORBA::ULong static_threads,
00359 CORBA::ULong dynamic_threads,
00360 RTCORBA::Priority default_priority,
00361 CORBA::Boolean allow_request_buffering,
00362 CORBA::ULong max_buffered_requests,
00363 CORBA::ULong max_request_buffer_size
00364 ACE_ENV_ARG_DECL)
00365 ACE_THROW_SPEC ((CORBA::SystemException))
00366 {
00367 return this->tp_manager_->create_threadpool (stacksize,
00368 static_threads,
00369 dynamic_threads,
00370 default_priority,
00371 allow_request_buffering,
00372 max_buffered_requests,
00373 max_request_buffer_size,
00374 this->dynamic_thread_idle_timeout_
00375 ACE_ENV_ARG_PARAMETER);
00376 }
00377
00378 RTCORBA::ThreadpoolId
00379 TAO_RT_ORB::create_threadpool_with_lanes (CORBA::ULong stacksize,
00380 const RTCORBA::ThreadpoolLanes &lanes,
00381 CORBA::Boolean allow_borrowing,
00382 CORBA::Boolean allow_request_buffering,
00383 CORBA::ULong max_buffered_requests,
00384 CORBA::ULong max_request_buffer_size
00385 ACE_ENV_ARG_DECL)
00386 ACE_THROW_SPEC ((CORBA::SystemException))
00387 {
00388 return this->tp_manager_->create_threadpool_with_lanes (stacksize,
00389 lanes,
00390 allow_borrowing,
00391 allow_request_buffering,
00392 max_buffered_requests,
00393 max_request_buffer_size,
00394 this->dynamic_thread_idle_timeout_
00395 ACE_ENV_ARG_PARAMETER);
00396 }
00397
00398 void
00399 TAO_RT_ORB::destroy_threadpool (RTCORBA::ThreadpoolId threadpool
00400 ACE_ENV_ARG_DECL)
00401 ACE_THROW_SPEC ((CORBA::SystemException,
00402 RTCORBA::RTORB::InvalidThreadpool))
00403 {
00404 this->tp_manager_->destroy_threadpool (threadpool
00405 ACE_ENV_ARG_PARAMETER);
00406 }
00407
00408 RTCORBA::PriorityModelPolicy_ptr
00409 TAO_RT_ORB::create_priority_model_policy (RTCORBA::PriorityModel priority_model,
00410 RTCORBA::Priority server_priority
00411 ACE_ENV_ARG_DECL)
00412 ACE_THROW_SPEC ((CORBA::SystemException))
00413 {
00414 TAO_PriorityModelPolicy *tmp = 0;
00415 ACE_NEW_THROW_EX (tmp,
00416 TAO_PriorityModelPolicy (priority_model, server_priority),
00417 CORBA::NO_MEMORY (TAO::VMCID,
00418 CORBA::COMPLETED_NO));
00419 ACE_CHECK_RETURN (RTCORBA::PriorityModelPolicy::_nil ());
00420
00421 return tmp;
00422 }
00423
00424 RTCORBA::ThreadpoolPolicy_ptr
00425 TAO_RT_ORB::create_threadpool_policy (RTCORBA::ThreadpoolId threadpool
00426 ACE_ENV_ARG_DECL)
00427 ACE_THROW_SPEC ((CORBA::SystemException))
00428 {
00429 TAO_ThreadpoolPolicy *tmp = 0;
00430 ACE_NEW_THROW_EX (tmp,
00431 TAO_ThreadpoolPolicy (threadpool),
00432 CORBA::NO_MEMORY (TAO::VMCID,
00433 CORBA::COMPLETED_NO));
00434 ACE_CHECK_RETURN (RTCORBA::ThreadpoolPolicy::_nil ());
00435
00436 return tmp;
00437 }
00438
00439 RTCORBA::PriorityBandedConnectionPolicy_ptr
00440 TAO_RT_ORB::create_priority_banded_connection_policy (const
00441 RTCORBA::PriorityBands & priority_bands
00442 ACE_ENV_ARG_DECL)
00443 ACE_THROW_SPEC ((CORBA::SystemException))
00444 {
00445 TAO_PriorityBandedConnectionPolicy *tmp = 0;
00446 ACE_NEW_THROW_EX (tmp,
00447 TAO_PriorityBandedConnectionPolicy (priority_bands),
00448 CORBA::NO_MEMORY (TAO::VMCID,
00449 CORBA::COMPLETED_NO));
00450 ACE_CHECK_RETURN (RTCORBA::PriorityBandedConnectionPolicy::_nil ());
00451
00452 return tmp;
00453 }
00454
00455 RTCORBA::PrivateConnectionPolicy_ptr
00456 TAO_RT_ORB::create_private_connection_policy (ACE_ENV_SINGLE_ARG_DECL)
00457 ACE_THROW_SPEC ((CORBA::SystemException))
00458 {
00459 TAO_PrivateConnectionPolicy *tmp = 0;
00460 ACE_NEW_THROW_EX (tmp,
00461 TAO_PrivateConnectionPolicy (),
00462 CORBA::NO_MEMORY (TAO::VMCID,
00463 CORBA::COMPLETED_NO));
00464 ACE_CHECK_RETURN (RTCORBA::PrivateConnectionPolicy::_nil ());
00465
00466 return tmp;
00467 }
00468
00469 RTCORBA::ServerProtocolPolicy_ptr
00470 TAO_RT_ORB::create_server_protocol_policy (const RTCORBA::ProtocolList & protocols
00471 ACE_ENV_ARG_DECL)
00472 ACE_THROW_SPEC ((CORBA::SystemException))
00473 {
00474 TAO_ServerProtocolPolicy *tmp = 0;
00475 ACE_NEW_THROW_EX (tmp,
00476 TAO_ServerProtocolPolicy (protocols),
00477 CORBA::NO_MEMORY (TAO::VMCID,
00478 CORBA::COMPLETED_NO));
00479 ACE_CHECK_RETURN (RTCORBA::ServerProtocolPolicy::_nil ());
00480
00481 return tmp;
00482 }
00483
00484 RTCORBA::ClientProtocolPolicy_ptr
00485 TAO_RT_ORB::create_client_protocol_policy (const RTCORBA::ProtocolList & protocols
00486 ACE_ENV_ARG_DECL)
00487 ACE_THROW_SPEC ((CORBA::SystemException))
00488 {
00489 TAO_ClientProtocolPolicy *tmp = 0;
00490 ACE_NEW_THROW_EX (tmp,
00491 TAO_ClientProtocolPolicy (protocols),
00492 CORBA::NO_MEMORY (TAO::VMCID,
00493 CORBA::COMPLETED_NO));
00494 ACE_CHECK_RETURN (RTCORBA::ClientProtocolPolicy::_nil ());
00495
00496 return tmp;
00497 }
00498
00499 TAO_Thread_Pool_Manager &
00500 TAO_RT_ORB::tp_manager (void) const
00501 {
00502 return *this->tp_manager_;
00503 }
00504
00505 TAO_ORB_Core *
00506 TAO_RT_ORB::orb_core (void) const
00507 {
00508 return this->orb_core_;
00509 }
00510
00511
00512 int
00513 TAO_RT_ORB::modify_thread_scheduling_policy (CORBA::ORB_ptr orb)
00514 {
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 #if defined (linux)
00532
00533 int sched_policy =
00534 orb->orb_core ()->orb_params ()->ace_sched_policy ();
00535
00536 int minimum_priority =
00537 ACE_Sched_Params::priority_min (sched_policy);
00538
00539 ACE_hthread_t thread_id;
00540 ACE_Thread::self (thread_id);
00541
00542 return ACE_Thread::setprio (thread_id,
00543 minimum_priority,
00544 sched_policy);
00545
00546 #else
00547
00548 ACE_UNUSED_ARG (orb);
00549 ACE_NOTSUP_RETURN (-1);
00550
00551 #endif
00552
00553 }
00554
00555 TAO_END_VERSIONED_NAMESPACE_DECL
00556
00557
00558
00559 #endif