RT_ORB.cpp

Go to the documentation of this file.
00001 // $Id: RT_ORB.cpp 80216 2007-12-10 08:15:33Z johnnyw $
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/SystemException.h"
00013 #include "tao/RTCORBA/Thread_Pool.h"
00014 #include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h"
00015 #include "ace/Sched_Params.h"
00016 
00017 ACE_RCSID(RTCORBA,
00018           RT_ORB,
00019           "$Id: RT_ORB.cpp 80216 2007-12-10 08:15:33Z johnnyw $")
00020 
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022 
00023 TAO_RT_ORB::TAO_RT_ORB (TAO_ORB_Core *orb_core,
00024                         TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00025                         ACE_Time_Value const &dynamic_thread_time)
00026   : orb_core_ (orb_core),
00027     mutex_mgr_ (),
00028     tp_manager_ (0),
00029     lifespan_ (lifespan),
00030     dynamic_thread_time_ (dynamic_thread_time)
00031 {
00032   TAO_Thread_Lane_Resources_Manager *thread_lane_resources_manager =
00033     &this->orb_core_->thread_lane_resources_manager ();
00034 
00035   TAO_RT_Thread_Lane_Resources_Manager *rt_thread_lane_resources_manager =
00036     dynamic_cast <TAO_RT_Thread_Lane_Resources_Manager *> (thread_lane_resources_manager);
00037 
00038   if (!rt_thread_lane_resources_manager)
00039     throw CORBA::INTERNAL ();
00040 
00041   this->tp_manager_ =
00042     &rt_thread_lane_resources_manager->tp_manager ();
00043 }
00044 
00045 TAO_RT_ORB::~TAO_RT_ORB (void)
00046 {
00047 }
00048 
00049 RTCORBA::Mutex_ptr
00050 TAO_RT_ORB::create_mutex (void)
00051 {
00052   return this->mutex_mgr_.create_mutex ();
00053 }
00054 
00055 void
00056 TAO_RT_ORB::destroy_mutex (RTCORBA::Mutex_ptr mutex)
00057 {
00058   this->mutex_mgr_.destroy_mutex (mutex);
00059 }
00060 
00061 
00062 RTCORBA::Mutex_ptr
00063 TAO_RT_ORB::create_named_mutex (const char *name,
00064                                 CORBA::Boolean_out created_flag)
00065 {
00066   return this->mutex_mgr_.create_named_mutex (name, created_flag);
00067 }
00068 
00069 RTCORBA::Mutex_ptr
00070 TAO_RT_ORB::open_named_mutex (const char *name)
00071 {
00072   return this->mutex_mgr_.open_named_mutex (name);
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////////////////
00076 
00077 TAO_Named_RT_Mutex_Manager::TAO_Named_RT_Mutex_Manager (void)
00078 {
00079 }
00080 
00081 TAO_Named_RT_Mutex_Manager::~TAO_Named_RT_Mutex_Manager (void)
00082 {
00083 }
00084 
00085 RTCORBA::Mutex_ptr
00086 TAO_Named_RT_Mutex_Manager::create_mutex (void)
00087 {
00088   TAO_RT_Mutex *mutex = 0;
00089   ACE_NEW_THROW_EX (mutex,
00090                     TAO_RT_Mutex (),
00091                     CORBA::NO_MEMORY (
00092                       CORBA::SystemException::_tao_minor_code (
00093                         TAO::VMCID,
00094                         ENOMEM),
00095                       CORBA::COMPLETED_NO));
00096 
00097   return mutex;
00098 }
00099 
00100 // If Named RT_Mutexes aren't enabled, this function is a nop
00101 // as also indicated by the comment below.
00102 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00103 void
00104 TAO_Named_RT_Mutex_Manager::destroy_mutex (RTCORBA::Mutex_ptr mutex)
00105 {
00106   TAO_RT_Mutex *tao_mutex =
00107     dynamic_cast<TAO_RT_Mutex *> (mutex);
00108 
00109   // If this mutex is named, then we need to remove it from our table.
00110   // Otherwise, we don't have to do anything.
00111   const char *name = tao_mutex->name ();
00112   if (name != 0)
00113     {
00114       // The following should be atomic.
00115       ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
00116                           monitor,
00117                           this->lock_,
00118                           CORBA::INTERNAL ());
00119 
00120       int result =
00121         this->map_.unbind (name);
00122 
00123       if (result != 0)
00124         throw ::CORBA::INTERNAL ();
00125     }
00126 }
00127 #else /* TAO_HAS_NAMED_RT_MUTEXES == 1 */
00128 void
00129 TAO_Named_RT_Mutex_Manager::destroy_mutex (RTCORBA::Mutex_ptr)
00130 {
00131 }
00132 #endif /* TAO_HAS_NAMED_RT_MUTEXES == 1 */
00133 
00134 RTCORBA::Mutex_ptr
00135 TAO_Named_RT_Mutex_Manager::create_named_mutex (const char *name,
00136                                                 CORBA::Boolean_out created_flag)
00137 {
00138 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00139   // The following should be atomic.
00140   ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
00141                       monitor,
00142                       this->lock_,
00143                       CORBA::INTERNAL ());
00144 
00145   // Optimistic that we'll find it.
00146   created_flag = false;
00147 
00148   // If we find the mutex, simply return it.
00149   RTCORBA::Mutex_var mutex;
00150   if (this->map_.find (name, mutex) != 0)
00151     {
00152       // Oops, we didn't find it.
00153       created_flag = true;
00154 
00155       RTCORBA::Mutex_ptr tmp_mutex;
00156 
00157       // Create a new one.
00158       ACE_NEW_THROW_EX (tmp_mutex,
00159                         TAO_Named_RT_Mutex (name),
00160                         CORBA::NO_MEMORY (
00161                           CORBA::SystemException::_tao_minor_code (
00162                             TAO::VMCID,
00163                             ENOMEM),
00164                           CORBA::COMPLETED_NO));
00165 
00166       mutex = tmp_mutex;
00167 
00168       // Add it to the map.
00169       int const result = this->map_.bind (name, mutex);
00170 
00171       if (result != 0)
00172         throw ::CORBA::INTERNAL ();
00173     }
00174 
00175   // Return the one we found or created.
00176   return mutex._retn ();
00177 #else /* TAO_HAS_NAMED_RT_MUTEXES */
00178   ACE_UNUSED_ARG (name);
00179   ACE_UNUSED_ARG (created_flag);
00180   throw ::CORBA::NO_IMPLEMENT ();
00181 #endif /* TAO_HAS_NAMED_RT_MUTEXES */
00182 }
00183 
00184 RTCORBA::Mutex_ptr
00185 TAO_Named_RT_Mutex_Manager::open_named_mutex (const char *name)
00186 {
00187 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00188   // The following should be atomic.
00189   ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
00190                       monitor,
00191                       this->lock_,
00192                       CORBA::INTERNAL ());
00193 
00194   // If we find the mutex, simply return it.
00195   RTCORBA::Mutex_var mutex;
00196   if (this->map_.find (name, mutex) != 0)
00197     throw RTCORBA::RTORB::MutexNotFound ();
00198 
00199   // Return the one we found.
00200   return mutex._retn ();
00201 #else /* TAO_HAS_NAMED_RT_MUTEXES */
00202   ACE_UNUSED_ARG (name);
00203   throw ::CORBA::NO_IMPLEMENT ();
00204 #endif /* TAO_HAS_NAMED_RT_MUTEXES */
00205 }
00206 
00207 ///////////////////////////////////////////////////////////////////////////////
00208 
00209 RTCORBA::TCPProtocolProperties_ptr
00210 TAO_RT_ORB::create_tcp_protocol_properties (CORBA::Long send_buffer_size,
00211                                             CORBA::Long recv_buffer_size,
00212                                             CORBA::Boolean keep_alive,
00213                                             CORBA::Boolean dont_route,
00214                                             CORBA::Boolean no_delay,
00215                                             CORBA::Boolean enable_network_priority
00216                                             )
00217 {
00218   TAO_TCP_Protocol_Properties *tmp = 0;
00219   ACE_NEW_THROW_EX (tmp,
00220                     TAO_TCP_Protocol_Properties (send_buffer_size,
00221                                         recv_buffer_size,
00222                                         keep_alive,
00223                                         dont_route,
00224                                         no_delay,
00225                                         enable_network_priority),
00226                     CORBA::NO_MEMORY (TAO::VMCID,
00227                                       CORBA::COMPLETED_NO));
00228 
00229   return tmp;
00230 }
00231 
00232 RTCORBA::UnixDomainProtocolProperties_ptr
00233 TAO_RT_ORB::create_unix_domain_protocol_properties (
00234                                                     CORBA::Long send_buffer_size,
00235                                                     CORBA::Long recv_buffer_size)
00236 {
00237   TAO_UnixDomain_Protocol_Properties *tmp = 0;
00238   ACE_NEW_THROW_EX (tmp,
00239                     TAO_UnixDomain_Protocol_Properties (
00240                                                send_buffer_size,
00241                                                recv_buffer_size),
00242                     CORBA::NO_MEMORY (TAO::VMCID,
00243                                       CORBA::COMPLETED_NO));
00244 
00245   return tmp;
00246 }
00247 
00248 RTCORBA::SharedMemoryProtocolProperties_ptr
00249 TAO_RT_ORB::create_shared_memory_protocol_properties (
00250                                                       CORBA::Long send_buffer_size,
00251                                                       CORBA::Long recv_buffer_size,
00252                                                       CORBA::Boolean keep_alive,
00253                                                       CORBA::Boolean dont_route,
00254                                                       CORBA::Boolean no_delay,
00255                                                       CORBA::Long preallocate_buffer_size,
00256                                                       const char *mmap_filename,
00257                                                       const char *mmap_lockname)
00258 {
00259   TAO_SharedMemory_Protocol_Properties *tmp = 0;
00260   ACE_NEW_THROW_EX (tmp,
00261                     TAO_SharedMemory_Protocol_Properties (send_buffer_size,
00262                                                           recv_buffer_size,
00263                                                           keep_alive,
00264                                                           dont_route,
00265                                                           no_delay,
00266                                                           preallocate_buffer_size,
00267                                                           mmap_filename,
00268                                                           mmap_lockname),
00269                     CORBA::NO_MEMORY (TAO::VMCID,
00270                                       CORBA::COMPLETED_NO));
00271 
00272   return tmp;
00273 }
00274 
00275 RTCORBA::UserDatagramProtocolProperties_ptr
00276 TAO_RT_ORB::create_user_datagram_protocol_properties (
00277                                                       CORBA::Long send_buffer_size,
00278                                                       CORBA::Long recv_buffer_size,
00279                                                       CORBA::Boolean enable_network_priority)
00280 {
00281   TAO_UserDatagram_Protocol_Properties *tmp = 0;
00282   ACE_NEW_THROW_EX (tmp,
00283                     TAO_UserDatagram_Protocol_Properties (
00284                                                  send_buffer_size,
00285                                                  recv_buffer_size,
00286                                                  enable_network_priority),
00287                     CORBA::NO_MEMORY (TAO::VMCID,
00288                                       CORBA::COMPLETED_NO));
00289 
00290   return tmp;
00291 }
00292 
00293 RTCORBA::StreamControlProtocolProperties_ptr
00294 TAO_RT_ORB::create_stream_control_protocol_properties (
00295                                                        CORBA::Long send_buffer_size,
00296                                                        CORBA::Long recv_buffer_size,
00297                                                        CORBA::Boolean keep_alive,
00298                                                        CORBA::Boolean dont_route,
00299                                                        CORBA::Boolean no_delay,
00300                                                        CORBA::Boolean enable_network_priority
00301                                                        )
00302 {
00303   TAO_StreamControl_Protocol_Properties *tmp = 0;
00304   ACE_NEW_THROW_EX (tmp,
00305                     TAO_StreamControl_Protocol_Properties (
00306                                                   send_buffer_size,
00307                                                   recv_buffer_size,
00308                                                   keep_alive,
00309                                                   dont_route,
00310                                                   no_delay,
00311                                                   enable_network_priority),
00312                     CORBA::NO_MEMORY (TAO::VMCID,
00313                                       CORBA::COMPLETED_NO));
00314 
00315   return tmp;
00316 }
00317 
00318 RTCORBA::ThreadpoolId
00319 TAO_RT_ORB::create_threadpool (CORBA::ULong stacksize,
00320                                CORBA::ULong static_threads,
00321                                CORBA::ULong dynamic_threads,
00322                                RTCORBA::Priority default_priority,
00323                                CORBA::Boolean allow_request_buffering,
00324                                CORBA::ULong max_buffered_requests,
00325                                CORBA::ULong max_request_buffer_size
00326                                )
00327 {
00328   return this->tp_manager_->create_threadpool (stacksize,
00329                                                static_threads,
00330                                                dynamic_threads,
00331                                                default_priority,
00332                                                allow_request_buffering,
00333                                                max_buffered_requests,
00334                                                max_request_buffer_size,
00335                                                this->lifespan_,
00336                                                this->dynamic_thread_time_);
00337 }
00338 
00339 RTCORBA::ThreadpoolId
00340 TAO_RT_ORB::create_threadpool_with_lanes (CORBA::ULong stacksize,
00341                                           const RTCORBA::ThreadpoolLanes &lanes,
00342                                           CORBA::Boolean allow_borrowing,
00343                                           CORBA::Boolean allow_request_buffering,
00344                                           CORBA::ULong max_buffered_requests,
00345                                           CORBA::ULong max_request_buffer_size)
00346 {
00347   return this->tp_manager_->create_threadpool_with_lanes (stacksize,
00348                                                           lanes,
00349                                                           allow_borrowing,
00350                                                           allow_request_buffering,
00351                                                           max_buffered_requests,
00352                                                           max_request_buffer_size,
00353                                                           this->lifespan_,
00354                                                           this->dynamic_thread_time_);
00355 }
00356 
00357 void
00358 TAO_RT_ORB::destroy_threadpool (RTCORBA::ThreadpoolId threadpool)
00359 {
00360   this->tp_manager_->destroy_threadpool (threadpool);
00361 }
00362 
00363 RTCORBA::PriorityModelPolicy_ptr
00364 TAO_RT_ORB::create_priority_model_policy (RTCORBA::PriorityModel priority_model,
00365                                           RTCORBA::Priority server_priority)
00366 {
00367   TAO_PriorityModelPolicy *tmp = 0;
00368   ACE_NEW_THROW_EX (tmp,
00369                     TAO_PriorityModelPolicy (priority_model, server_priority),
00370                     CORBA::NO_MEMORY (TAO::VMCID,
00371                                       CORBA::COMPLETED_NO));
00372 
00373   return tmp;
00374 }
00375 
00376 RTCORBA::ThreadpoolPolicy_ptr
00377 TAO_RT_ORB::create_threadpool_policy (RTCORBA::ThreadpoolId threadpool)
00378 {
00379   TAO_ThreadpoolPolicy *tmp = 0;
00380   ACE_NEW_THROW_EX (tmp,
00381                     TAO_ThreadpoolPolicy (threadpool),
00382                     CORBA::NO_MEMORY (TAO::VMCID,
00383                                       CORBA::COMPLETED_NO));
00384 
00385   return tmp;
00386 }
00387 
00388 RTCORBA::PriorityBandedConnectionPolicy_ptr
00389 TAO_RT_ORB::create_priority_banded_connection_policy (const
00390                                                       RTCORBA::PriorityBands & priority_bands)
00391 {
00392   TAO_PriorityBandedConnectionPolicy *tmp = 0;
00393   ACE_NEW_THROW_EX (tmp,
00394                     TAO_PriorityBandedConnectionPolicy (priority_bands),
00395                     CORBA::NO_MEMORY (TAO::VMCID,
00396                                       CORBA::COMPLETED_NO));
00397 
00398   return tmp;
00399 }
00400 
00401 RTCORBA::PrivateConnectionPolicy_ptr
00402 TAO_RT_ORB::create_private_connection_policy (void)
00403 {
00404   TAO_PrivateConnectionPolicy *tmp = 0;
00405   ACE_NEW_THROW_EX (tmp,
00406                     TAO_PrivateConnectionPolicy (),
00407                     CORBA::NO_MEMORY (TAO::VMCID,
00408                                       CORBA::COMPLETED_NO));
00409 
00410   return tmp;
00411 }
00412 
00413 RTCORBA::ServerProtocolPolicy_ptr
00414 TAO_RT_ORB::create_server_protocol_policy (const RTCORBA::ProtocolList & protocols)
00415 {
00416   TAO_ServerProtocolPolicy *tmp = 0;
00417   ACE_NEW_THROW_EX (tmp,
00418                     TAO_ServerProtocolPolicy (protocols),
00419                     CORBA::NO_MEMORY (TAO::VMCID,
00420                                       CORBA::COMPLETED_NO));
00421 
00422   return tmp;
00423 }
00424 
00425 RTCORBA::ClientProtocolPolicy_ptr
00426 TAO_RT_ORB::create_client_protocol_policy (const RTCORBA::ProtocolList & protocols)
00427 {
00428   TAO_ClientProtocolPolicy *tmp = 0;
00429   ACE_NEW_THROW_EX (tmp,
00430                     TAO_ClientProtocolPolicy (protocols),
00431                     CORBA::NO_MEMORY (TAO::VMCID,
00432                                       CORBA::COMPLETED_NO));
00433 
00434   return tmp;
00435 }
00436 
00437 TAO_Thread_Pool_Manager &
00438 TAO_RT_ORB::tp_manager (void) const
00439 {
00440   return *this->tp_manager_;
00441 }
00442 
00443 TAO_ORB_Core *
00444 TAO_RT_ORB::orb_core (void) const
00445 {
00446   return this->orb_core_;
00447 }
00448 
00449 /* static */
00450 int
00451 TAO_RT_ORB::modify_thread_scheduling_policy (CORBA::ORB_ptr orb)
00452 {
00453   //
00454   // This method changes the scheduling policy of the calling thread
00455   // to match the scheduling policy specified in the svc.conf file.
00456   // The priority of the calling thread will be set to the minimum
00457   // priority supported by that scheduling policy.
00458   //
00459   // This method make sense on those platform (e.g., Linux) where
00460   // PTHREAD_SCOPE_SYSTEM is the only scheduling scope supported.  On
00461   // other platforms, this method is a no-op since the only way to get
00462   // the real-time threading behavior is to setup the
00463   // PTHREAD_SCOPE_SYSTEM scheduling scope when a thread is being
00464   // created.  On such platforms, one can set the correct scheduling
00465   // scope and policy when creating the thread, thus not needing to
00466   // use this method.
00467   //
00468 
00469 #if defined (linux)
00470 
00471   int const sched_policy = orb->orb_core ()->orb_params ()->ace_sched_policy ();
00472 
00473   int const minimum_priority = ACE_Sched_Params::priority_min (sched_policy);
00474 
00475   ACE_hthread_t thread_id;
00476   ACE_Thread::self (thread_id);
00477 
00478   return ACE_Thread::setprio (thread_id, minimum_priority, sched_policy);
00479 
00480 #else /* linux */
00481 
00482   ACE_UNUSED_ARG (orb);
00483   ACE_NOTSUP_RETURN (-1);
00484 
00485 #endif /* linux */
00486 
00487 }
00488 
00489 TAO_END_VERSIONED_NAMESPACE_DECL
00490 
00491 ///////////////////////////////////////////////////////////////////////////////
00492 
00493 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */

Generated on Tue Feb 2 17:42:49 2010 for TAO_RTCORBA by  doxygen 1.4.7