diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-09-13 00:32:20 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-09-13 00:32:20 +0000 |
commit | bb581ca34145d9f88c8d95ee2a1a885d2572f1f6 (patch) | |
tree | 714c1845a75010173147e153a132fc1589bfc1ce /TAO/tao/RTCORBA | |
parent | 0b10bc456cf2ecca67f9e97b225835c5a7ac5599 (diff) | |
download | ATCD-bb581ca34145d9f88c8d95ee2a1a885d2572f1f6.tar.gz |
New branch Thread_Pool_stage_3 (very close to x.1.20 release)
Diffstat (limited to 'TAO/tao/RTCORBA')
-rw-r--r-- | TAO/tao/RTCORBA/Continuous_Priority_Mapping.cpp | 130 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/Continuous_Priority_Mapping.h | 75 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/Continuous_Priority_Mapping.i | 1 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp | 134 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h | 105 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i | 1 |
6 files changed, 446 insertions, 0 deletions
diff --git a/TAO/tao/RTCORBA/Continuous_Priority_Mapping.cpp b/TAO/tao/RTCORBA/Continuous_Priority_Mapping.cpp new file mode 100644 index 00000000000..fe50a6d7e4d --- /dev/null +++ b/TAO/tao/RTCORBA/Continuous_Priority_Mapping.cpp @@ -0,0 +1,130 @@ +// $Id$ + +#include "Continuous_Priority_Mapping.h" +#include "ace/Sched_Params.h" + +#if !defined (__ACE_INLINE__) +# include "Continuous_Priority_Mapping.i" +#endif /* ! __ACE_INLINE__ */ + +ACE_RCSID(RTCORBA, Continuous_Priority_Mapping, "$Id: ") + +TAO_Continuous_Priority_Mapping::TAO_Continuous_Priority_Mapping (int policy) + : policy_ (policy) +{ + this->min_ = + ACE_Sched_Params::priority_min (this->policy_); + + this->max_ = + ACE_Sched_Params::priority_max (this->policy_); +} + +TAO_Continuous_Priority_Mapping::~TAO_Continuous_Priority_Mapping (void) +{ +} + +CORBA::Boolean +TAO_Continuous_Priority_Mapping::to_native (RTCORBA::Priority corba_priority, + RTCORBA::NativePriority &native_priority) +{ + if (corba_priority < 0) + return 0; + +#if defined (ACE_WIN32) + + int current_native_priority = this->min_; + int next_native_priority; + for (int i = 1; i <= corba_priority; ++i) + { + next_native_priority = + ACE_Sched_Params::next_priority (this->policy_, + current_native_priority); + + if (next_native_priority == current_native_priority) + return 0; + + current_native_priority = next_native_priority; + } + + native_priority = current_native_priority; + return 1; + +#else + + if (this->min_ < this->max_) + { + native_priority = corba_priority + this->min_; + if (native_priority > this->max_) + return 0; + } + else if (this->min_ > this->max_) + { + native_priority = this->min_ - corba_priority; + if (native_priority < this->max_) + return 0; + } + else + { + // There is only one native priority. + if (corba_priority != 0) + return 0; + + native_priority = this->min_; + } + + return 1; + +#endif /* ACE_WIN32 */ + +} + +CORBA::Boolean +TAO_Continuous_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority, + RTCORBA::Priority &corba_priority) +{ + +#if defined (ACE_WIN32) + + int current_native_priority = this->min_; + for (corba_priority = 0; ; ++corba_priority) + { + if (current_native_priority == native_priority) + return 1; + + else if (current_native_priority == this->max_) + return 0; + + else + current_native_priority = + ACE_Sched_Params::next_priority (this->policy_, + current_native_priority); + } + +#else + + if (this->min_ < this->max_) + { + if (native_priority < this->min_ + || native_priority > this->max_) + return 0; + corba_priority = native_priority - this->min_; + } + else if (this->min_ > this->max_) + { + if (native_priority > this->min_ + || native_priority < this->max_) + return 0; + corba_priority = this->min_ - native_priority; + } + else if (this->min_ == this->max_) + { + if (native_priority != this->min_) + return 0; + corba_priority = 0; + } + + return 1; + +#endif /* ACE_WIN32 */ + +} diff --git a/TAO/tao/RTCORBA/Continuous_Priority_Mapping.h b/TAO/tao/RTCORBA/Continuous_Priority_Mapping.h new file mode 100644 index 00000000000..820df1379fb --- /dev/null +++ b/TAO/tao/RTCORBA/Continuous_Priority_Mapping.h @@ -0,0 +1,75 @@ +//============================================================================= +/** + * @file Continuous_Priority_Mapping.h + * + * $Id$ + * + * @author Irfan Pyarali + */ +// =================================================================== + +#ifndef TAO_CONTINUOUS_PRIORITY_MAPPING_H +#define TAO_CONTINUOUS_PRIORITY_MAPPING_H + +#include "ace/pre.h" +#include "tao/orbconf.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "rtcorba_export.h" +#include "Priority_Mapping.h" + +/** + * @class TAO_Continuous_Priority_Mapping + * + * @brief Maps the first n CORBA priorities to the range of native + * priorities, where n is the number of native priorities. + * + * The lowest native priority is mapped to CORBA priority 0, next + * higher native priority is mapped to CORBA priority 1, and so + * on. Since in all the operating systems where TAO is supported the + * native priority set contains less than 32767 priorities, part of + * the CORBA priority range is left unused. Consider NT as an + * example. NT native priorities -15 -2 -1 0 1 2 15 are mapped to + * CORBA priorities 0 1 2 3 4 5 6, respectively, and the rest of the + * CORBA priority range is not used. + * + * This class was previously called Direct_Priority_Mapping. + * + * \nosubgrouping + * + **/ +class TAO_RTCORBA_Export TAO_Continuous_Priority_Mapping + : public TAO_Priority_Mapping +{ +public: + + /// Constructor. + TAO_Continuous_Priority_Mapping (int policy = ACE_SCHED_OTHER); + + /// Destructor. + ~TAO_Continuous_Priority_Mapping (void); + + /// Convert CORBA priority to native priority. + CORBA::Boolean to_native (RTCORBA::Priority corba_priority, + RTCORBA::NativePriority &native_priority); + + /// Convert native priority to CORBA priority. + CORBA::Boolean to_CORBA (RTCORBA::NativePriority native_priority, + RTCORBA::Priority &corba_priority); + +private: + int policy_; + int min_; + int max_; +}; + +#if defined (__ACE_INLINE__) +# include "Continuous_Priority_Mapping.i" +#endif /* __ACE_INLINE__ */ + +#include "ace/post.h" + +#endif /* TAO_CONTINUOUS_PRIORITY_MAPPING_H */ diff --git a/TAO/tao/RTCORBA/Continuous_Priority_Mapping.i b/TAO/tao/RTCORBA/Continuous_Priority_Mapping.i new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/tao/RTCORBA/Continuous_Priority_Mapping.i @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp new file mode 100644 index 00000000000..0c0b75c99cd --- /dev/null +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp @@ -0,0 +1,134 @@ +// $Id$ + +#include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h" + +ACE_RCSID(RTCORBA, RT_Thread_Lane_Resources_Manager, "$Id$") + +#include "tao/ORB_Core.h" +#include "tao/Acceptor_Registry.h" +#include "tao/Thread_Lane_Resources.h" +#include "tao/RTCORBA/Thread_Pool.h" +#include "tao/Leader_Follower.h" + +#if !defined (__ACE_INLINE__) +# include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i" +#endif /* ! __ACE_INLINE__ */ + +TAO_RT_Thread_Lane_Resources_Manager::TAO_RT_Thread_Lane_Resources_Manager (TAO_ORB_Core &orb_core) + : TAO_Thread_Lane_Resources_Manager (orb_core), + default_lane_resources_ (0), + tp_manager_ (0) +{ + // Create the default resources. + ACE_NEW (this->default_lane_resources_, + TAO_Thread_Lane_Resources (orb_core)); + + // Create the thread-pool manager. + ACE_NEW (this->tp_manager_, + TAO_Thread_Pool_Manager (orb_core)); + +} + +TAO_RT_Thread_Lane_Resources_Manager::~TAO_RT_Thread_Lane_Resources_Manager (void) +{ + // Delete the default resources. + delete this->default_lane_resources_; + + // Delete the thread-pool manager. + delete this->tp_manager_; +} + +int +TAO_RT_Thread_Lane_Resources_Manager::open_default_resources (CORBA_Environment &ACE_TRY_ENV) +{ + int result = + this->default_lane_resources_->open_acceptor_registry (0, + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + return result; +} + +void +TAO_RT_Thread_Lane_Resources_Manager::finalize (void) +{ + // Finalize default resources. + this->default_lane_resources_->finalize (); + + // Finalize resources managed by the thread-pool manager. + this->tp_manager_->finalize (); +} + +void +TAO_RT_Thread_Lane_Resources_Manager::shutdown_reactor (void) +{ + // Shutdown default reactors. + this->default_lane_resources_->shutdown_reactor (); + + // Shutdown reactors managed by the thread-pool manager. + this->tp_manager_->shutdown_reactor (); +} + +int +TAO_RT_Thread_Lane_Resources_Manager::is_collocated (const TAO_MProfile &mprofile) +{ + int result = + this->default_lane_resources_->is_collocated (mprofile); + + if (result) + return result; + + return this->tp_manager_->is_collocated (mprofile); +} + +TAO_Thread_Lane_Resources & +TAO_RT_Thread_Lane_Resources_Manager::lane_resources (void) +{ + // Get the ORB_Core's TSS resources. + TAO_ORB_Core_TSS_Resources &tss = + *this->orb_core_->get_tss_resources (); + + // Get the lane for this thread. + TAO_Thread_Lane *lane = + (TAO_Thread_Lane *) tss.lane_; + + // If we have a valid lane, use that lane's resources. + if (lane) + return lane->resources (); + else + // Otherwise, return the default resources. + return *this->default_lane_resources_; +} + +TAO_Thread_Lane_Resources & +TAO_RT_Thread_Lane_Resources_Manager::default_lane_resources (void) +{ + return *this->default_lane_resources_; +} + +TAO_Thread_Pool_Manager & +TAO_RT_Thread_Lane_Resources_Manager::tp_manager (void) +{ + return *this->tp_manager_; +} + +TAO_Thread_Lane_Resources_Manager * +TAO_RT_Thread_Lane_Resources_Manager_Factory::create_thread_lane_resources_manager (TAO_ORB_Core &core) +{ + TAO_Thread_Lane_Resources_Manager *manager = 0; + + /// Create the RT Thread Lane Resources Manager. + ACE_NEW_RETURN (manager, + TAO_RT_Thread_Lane_Resources_Manager (core), + 0); + + return manager; +} + +ACE_STATIC_SVC_DEFINE (TAO_RT_Thread_Lane_Resources_Manager_Factory, + ACE_TEXT ("RT_Thread_Lane_Resources_Manager_Factory"), + ACE_SVC_OBJ_T, + &ACE_SVC_NAME (TAO_RT_Thread_Lane_Resources_Manager_Factory), + ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ, + 0) +ACE_FACTORY_DEFINE (TAO, TAO_RT_Thread_Lane_Resources_Manager_Factory) diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h new file mode 100644 index 00000000000..eff190fd84a --- /dev/null +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h @@ -0,0 +1,105 @@ +//============================================================================= +/** + * @file RT_Thread_Lane_Resources_Manager.h + * + * $Id$ + * + * @author Irfan Pyarali + */ +// =================================================================== + +#ifndef TAO_RT_THREAD_LANE_RESOURCES_MANAGER_H +#define TAO_RT_THREAD_LANE_RESOURCES_MANAGER_H + +#include "ace/pre.h" +#include "tao/orbconf.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/RTCORBA/rtcorba_export.h" +#include "tao/Thread_Lane_Resources_Manager.h" +#include "ace/Service_Config.h" + +class TAO_Thread_Pool_Manager; + +/** + * @class TAO_RT_Thread_Lane_Resources_Manager + * + * @brief Manager for thread lane resources. + * + * \nosubgrouping + * + **/ +class TAO_RTCORBA_Export TAO_RT_Thread_Lane_Resources_Manager : + public TAO_Thread_Lane_Resources_Manager +{ +public: + + /// Constructor. + TAO_RT_Thread_Lane_Resources_Manager (TAO_ORB_Core &orb_core); + + /// Destructor. + ~TAO_RT_Thread_Lane_Resources_Manager (void); + + /// Finalize resources. + void finalize (void); + + /// Open default resources. + int open_default_resources (CORBA_Environment &ACE_TRY_ENV); + + /// Shutdown reactor. + void shutdown_reactor (void); + + // Does <mprofile> belong to us? + int is_collocated (const TAO_MProfile &mprofile); + + /// @name Accessors + // @{ + + TAO_Thread_Lane_Resources &lane_resources (void); + + TAO_Thread_Lane_Resources &default_lane_resources (void); + + TAO_Thread_Pool_Manager &tp_manager (void); + + // @} + +protected: + + /// Default lane resources. + TAO_Thread_Lane_Resources *default_lane_resources_; + + /// Thread Pool Manager. + TAO_Thread_Pool_Manager *tp_manager_; +}; + +/** + * @class TAO_RT_Thread_Lane_Resources_Manager_Factory + * + * @brief This class is a factory for managers of thread resources. + * + * \nosubgrouping + * + **/ +class TAO_RTCORBA_Export TAO_RT_Thread_Lane_Resources_Manager_Factory + : public TAO_Thread_Lane_Resources_Manager_Factory +{ +public: + + /// Factory method. + TAO_Thread_Lane_Resources_Manager *create_thread_lane_resources_manager (TAO_ORB_Core &core); + +}; + +ACE_STATIC_SVC_DECLARE_EXPORT (TAO_RTCORBA, TAO_RT_Thread_Lane_Resources_Manager_Factory) +ACE_FACTORY_DECLARE (TAO_RTCORBA, TAO_RT_Thread_Lane_Resources_Manager_Factory) + +#if defined (__ACE_INLINE__) +# include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i" +#endif /* __ACE_INLINE__ */ + +#include "ace/post.h" + +#endif /* TAO_RT_THREAD_LANE_RESOURCES_MANAGER_H */ diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i @@ -0,0 +1 @@ +// $Id$ |