Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Dynamic_Message_Strategy.cpp
blob5bad52c38b28501c6ce60a53e6063983d9860920
1 #include "ace/Dynamic_Message_Strategy.h"
3 #if !defined (__ACE_INLINE__)
4 #include "ace/Dynamic_Message_Strategy.inl"
5 #endif /* __ACE_INLINE__ */
7 #include "ace/Guard_T.h"
8 #include "ace/Log_Category.h"
9 #include "ace/Malloc_Base.h"
10 #include "ace/OS_NS_string.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 // ctor
15 ACE_Dynamic_Message_Strategy::ACE_Dynamic_Message_Strategy (unsigned long static_bit_field_mask,
16 unsigned long static_bit_field_shift,
17 unsigned long dynamic_priority_max,
18 unsigned long dynamic_priority_offset)
19 : static_bit_field_mask_ (static_bit_field_mask),
20 static_bit_field_shift_ (static_bit_field_shift),
21 dynamic_priority_max_ (dynamic_priority_max),
22 dynamic_priority_offset_ (dynamic_priority_offset),
23 max_late_ (0, dynamic_priority_offset - 1),
24 min_pending_ (0, dynamic_priority_offset),
25 pending_shift_ (0, dynamic_priority_max)
29 // dtor
31 ACE_Dynamic_Message_Strategy::~ACE_Dynamic_Message_Strategy ()
35 ACE_Dynamic_Message_Strategy::Priority_Status
36 ACE_Dynamic_Message_Strategy::priority_status (ACE_Message_Block & mb,
37 const ACE_Time_Value & tv)
39 // default the message to have pending priority status
40 Priority_Status status = ACE_Dynamic_Message_Strategy::PENDING;
42 // start with the passed absolute time as the message's priority, then
43 // call the polymorphic hook method to (at least partially) convert
44 // the absolute time and message attributes into the message's priority
45 ACE_Time_Value priority (tv);
46 convert_priority (priority, mb);
48 // if the priority is negative, the message is pending
49 if (priority < ACE_Time_Value::zero)
51 // priority for pending messages must be shifted
52 // upward above the late priority range
53 priority += pending_shift_;
54 if (priority < min_pending_)
55 priority = min_pending_;
57 // otherwise, if the priority is greater than the maximum late
58 // priority value that can be represented, it is beyond late
59 else if (priority > max_late_)
61 // all messages that are beyond late are assigned lowest priority (zero)
62 mb.msg_priority (0);
63 return ACE_Dynamic_Message_Strategy::BEYOND_LATE;
65 // otherwise, the message is late, but its priority is correct
66 else
67 status = ACE_Dynamic_Message_Strategy::LATE;
69 // use (fast) bitwise operators to isolate and replace
70 // the dynamic portion of the message's priority
71 mb.msg_priority((mb.msg_priority() & static_bit_field_mask_) |
72 ((priority.usec () +
73 ACE_ONE_SECOND_IN_USECS * (suseconds_t)(priority.sec())) <<
74 static_bit_field_shift_));
76 // returns the priority status of the message
77 return status;
81 // Dump the state of the strategy.
83 void
84 ACE_Dynamic_Message_Strategy::dump () const
86 #if defined (ACE_HAS_DUMP)
87 ACE_TRACE ("ACE_Dynamic_Message_Strategy::dump");
89 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
91 ACELIB_DEBUG ((LM_DEBUG,
92 ACE_TEXT ("static_bit_field_mask_ = %u\n")
93 ACE_TEXT ("static_bit_field_shift_ = %u\n")
94 ACE_TEXT ("dynamic_priority_max_ = %u\n")
95 ACE_TEXT ("dynamic_priority_offset_ = %u\n")
96 ACE_TEXT ("max_late_ = [%d sec, %d usec]\n")
97 ACE_TEXT ("min_pending_ = [%d sec, %d usec]\n")
98 ACE_TEXT ("pending_shift_ = [%d sec, %d usec]\n"),
99 this->static_bit_field_mask_,
100 this->static_bit_field_shift_,
101 this->dynamic_priority_max_,
102 this->dynamic_priority_offset_,
103 this->max_late_.sec (),
104 this->max_late_.usec (),
105 this->min_pending_.sec (),
106 this->min_pending_.usec (),
107 this->pending_shift_.sec (),
108 this->pending_shift_.usec ()));
110 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
111 #endif /* ACE_HAS_DUMP */
114 ACE_Deadline_Message_Strategy::ACE_Deadline_Message_Strategy (unsigned long static_bit_field_mask,
115 unsigned long static_bit_field_shift,
116 unsigned long dynamic_priority_max,
117 unsigned long dynamic_priority_offset)
118 : ACE_Dynamic_Message_Strategy (static_bit_field_mask,
119 static_bit_field_shift,
120 dynamic_priority_max,
121 dynamic_priority_offset)
125 ACE_Deadline_Message_Strategy::~ACE_Deadline_Message_Strategy ()
129 void
130 ACE_Deadline_Message_Strategy::convert_priority (ACE_Time_Value & priority,
131 const ACE_Message_Block & mb)
133 // Convert absolute time passed in tv to negative time
134 // to deadline of mb with respect to that absolute time.
135 priority -= mb.msg_deadline_time ();
137 // dynamic priority conversion function based on time to deadline
139 void
140 ACE_Deadline_Message_Strategy::dump () const
142 #if defined (ACE_HAS_DUMP)
143 ACE_TRACE ("ACE_Deadline_Message_Strategy::dump");
145 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
147 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_Dynamic_Message_Strategy base class:\n")));
148 this->ACE_Dynamic_Message_Strategy::dump ();
150 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nderived class: ACE_Deadline_Message_Strategy\n")));
152 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
153 #endif /* ACE_HAS_DUMP */
156 ACE_Laxity_Message_Strategy::ACE_Laxity_Message_Strategy (unsigned long static_bit_field_mask,
157 unsigned long static_bit_field_shift,
158 unsigned long dynamic_priority_max,
159 unsigned long dynamic_priority_offset)
160 : ACE_Dynamic_Message_Strategy (static_bit_field_mask,
161 static_bit_field_shift,
162 dynamic_priority_max,
163 dynamic_priority_offset)
167 ACE_Laxity_Message_Strategy::~ACE_Laxity_Message_Strategy ()
171 void
172 ACE_Laxity_Message_Strategy::convert_priority (ACE_Time_Value & priority,
173 const ACE_Message_Block & mb)
175 // Convert absolute time passed in tv to negative
176 // laxity of mb with respect to that absolute time.
177 priority += mb.msg_execution_time ();
178 priority -= mb.msg_deadline_time ();
180 // dynamic priority conversion function based on laxity
182 void
183 ACE_Laxity_Message_Strategy::dump () const
185 #if defined (ACE_HAS_DUMP)
186 ACE_TRACE ("ACE_Laxity_Message_Strategy::dump");
188 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
190 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_Dynamic_Message_Strategy base class:\n")));
191 this->ACE_Dynamic_Message_Strategy::dump ();
193 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nderived class: ACE_Laxity_Message_Strategy\n")));
195 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
196 #endif /* ACE_HAS_DUMP */
198 // Dump the state of the strategy.
200 ACE_END_VERSIONED_NAMESPACE_DECL