A simple implementation of the Priority_Mapping interface. More...
#include <Linear_Priority_Mapping.h>
Public Member Functions | |
TAO_Linear_Priority_Mapping (long policy) | |
Default constructor. | |
virtual | ~TAO_Linear_Priority_Mapping (void) |
The destructor. | |
virtual CORBA::Boolean | to_native (RTCORBA::Priority corba_priority, RTCORBA::NativePriority &native_priority) |
virtual CORBA::Boolean | to_CORBA (RTCORBA::NativePriority native_priority, RTCORBA::Priority &corba_priority) |
Private Attributes | |
long | policy_ |
The scheduling policy. | |
int const | min_ |
int const | max_ |
A simple implementation of the Priority_Mapping interface.
This implementation uses linear mapping between the range of priorities for a given scheduling class (ACE_SCHED_OTHER, ACE_SCHED_FIFO, ACE_SCHED_RR) and the valid range of CORBA priorities (0...32767)
Definition at line 46 of file Linear_Priority_Mapping.h.
TAO_Linear_Priority_Mapping::TAO_Linear_Priority_Mapping | ( | long | policy | ) |
Default constructor.
Definition at line 19 of file Linear_Priority_Mapping.cpp.
: policy_ (policy) , min_ (ACE_Sched_Params::priority_min (this->policy_)) , max_ (ACE_Sched_Params::priority_max (this->policy_)) { }
TAO_Linear_Priority_Mapping::~TAO_Linear_Priority_Mapping | ( | void | ) | [virtual] |
CORBA::Boolean TAO_Linear_Priority_Mapping::to_CORBA | ( | RTCORBA::NativePriority | native_priority, | |
RTCORBA::Priority & | corba_priority | |||
) | [virtual] |
Implements TAO_Priority_Mapping.
Definition at line 85 of file Linear_Priority_Mapping.cpp.
{ #if defined (ACE_WIN32) // Iterate over native priorities in order to 1) make sure // <native_priority> argument contains a valid value, 2) count its // index among all valid native pr. values, 3) get the total number // of native priority values for the current platform. int total; int native_priority_index = 0; int current_priority = this->min_; for (total = 1; ; ++total) { if (native_priority == current_priority) native_priority_index = total; if (current_priority == this->max_) break; current_priority = ACE_Sched_Params::next_priority (this->policy_, current_priority); } if (native_priority_index == 0) return 0; int delta = total - 1; if (delta != 0) { int numerator = (RTCORBA::maxPriority - RTCORBA::minPriority) * (native_priority_index - 1); div_t corba_offset = div (numerator, delta); int rounding = 0; if (corba_offset.rem) { rounding = ((numerator < 0 && delta < 0) || (numerator >= 0 && delta >= 0) ? 1 : -1); } corba_priority = static_cast<RTCORBA::Priority> (RTCORBA::minPriority + corba_offset.quot + rounding); } else { // There is only one native priority. corba_priority = RTCORBA::minPriority; } return 1; #else if ((this->min_ < this->max_ && (native_priority < this->min_ || native_priority > this->max_)) || (this->min_ > this->max_ && (native_priority < this->max_ || native_priority > this->min_))) { ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Linear_Priority_Mapping::to_CORBA: " " priority %d out of range [%d,%d]\n", native_priority, this->min_, this->max_)); return 0; } int delta = this->max_ - this->min_; if (delta != 0) { int numerator = (RTCORBA::maxPriority - RTCORBA::minPriority) * (native_priority - this->min_); div_t corba_offset = div (numerator, delta); int rounding = 0; if (corba_offset.rem) { rounding = ((numerator < 0 && delta < 0) || (numerator >= 0 && delta >= 0) ? 1 : -1); } corba_priority = RTCORBA::minPriority + corba_offset.quot + rounding; } else { // There is only one native priority. if (native_priority != this->min_) return 0; corba_priority = RTCORBA::minPriority; } return 1; #endif /* ACE_WIN32 */ }
CORBA::Boolean TAO_Linear_Priority_Mapping::to_native | ( | RTCORBA::Priority | corba_priority, | |
RTCORBA::NativePriority & | native_priority | |||
) | [virtual] |
Implements TAO_Priority_Mapping.
Definition at line 31 of file Linear_Priority_Mapping.cpp.
{ if (corba_priority < RTCORBA::minPriority // The line below will always be false unless the value of // RTCORBA::maxPriority, which is now assigned the value of // 32767, is changed in RTCORBA.pidl. // || corba_priority > RTCORBA::maxPriority ) { return 0; } #if defined (ACE_WIN32) // Count up the number of distinct native priorities on current // platform. int n; int current_priority = this->min_; for (n = 1; current_priority != this->max_; ++n) { current_priority = ACE_Sched_Params::next_priority (this->policy_, current_priority); } int native_priority_index = 1 + ((n - 1) * (corba_priority - RTCORBA::minPriority) / (RTCORBA::maxPriority - RTCORBA::minPriority)); // Now, find the value corresponding to this index. native_priority = static_cast<RTCORBA::NativePriority> (this->min_); for (int i = 2; i <= native_priority_index; ++i) { native_priority = static_cast<RTCORBA::NativePriority> (ACE_Sched_Params::next_priority (this->policy_, native_priority)); } return 1; #else native_priority = this->min_ + ((this->max_ - this->min_) * (corba_priority - RTCORBA::minPriority) / (RTCORBA::maxPriority - RTCORBA::minPriority)); return 1; #endif /* ACE_WIN32 */ }
int const TAO_Linear_Priority_Mapping::max_ [private] |
Definition at line 66 of file Linear_Priority_Mapping.h.
int const TAO_Linear_Priority_Mapping::min_ [private] |
Definition at line 65 of file Linear_Priority_Mapping.h.
long TAO_Linear_Priority_Mapping::policy_ [private] |
The scheduling policy.
Definition at line 62 of file Linear_Priority_Mapping.h.