1 #include "tao/RTCORBA/RT_ORB.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTCORBA/RT_Policy_i.h"
6 #include "tao/RTCORBA/RT_Mutex.h"
7 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
8 #include "tao/ORB_Core.h"
10 #include "tao/SystemException.h"
11 #include "tao/RTCORBA/Thread_Pool.h"
12 #include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h"
13 #include "ace/Sched_Params.h"
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 TAO_RT_ORB::TAO_RT_ORB (TAO_ORB_Core
*orb_core
,
18 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan
,
19 ACE_Time_Value
const &dynamic_thread_time
)
20 : orb_core_ (orb_core
),
24 dynamic_thread_time_ (dynamic_thread_time
)
26 TAO_Thread_Lane_Resources_Manager
*thread_lane_resources_manager
=
27 &this->orb_core_
->thread_lane_resources_manager ();
29 TAO_RT_Thread_Lane_Resources_Manager
*rt_thread_lane_resources_manager
=
30 dynamic_cast <TAO_RT_Thread_Lane_Resources_Manager
*> (thread_lane_resources_manager
);
32 if (!rt_thread_lane_resources_manager
)
33 throw CORBA::INTERNAL ();
36 &rt_thread_lane_resources_manager
->tp_manager ();
39 TAO_RT_ORB::~TAO_RT_ORB ()
44 TAO_RT_ORB::create_mutex ()
46 return this->mutex_mgr_
.create_mutex ();
50 TAO_RT_ORB::destroy_mutex (RTCORBA::Mutex_ptr mutex
)
52 this->mutex_mgr_
.destroy_mutex (mutex
);
57 TAO_RT_ORB::create_named_mutex (const char *name
,
58 CORBA::Boolean_out created_flag
)
60 return this->mutex_mgr_
.create_named_mutex (name
, created_flag
);
64 TAO_RT_ORB::open_named_mutex (const char *name
)
66 return this->mutex_mgr_
.open_named_mutex (name
);
69 ////////////////////////////////////////////////////////////////////////////////
71 TAO_Named_RT_Mutex_Manager::TAO_Named_RT_Mutex_Manager ()
75 TAO_Named_RT_Mutex_Manager::~TAO_Named_RT_Mutex_Manager ()
80 TAO_Named_RT_Mutex_Manager::create_mutex ()
82 TAO_RT_Mutex
*mutex
= 0;
83 ACE_NEW_THROW_EX (mutex
,
86 CORBA::SystemException::_tao_minor_code (
89 CORBA::COMPLETED_NO
));
94 // If Named RT_Mutexes aren't enabled, this function is a nop
95 // as also indicated by the comment below.
96 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
98 TAO_Named_RT_Mutex_Manager::destroy_mutex (RTCORBA::Mutex_ptr mutex
)
100 TAO_RT_Mutex
*tao_mutex
=
101 dynamic_cast<TAO_RT_Mutex
*> (mutex
);
103 // If this mutex is named, then we need to remove it from our table.
104 // Otherwise, we don't have to do anything.
105 const char *name
= tao_mutex
->name ();
108 // The following should be atomic.
109 ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX
,
115 this->map_
.unbind (name
);
118 throw ::CORBA::INTERNAL ();
121 #else /* TAO_HAS_NAMED_RT_MUTEXES == 1 */
123 TAO_Named_RT_Mutex_Manager::destroy_mutex (RTCORBA::Mutex_ptr
)
126 #endif /* TAO_HAS_NAMED_RT_MUTEXES == 1 */
129 TAO_Named_RT_Mutex_Manager::create_named_mutex (const char *name
,
130 CORBA::Boolean_out created_flag
)
132 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
133 // The following should be atomic.
134 ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX
,
139 // Optimistic that we'll find it.
140 created_flag
= false;
142 // If we find the mutex, simply return it.
143 RTCORBA::Mutex_var mutex
;
144 if (this->map_
.find (name
, mutex
) != 0)
146 // Oops, we didn't find it.
149 RTCORBA::Mutex_ptr tmp_mutex
;
152 ACE_NEW_THROW_EX (tmp_mutex
,
153 TAO_Named_RT_Mutex (name
),
155 CORBA::SystemException::_tao_minor_code (
158 CORBA::COMPLETED_NO
));
162 // Add it to the map.
163 int const result
= this->map_
.bind (name
, mutex
);
166 throw ::CORBA::INTERNAL ();
169 // Return the one we found or created.
170 return mutex
._retn ();
171 #else /* TAO_HAS_NAMED_RT_MUTEXES */
172 ACE_UNUSED_ARG (name
);
173 ACE_UNUSED_ARG (created_flag
);
174 throw ::CORBA::NO_IMPLEMENT ();
175 #endif /* TAO_HAS_NAMED_RT_MUTEXES */
179 TAO_Named_RT_Mutex_Manager::open_named_mutex (const char *name
)
181 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
182 // The following should be atomic.
183 ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX
,
188 // If we find the mutex, simply return it.
189 RTCORBA::Mutex_var mutex
;
190 if (this->map_
.find (name
, mutex
) != 0)
191 throw RTCORBA::RTORB::MutexNotFound ();
193 // Return the one we found.
194 return mutex
._retn ();
195 #else /* TAO_HAS_NAMED_RT_MUTEXES */
196 ACE_UNUSED_ARG (name
);
197 throw ::CORBA::NO_IMPLEMENT ();
198 #endif /* TAO_HAS_NAMED_RT_MUTEXES */
201 ///////////////////////////////////////////////////////////////////////////////
203 RTCORBA::TCPProtocolProperties_ptr
204 TAO_RT_ORB::create_tcp_protocol_properties (CORBA::Long send_buffer_size
,
205 CORBA::Long recv_buffer_size
,
206 CORBA::Boolean keep_alive
,
207 CORBA::Boolean dont_route
,
208 CORBA::Boolean no_delay
,
209 CORBA::Boolean enable_network_priority
)
211 TAO_TCP_Protocol_Properties
*tmp
= 0;
212 ACE_NEW_THROW_EX (tmp
,
213 TAO_TCP_Protocol_Properties (send_buffer_size
,
218 enable_network_priority
),
219 CORBA::NO_MEMORY (TAO::VMCID
,
220 CORBA::COMPLETED_NO
));
225 RTCORBA::UnixDomainProtocolProperties_ptr
226 TAO_RT_ORB::create_unix_domain_protocol_properties (
227 CORBA::Long send_buffer_size
,
228 CORBA::Long recv_buffer_size
)
230 TAO_UnixDomain_Protocol_Properties
*tmp
= 0;
231 ACE_NEW_THROW_EX (tmp
,
232 TAO_UnixDomain_Protocol_Properties (
235 CORBA::NO_MEMORY (TAO::VMCID
,
236 CORBA::COMPLETED_NO
));
241 RTCORBA::SharedMemoryProtocolProperties_ptr
242 TAO_RT_ORB::create_shared_memory_protocol_properties (
243 CORBA::Long send_buffer_size
,
244 CORBA::Long recv_buffer_size
,
245 CORBA::Boolean keep_alive
,
246 CORBA::Boolean dont_route
,
247 CORBA::Boolean no_delay
,
248 CORBA::Long preallocate_buffer_size
,
249 const char *mmap_filename
,
250 const char *mmap_lockname
)
252 TAO_SharedMemory_Protocol_Properties
*tmp
= 0;
253 ACE_NEW_THROW_EX (tmp
,
254 TAO_SharedMemory_Protocol_Properties (send_buffer_size
,
259 preallocate_buffer_size
,
262 CORBA::NO_MEMORY (TAO::VMCID
,
263 CORBA::COMPLETED_NO
));
268 RTCORBA::UserDatagramProtocolProperties_ptr
269 TAO_RT_ORB::create_user_datagram_protocol_properties (
270 CORBA::Long send_buffer_size
,
271 CORBA::Long recv_buffer_size
,
272 CORBA::Boolean enable_network_priority
)
274 TAO_UserDatagram_Protocol_Properties
*tmp
= 0;
275 ACE_NEW_THROW_EX (tmp
,
276 TAO_UserDatagram_Protocol_Properties (
279 enable_network_priority
),
280 CORBA::NO_MEMORY (TAO::VMCID
,
281 CORBA::COMPLETED_NO
));
286 RTCORBA::StreamControlProtocolProperties_ptr
287 TAO_RT_ORB::create_stream_control_protocol_properties (
288 CORBA::Long send_buffer_size
,
289 CORBA::Long recv_buffer_size
,
290 CORBA::Boolean keep_alive
,
291 CORBA::Boolean dont_route
,
292 CORBA::Boolean no_delay
,
293 CORBA::Boolean enable_network_priority
)
295 TAO_StreamControl_Protocol_Properties
*tmp
= 0;
296 ACE_NEW_THROW_EX (tmp
,
297 TAO_StreamControl_Protocol_Properties (
303 enable_network_priority
),
304 CORBA::NO_MEMORY (TAO::VMCID
,
305 CORBA::COMPLETED_NO
));
310 RTCORBA::ThreadpoolId
311 TAO_RT_ORB::create_threadpool (CORBA::ULong stacksize
,
312 CORBA::ULong static_threads
,
313 CORBA::ULong dynamic_threads
,
314 RTCORBA::Priority default_priority
,
315 CORBA::Boolean allow_request_buffering
,
316 CORBA::ULong max_buffered_requests
,
317 CORBA::ULong max_request_buffer_size
)
319 return this->tp_manager_
->create_threadpool (stacksize
,
323 allow_request_buffering
,
324 max_buffered_requests
,
325 max_request_buffer_size
,
327 this->dynamic_thread_time_
);
330 RTCORBA::ThreadpoolId
331 TAO_RT_ORB::create_threadpool_with_lanes (CORBA::ULong stacksize
,
332 const RTCORBA::ThreadpoolLanes
&lanes
,
333 CORBA::Boolean allow_borrowing
,
334 CORBA::Boolean allow_request_buffering
,
335 CORBA::ULong max_buffered_requests
,
336 CORBA::ULong max_request_buffer_size
)
338 return this->tp_manager_
->create_threadpool_with_lanes (stacksize
,
341 allow_request_buffering
,
342 max_buffered_requests
,
343 max_request_buffer_size
,
345 this->dynamic_thread_time_
);
349 TAO_RT_ORB::destroy_threadpool (RTCORBA::ThreadpoolId threadpool
)
351 this->tp_manager_
->destroy_threadpool (threadpool
);
354 RTCORBA::PriorityModelPolicy_ptr
355 TAO_RT_ORB::create_priority_model_policy (RTCORBA::PriorityModel priority_model
,
356 RTCORBA::Priority server_priority
)
358 TAO_PriorityModelPolicy
*tmp
= 0;
359 ACE_NEW_THROW_EX (tmp
,
360 TAO_PriorityModelPolicy (priority_model
, server_priority
),
361 CORBA::NO_MEMORY (TAO::VMCID
,
362 CORBA::COMPLETED_NO
));
367 RTCORBA::ThreadpoolPolicy_ptr
368 TAO_RT_ORB::create_threadpool_policy (RTCORBA::ThreadpoolId threadpool
)
370 TAO_ThreadpoolPolicy
*tmp
= 0;
371 ACE_NEW_THROW_EX (tmp
,
372 TAO_ThreadpoolPolicy (threadpool
),
373 CORBA::NO_MEMORY (TAO::VMCID
,
374 CORBA::COMPLETED_NO
));
379 RTCORBA::PriorityBandedConnectionPolicy_ptr
380 TAO_RT_ORB::create_priority_banded_connection_policy (const
381 RTCORBA::PriorityBands
& priority_bands
)
383 TAO_PriorityBandedConnectionPolicy
*tmp
= 0;
384 ACE_NEW_THROW_EX (tmp
,
385 TAO_PriorityBandedConnectionPolicy (priority_bands
),
386 CORBA::NO_MEMORY (TAO::VMCID
,
387 CORBA::COMPLETED_NO
));
392 RTCORBA::PrivateConnectionPolicy_ptr
393 TAO_RT_ORB::create_private_connection_policy ()
395 TAO_PrivateConnectionPolicy
*tmp
= 0;
396 ACE_NEW_THROW_EX (tmp
,
397 TAO_PrivateConnectionPolicy (),
398 CORBA::NO_MEMORY (TAO::VMCID
,
399 CORBA::COMPLETED_NO
));
404 RTCORBA::ServerProtocolPolicy_ptr
405 TAO_RT_ORB::create_server_protocol_policy (const RTCORBA::ProtocolList
& protocols
)
407 TAO_ServerProtocolPolicy
*tmp
= 0;
408 ACE_NEW_THROW_EX (tmp
,
409 TAO_ServerProtocolPolicy (protocols
),
410 CORBA::NO_MEMORY (TAO::VMCID
,
411 CORBA::COMPLETED_NO
));
416 RTCORBA::ClientProtocolPolicy_ptr
417 TAO_RT_ORB::create_client_protocol_policy (const RTCORBA::ProtocolList
& protocols
)
419 TAO_ClientProtocolPolicy
*tmp
= 0;
420 ACE_NEW_THROW_EX (tmp
,
421 TAO_ClientProtocolPolicy (protocols
),
422 CORBA::NO_MEMORY (TAO::VMCID
,
423 CORBA::COMPLETED_NO
));
428 TAO_Thread_Pool_Manager
&
429 TAO_RT_ORB::tp_manager () const
431 return *this->tp_manager_
;
435 TAO_RT_ORB::orb_core () const
437 return this->orb_core_
;
442 TAO_RT_ORB::modify_thread_scheduling_policy (CORBA::ORB_ptr orb
)
444 // This method changes the scheduling policy of the calling thread
445 // to match the scheduling policy specified in the svc.conf file.
446 // The priority of the calling thread will be set to the minimum
447 // priority supported by that scheduling policy.
449 // This method make sense on those platform (e.g., Linux) where
450 // PTHREAD_SCOPE_SYSTEM is the only scheduling scope supported. On
451 // other platforms, this method is a no-op since the only way to get
452 // the real-time threading behavior is to setup the
453 // PTHREAD_SCOPE_SYSTEM scheduling scope when a thread is being
454 // created. On such platforms, one can set the correct scheduling
455 // scope and policy when creating the thread, thus not needing to
458 #if !defined (ACE_LACKS_THREAD_PROCESS_SCOPING) && defined (ACE_LACKS_PTHREAD_SCOPE_PROCESS)
460 int const sched_policy
= orb
->orb_core ()->orb_params ()->ace_sched_policy ();
462 int const minimum_priority
= ACE_Sched_Params::priority_min (sched_policy
);
464 ACE_hthread_t thread_id
;
465 ACE_Thread::self (thread_id
);
467 return ACE_Thread::setprio (thread_id
, minimum_priority
, sched_policy
);
469 #else /* !ACE_LACKS_THREAD_PROCESS_SCOPING && ACE_LACKS_PTHREAD_SCOPE_PROCESS */
471 ACE_UNUSED_ARG (orb
);
472 ACE_NOTSUP_RETURN (-1);
478 TAO_END_VERSIONED_NAMESPACE_DECL
480 ///////////////////////////////////////////////////////////////////////////////
482 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */