1 #include "ace/Message_Queue.h"
2 #include "ace/Message_Queue_Vx.h"
3 #include "ace/Log_Category.h"
5 #if !defined (__ACE_INLINE__)
6 #include "ace/Message_Queue_Vx.inl"
7 #endif /* __ACE_INLINE__ */
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 #if defined (ACE_VXWORKS)
13 ////////////////////////////////
14 // class ACE_Message_Queue_Vx //
15 ////////////////////////////////
17 ACE_ALLOC_HOOK_DEFINE (ACE_Message_Queue_Vx
);
20 ACE_Message_Queue_Vx::dump () const
22 #if defined (ACE_HAS_DUMP)
23 ACE_TRACE ("ACE_Message_Queue_Vx::dump");
24 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
27 case ACE_Message_Queue_Base::ACTIVATED
:
28 ACELIB_DEBUG ((LM_DEBUG
,
29 ACE_TEXT ("state = ACTIVATED\n")));
31 case ACE_Message_Queue_Base::DEACTIVATED
:
32 ACELIB_DEBUG ((LM_DEBUG
,
33 ACE_TEXT ("state = DEACTIVATED\n")));
35 case ACE_Message_Queue_Base::PULSED
:
36 ACELIB_DEBUG ((LM_DEBUG
,
37 ACE_TEXT ("state = PULSED\n")));
40 ACELIB_DEBUG ((LM_DEBUG
,
41 ACE_TEXT ("low_water_mark = %d\n")
42 ACE_TEXT ("high_water_mark = %d\n")
43 ACE_TEXT ("cur_bytes = %d\n")
44 ACE_TEXT ("cur_length = %d\n")
45 ACE_TEXT ("cur_count = %d\n")
46 ACE_TEXT ("head_ = %u\n")
47 ACE_TEXT ("MSG_Q_ID = %u\n"),
48 this->low_water_mark_
,
49 this->high_water_mark_
,
55 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
56 #endif /* ACE_HAS_DUMP */
59 ACE_Message_Queue_Vx::ACE_Message_Queue_Vx (size_t max_messages
,
60 size_t max_message_length
,
61 ACE_Notification_Strategy
*ns
)
62 : ACE_Message_Queue
<ACE_NULL_SYNCH
> (0, 0, ns
),
63 max_messages_ (static_cast<int> (max_messages
)),
64 max_message_length_ (static_cast<int> (max_message_length
))
66 ACE_TRACE ("ACE_Message_Queue_Vx::ACE_Message_Queue_Vx");
68 if (this->open (max_messages_
, max_message_length_
, ns
) == -1)
69 ACELIB_ERROR ((LM_ERROR
, ACE_TEXT ("open")));
72 ACE_Message_Queue_Vx::~ACE_Message_Queue_Vx ()
74 ACE_TRACE ("ACE_Message_Queue_Vx::~ACE_Message_Queue_Vx");
76 if (this->tail_
!= 0 && this->close () == -1)
77 ACELIB_ERROR ((LM_ERROR
, ACE_TEXT ("close")));
80 // Don't bother locking since if someone calls this function more than
81 // once for the same queue, we're in bigger trouble than just
82 // concurrency control!
85 ACE_Message_Queue_Vx::open (size_t max_messages
,
86 size_t max_message_length
,
87 ACE_Notification_Strategy
*ns
)
89 ACE_TRACE ("ACE_Message_Queue_Vx::open");
90 this->high_water_mark_
= 0;
91 this->low_water_mark_
= 0;
93 this->cur_length_
= 0;
96 this->notification_strategy_
= ns
;
97 this->max_messages_
= static_cast<int> (max_messages
);
98 this->max_message_length_
= static_cast<int> (max_message_length
);
102 // Had already created a msgQ, so delete it.
107 return (this->tail_
=
108 reinterpret_cast<ACE_Message_Block
*> (
109 ::msgQCreate (max_messages_
,
111 MSG_Q_FIFO
))) == 0 ? -1 : 0;
114 // Clean up the queue if we have not already done so!
116 ACE_Message_Queue_Vx::close ()
118 ACE_TRACE ("ACE_Message_Queue_Vx::close");
119 // Don't lock, because we don't have a lock. It shouldn't be
120 // necessary, anyways.
122 this->deactivate_i ();
124 // Don't bother to free up the remaining message on the list,
125 // because we don't have any way to iterate over what's in the
128 return ::msgQDelete (msgq ());
132 ACE_Message_Queue_Vx::is_empty_i ()
134 ACE_TRACE ("ACE_Message_Queue_Vx::is_empty_i");
135 return ::msgQNumMsgs (msgq ()) == 0;
139 ACE_Message_Queue_Vx::is_full_i ()
141 ACE_TRACE ("ACE_Message_Queue_Vx::is_full_i");
142 return ::msgQNumMsgs (msgq ()) >= max_messages_
;
146 ACE_Message_Queue_Vx::high_water_mark ()
148 ACE_TRACE ("ACE_Message_Queue_Vx::high_water_mark");
149 ACE_NOTSUP_RETURN ((size_t) -1);
153 ACE_Message_Queue_Vx::high_water_mark (size_t)
155 ACE_TRACE ("ACE_Message_Queue_Vx::high_water_mark");
160 ACE_Message_Queue_Vx::low_water_mark ()
162 ACE_TRACE ("ACE_Message_Queue_Vx::low_water_mark");
163 // Don't need to guard, because this is fixed.
165 ACE_NOTSUP_RETURN ((size_t) -1);
169 ACE_Message_Queue_Vx::low_water_mark (size_t)
171 ACE_TRACE ("ACE_Message_Queue_Vx::low_water_mark");
176 ACE_Message_Queue_Vx::message_bytes ()
178 ACE_TRACE ("ACE_Message_Queue_Vx::message_bytes");
179 ACE_NOTSUP_RETURN ((size_t) -1);
183 ACE_Message_Queue_Vx::message_length ()
185 ACE_TRACE ("ACE_Message_Queue_Vx::message_length");
186 ACE_NOTSUP_RETURN ((size_t) -1);
190 ACE_Message_Queue_Vx::message_count ()
192 ACE_TRACE ("ACE_Message_Queue_Vx::message_count");
193 // Don't need to guard, because this is a system call.
195 return ::msgQNumMsgs (msgq ());
199 ACE_Message_Queue_Vx::message_bytes (size_t)
201 ACE_TRACE ("ACE_Message_Queue_Vx::message_bytes");
206 ACE_Message_Queue_Vx::message_length (size_t)
208 ACE_TRACE ("ACE_Message_Queue_Vx::message_length");
213 ACE_Message_Queue_Vx::signal_enqueue_waiters ()
220 ACE_Message_Queue_Vx::signal_dequeue_waiters ()
227 ACE_Message_Queue_Vx::enqueue_tail_i (ACE_Message_Block
*new_item
)
229 ACE_TRACE ("ACE_Message_Queue_Vx::enqueue_tail_i");
234 // Don't try to send a composite message!!!! Only the first
235 // block will be sent.
239 // Always use this method to actually send a message on the queue.
240 if (::msgQSend (msgq (),
244 MSG_PRI_NORMAL
) == OK
)
245 return ::msgQNumMsgs (msgq ());
251 ACE_Message_Queue_Vx::enqueue_head_i (ACE_Message_Block
*new_item
)
253 ACE_TRACE ("ACE_Message_Queue_Vx::enqueue_head_i");
255 // Just delegate to enqueue_tail_i.
256 return enqueue_tail_i (new_item
);
260 ACE_Message_Queue_Vx::enqueue_i (ACE_Message_Block
*new_item
)
262 ACE_TRACE ("ACE_Message_Queue_Vx::enqueue_i");
267 if (this->head_
== 0)
268 // Should always take this branch.
269 return this->enqueue_head_i (new_item
);
271 ACE_NOTSUP_RETURN (-1);
275 ACE_Message_Queue_Vx::enqueue_deadline_i (ACE_Message_Block
*new_item
)
277 ACE_TRACE ("ACE_Message_Queue_Vx::enqueue_deadline_i");
279 // Just delegate to enqueue_tail_i.
280 return enqueue_tail_i (new_item
);
283 // Actually get the first ACE_Message_Block (no locking, so must be
284 // called with locks held). This method assumes that the queue has at
285 // least one item in it when it is called.
288 ACE_Message_Queue_Vx::dequeue_head_i (ACE_Message_Block
*&first_item
)
290 ACE_TRACE ("ACE_Message_Queue_Vx::dequeue_head_i");
292 // We don't allocate a new Message_Block: the caller must provide
293 // it, and must ensure that it is big enough (without chaining).
295 if (first_item
== 0 || first_item
->wr_ptr () == 0)
298 if (::msgQReceive (msgq (),
299 first_item
->wr_ptr (),
301 WAIT_FOREVER
) == ERROR
)
304 return ::msgQNumMsgs (msgq ());
308 ACE_Message_Queue_Vx::dequeue_prio_i (ACE_Message_Block
*& /*dequeued*/)
310 ACE_TRACE ("ACE_Message_Queue_Vx::dequeue_prio_i");
311 ACE_NOTSUP_RETURN (-1);
315 ACE_Message_Queue_Vx::dequeue_tail_i (ACE_Message_Block
*& /*dequeued*/)
317 ACE_TRACE ("ACE_Message_Queue_Vx::dequeue_tail_i");
318 ACE_NOTSUP_RETURN (-1);
322 ACE_Message_Queue_Vx::dequeue_deadline_i (ACE_Message_Block
*& /*dequeued*/)
324 ACE_TRACE ("ACE_Message_Queue_Vx::dequeue_deadline_i");
325 ACE_NOTSUP_RETURN (-1);
328 // Take a look at the first item without removing it.
331 ACE_Message_Queue_Vx::wait_not_full_cond (ACE_Time_Value
*)
333 // Always return here, and let the VxWorks message queue handle blocking.
338 ACE_Message_Queue_Vx::wait_not_empty_cond (ACE_Time_Value
*)
340 // Always return here, and let the VxWorks message queue handle blocking.
344 #endif /* ACE_VXWORKS */
346 ACE_END_VERSIONED_NAMESPACE_DECL