Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

ACE_Dynamic_Message_Strategy Class Reference

An abstract base class which provides dynamic priority evaluation methods for use by the ACE_Dynamic_Message_Queue class or any other class which needs to manage the priorities of a collection of ACE_Message_Blocks dynamically. More...

#include <Dynamic_Message_Strategy.h>

Inheritance diagram for ACE_Dynamic_Message_Strategy:
Inheritance graph
[legend]
Collaboration diagram for ACE_Dynamic_Message_Strategy:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Priority_Status { PENDING = 0x01, LATE = 0x02, BEYOND_LATE = 0x04, ANY_STATUS = 0x07 }

Public Member Functions

 ACE_Dynamic_Message_Strategy (unsigned long static_bit_field_mask, unsigned long static_bit_field_shift, unsigned long dynamic_priority_max, unsigned long dynamic_priority_offset)
 Constructor.
virtual ~ACE_Dynamic_Message_Strategy (void)
 Virtual destructor.
Priority_Status priority_status (ACE_Message_Block &mb, const ACE_Time_Value &tv)
 Updates the message's priority and returns its priority status.
unsigned long static_bit_field_mask (void) const
 Get static bit field mask.
void static_bit_field_mask (unsigned long)
 Set static bit field mask.
unsigned long static_bit_field_shift (void) const
 Get left shift value to make room for static bit field.
void static_bit_field_shift (unsigned long)
 Set left shift value to make room for static bit field.
unsigned long dynamic_priority_max (void) const
 Get maximum supported priority value.
void dynamic_priority_max (unsigned long)
 Set maximum supported priority value.
unsigned long dynamic_priority_offset (void) const
 Get offset to boundary between signed range and unsigned range.
void dynamic_priority_offset (unsigned long)
 Set offset to boundary between signed range and unsigned range.
virtual void dump (void) const
 Dump the state of the strategy.

Protected Member Functions

virtual void convert_priority (ACE_Time_Value &priority, const ACE_Message_Block &mb)=0
 Hook method for dynamic priority conversion.

Protected Attributes

unsigned long static_bit_field_mask_
 This is a bit mask with all ones in the static bit field.
unsigned long static_bit_field_shift_
unsigned long dynamic_priority_max_
 Maximum supported priority value.
unsigned long dynamic_priority_offset_
 Offset to boundary between signed range and unsigned range.
ACE_Time_Value max_late_
 Maximum late time value that can be represented.
ACE_Time_Value min_pending_
 Minimum pending time value that can be represented.
ACE_Time_Value pending_shift_
 Time value by which to shift pending priority.

Detailed Description

An abstract base class which provides dynamic priority evaluation methods for use by the ACE_Dynamic_Message_Queue class or any other class which needs to manage the priorities of a collection of ACE_Message_Blocks dynamically.

Methods for deadline and laxity based priority evaluation are provided. These methods assume a specific partitioning of the message priority number into a higher order dynamic bit field and a lower order static priority bit field. The default partitioning assumes an unsigned dynamic message priority field of 22 bits and an unsigned static message priority field of 10 bits. This corresponds to the initial values of the static class members. To provide a different partitioning, assign a different set of values to the static class memebers before using the static member functions.

Definition at line 48 of file Dynamic_Message_Strategy.h.


Member Enumeration Documentation

Enumerator:
PENDING 

Message can still make its deadline.

LATE 

Message cannot make its deadline.

BEYOND_LATE 

Message is so late its priority is undefined.

ANY_STATUS 

Mask to match any priority status.

Definition at line 57 of file Dynamic_Message_Strategy.h.

  {
    /// Message can still make its deadline
    PENDING     = 0x01,
    /// Message cannot make its deadline
    LATE        = 0x02,
    /// Message is so late its priority is undefined
    BEYOND_LATE = 0x04,
    /// Mask to match any priority status
    ANY_STATUS  = 0x07
  };


Constructor & Destructor Documentation

ACE_Dynamic_Message_Strategy::ACE_Dynamic_Message_Strategy ( unsigned long  static_bit_field_mask,
unsigned long  static_bit_field_shift,
unsigned long  dynamic_priority_max,
unsigned long  dynamic_priority_offset 
)

Constructor.

ACE_Dynamic_Message_Strategy::~ACE_Dynamic_Message_Strategy ( void   )  [virtual]

Virtual destructor.

Definition at line 36 of file Dynamic_Message_Strategy.cpp.

{
}


Member Function Documentation

virtual void ACE_Dynamic_Message_Strategy::convert_priority ( ACE_Time_Value priority,
const ACE_Message_Block mb 
) [protected, pure virtual]

Hook method for dynamic priority conversion.

Implemented in ACE_Deadline_Message_Strategy, and ACE_Laxity_Message_Strategy.

void ACE_Dynamic_Message_Strategy::dump ( void   )  const [virtual]

Dump the state of the strategy.

Reimplemented in ACE_Deadline_Message_Strategy, and ACE_Laxity_Message_Strategy.

Definition at line 89 of file Dynamic_Message_Strategy.cpp.

{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_Dynamic_Message_Strategy::dump");

  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("static_bit_field_mask_ = %u\n")
              ACE_TEXT ("static_bit_field_shift_ = %u\n")
              ACE_TEXT ("dynamic_priority_max_ = %u\n")
              ACE_TEXT ("dynamic_priority_offset_ = %u\n")
              ACE_TEXT ("max_late_ = [%d sec, %d usec]\n")
              ACE_TEXT ("min_pending_ = [%d sec, %d usec]\n")
              ACE_TEXT ("pending_shift_ = [%d sec, %d usec]\n"),
              this->static_bit_field_mask_,
              this->static_bit_field_shift_,
              this->dynamic_priority_max_,
              this->dynamic_priority_offset_,
              this->max_late_.sec (),
              this->max_late_.usec (),
              this->min_pending_.sec (),
              this->min_pending_.usec (),
              this->pending_shift_.sec (),
              this->pending_shift_.usec ()));

  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_HAS_DUMP */
}

