Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / RTCORBA / Continuous_Priority_Mapping.cpp
blob549c24233205298ce85bfbba26c0f744e24a3d05
1 #include "tao/RTCORBA/Continuous_Priority_Mapping.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "ace/Sched_Params.h"
7 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
9 TAO_Continuous_Priority_Mapping::TAO_Continuous_Priority_Mapping (int policy)
10 : policy_ (policy)
11 , min_ (ACE_Sched_Params::priority_min (this->policy_))
12 , max_ (ACE_Sched_Params::priority_max (this->policy_))
16 TAO_Continuous_Priority_Mapping::~TAO_Continuous_Priority_Mapping ()
20 CORBA::Boolean
21 TAO_Continuous_Priority_Mapping::to_native (RTCORBA::Priority corba_priority,
22 RTCORBA::NativePriority &native_priority)
24 if (corba_priority < 0)
25 return false;
27 #if defined (ACE_WIN32)
29 int current_native_priority = this->min_;
30 int next_native_priority;
31 for (int i = 1; i <= corba_priority; ++i)
33 next_native_priority =
34 ACE_Sched_Params::next_priority (this->policy_,
35 current_native_priority);
37 if (next_native_priority == current_native_priority)
38 return false;
40 current_native_priority = next_native_priority;
43 native_priority = static_cast<RTCORBA::NativePriority> (current_native_priority);
44 return true;
46 #else
47 int native;
49 if (this->min_ < this->max_)
51 native = corba_priority + this->min_;
52 if (native > this->max_)
53 return false;
55 else if (this->min_ > this->max_)
57 native = this->min_ - corba_priority;
58 if (native < this->max_)
59 return false;
61 else
63 // There is only one native priority.
64 if (corba_priority != 0)
65 return false;
67 native = this->min_;
70 native_priority = native;
72 return true;
74 #endif /* ACE_WIN32 */
78 CORBA::Boolean
79 TAO_Continuous_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority,
80 RTCORBA::Priority &corba_priority)
82 #if defined (ACE_WIN32)
84 int current_native_priority = this->min_;
85 for (corba_priority = 0; ; ++corba_priority)
87 if (current_native_priority == native_priority)
88 return true;
90 else if (current_native_priority == this->max_)
91 return false;
93 else
94 current_native_priority =
95 ACE_Sched_Params::next_priority (this->policy_,
96 current_native_priority);
99 #else
101 if (this->min_ < this->max_)
103 if (native_priority < this->min_
104 || native_priority > this->max_)
105 return false;
106 corba_priority = native_priority - this->min_;
108 else if (this->min_ > this->max_)
110 if (native_priority > this->min_
111 || native_priority < this->max_)
112 return false;
113 corba_priority = this->min_ - native_priority;
115 else if (this->min_ == this->max_)
117 if (native_priority != this->min_)
118 return false;
119 corba_priority = 0;
122 return true;
124 #endif /* ACE_WIN32 */
128 TAO_END_VERSIONED_NAMESPACE_DECL
130 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */