Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Incoming_Message_Queue.cpp
blob5622b3875719b19699434f3fe3ffabc7552ab667
1 #include "tao/Incoming_Message_Queue.h"
2 #include "tao/Queued_Data.h"
3 #include "tao/debug.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/Malloc_Base.h"
8 #if !defined (__ACE_INLINE__)
9 # include "tao/Incoming_Message_Queue.inl"
10 #endif /* __ACE_INLINE__ */
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 TAO_Incoming_Message_Queue::~TAO_Incoming_Message_Queue ()
16 CORBA::ULong const sz = this->size_;
18 // Delete all the nodes left behind
19 for (CORBA::ULong i = 0;
20 i < sz;
21 ++i)
23 TAO_Queued_Data *qd = this->dequeue_head ();
24 TAO_Queued_Data::release (qd);
29 TAO_Queued_Data *
30 TAO_Incoming_Message_Queue::dequeue_head ()
32 if (this->size_ == 0)
33 return nullptr;
35 // Get the node on the head of the queue...
36 TAO_Queued_Data * const head = this->last_added_->next ();
38 // Reset the head node..
39 this->last_added_->next (head->next ());
41 // Decrease the size and reset last_added_ if empty
42 if (--this->size_ == 0)
43 this->last_added_ = nullptr;
45 return head;
48 TAO_Queued_Data *
49 TAO_Incoming_Message_Queue::dequeue_tail ()
51 // This is a bit painful stuff...
52 if (this->size_ == 0)
53 return nullptr;
55 // Get the node on the head of the queue...
56 TAO_Queued_Data *head = this->last_added_->next ();
58 while (head->next () != this->last_added_)
60 head = head->next ();
63 // Put the head in tmp.
64 head->next (this->last_added_->next ());
66 TAO_Queued_Data *ret_qd = this->last_added_;
68 this->last_added_ = head;
70 // Decrease the size
71 if (--this->size_ == 0)
72 this->last_added_ = nullptr;
74 return ret_qd;
77 int
78 TAO_Incoming_Message_Queue::enqueue_tail (TAO_Queued_Data *nd)
80 if (this->size_ == 0)
82 this->last_added_ = nd;
83 this->last_added_->next (this->last_added_);
85 else
87 nd->next (this->last_added_->next ());
88 this->last_added_->next (nd);
89 this->last_added_ = nd;
92 ++this->size_;
93 return 0;
96 TAO_END_VERSIONED_NAMESPACE_DECL