unsigned long ACE_Dynamic_Message_Strategy::dynamic_priority_max ( void   )  const [inline]

Get maximum supported priority value.

Definition at line 36 of file Dynamic_Message_Strategy.inl.

void ACE_Dynamic_Message_Strategy::dynamic_priority_max ( unsigned long  ul  )  [inline]

Set maximum supported priority value.

Definition at line 43 of file Dynamic_Message_Strategy.inl.

{
  // pending_shift_ depends on dynamic_priority_max_: for performance
  // reasons, the value in pending_shift_ is (re)calculated only when
  // dynamic_priority_max_ is initialized or changes, and is stored
  // as a class member rather than being a derived value.
  dynamic_priority_max_ = ul;
  pending_shift_ = ACE_Time_Value (0, ul);
}

void ACE_Dynamic_Message_Strategy::dynamic_priority_offset ( unsigned long  ul  )  [inline]

Set offset to boundary between signed range and unsigned range.

Definition at line 62 of file Dynamic_Message_Strategy.inl.

{
  // max_late_ and min_pending_ depend on dynamic_priority_offset_:
  // for performance reasons, the values in max_late_ and min_pending_
  // are (re)calculated only when dynamic_priority_offset_ is
  // initialized or changes, and are stored as a class member rather
  // than being derived each time one of their values is needed.
  dynamic_priority_offset_ = ul;
  max_late_ = ACE_Time_Value (0, ul - 1);
  min_pending_ = ACE_Time_Value (0, ul);
}

unsigned long ACE_Dynamic_Message_Strategy::dynamic_priority_offset ( void   )  const [inline]

Get offset to boundary between signed range and unsigned range.

Definition at line 55 of file Dynamic_Message_Strategy.inl.

ACE_Dynamic_Message_Strategy::Priority_Status ACE_Dynamic_Message_Strategy::priority_status ( ACE_Message_Block mb,
const ACE_Time_Value tv 
)

Updates the message's priority and returns its priority status.

Definition at line 41 of file Dynamic_Message_Strategy.cpp.

{
  // default the message to have pending priority status
  Priority_Status status = ACE_Dynamic_Message_Strategy::PENDING;

  // start with the passed absolute time as the message's priority, then
  // call the polymorphic hook method to (at least partially) convert
  // the absolute time and message attributes into the message's priority
  ACE_Time_Value priority (tv);
  convert_priority (priority, mb);

  // if the priority is negative, the message is pending
  if (priority < ACE_Time_Value::zero)
    {
      // priority for pending messages must be shifted
      // upward above the late priority range
      priority += pending_shift_;
      if (priority < min_pending_)
        priority = min_pending_;
    }
  // otherwise, if the priority is greater than the maximum late
  // priority value that can be represented, it is beyond late
  else if (priority > max_late_)
    {
      // all messages that are beyond late are assigned lowest priority (zero)
      mb.msg_priority (0);
      return ACE_Dynamic_Message_Strategy::BEYOND_LATE;
    }
  // otherwise, the message is late, but its priority is correct
  else
    status = ACE_Dynamic_Message_Strategy::LATE;

  // use (fast) bitwise operators to isolate and replace
  // the dynamic portion of the message's priority
  mb.msg_priority((mb.msg_priority() & static_bit_field_mask_) |
                  ((priority.usec () +
                    ACE_ONE_SECOND_IN_USECS * (suseconds_t)(priority.sec())) <<
                   static_bit_field_shift_));

  // returns the priority status of the message
  return status;
}

unsigned long ACE_Dynamic_Message_Strategy::static_bit_field_mask ( void   )  const [inline]

Get static bit field mask.

Definition at line 8 of file Dynamic_Message_Strategy.inl.

void ACE_Dynamic_Message_Strategy::static_bit_field_mask ( unsigned long  ul  )  [inline]

Set static bit field mask.

Definition at line 15 of file Dynamic_Message_Strategy.inl.

void ACE_Dynamic_Message_Strategy::static_bit_field_shift ( unsigned long  ul  )  [inline]

Set left shift value to make room for static bit field.

Definition at line 29 of file Dynamic_Message_Strategy.inl.

unsigned long ACE_Dynamic_Message_Strategy::static_bit_field_shift ( void   )  const [inline]

Get left shift value to make room for static bit field.

Definition at line 22 of file Dynamic_Message_Strategy.inl.


Member Data Documentation

Maximum supported priority value.

Definition at line 125 of file Dynamic_Message_Strategy.h.

Offset to boundary between signed range and unsigned range.

Definition at line 128 of file Dynamic_Message_Strategy.h.

Maximum late time value that can be represented.

Definition at line 131 of file Dynamic_Message_Strategy.h.

Minimum pending time value that can be represented.

Definition at line 134 of file Dynamic_Message_Strategy.h.

Time value by which to shift pending priority.

Definition at line 137 of file Dynamic_Message_Strategy.h.

This is a bit mask with all ones in the static bit field.

Definition at line 115 of file Dynamic_Message_Strategy.h.

This is a left shift value to make room for static bit field: this value should be the logarithm base 2 of (static_bit_field_mask_ + 1).

Definition at line 122 of file Dynamic_Message_Strategy.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines