00001 #include "tao/Incoming_Message_Queue.h" 00002 #include "tao/Queued_Data.h" 00003 #include "tao/debug.h" 00004 00005 #include "ace/Log_Msg.h" 00006 #include "ace/Malloc_Base.h" 00007 00008 #if !defined (__ACE_INLINE__) 00009 # include "tao/Incoming_Message_Queue.inl" 00010 #endif /* __ACE_INLINE__ */ 00011 00012 ACE_RCSID (tao, 00013 Incoming_Message_Queue, 00014 "$Id: Incoming_Message_Queue.cpp 82031 2008-06-18 10:13:25Z johnnyw $") 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 TAO_Incoming_Message_Queue::~TAO_Incoming_Message_Queue (void) 00019 { 00020 CORBA::ULong const sz = this->size_; 00021 00022 // Delete all the nodes left behind 00023 for (CORBA::ULong i = 0; 00024 i < sz; 00025 ++i) 00026 { 00027 TAO_Queued_Data *qd = this->dequeue_head (); 00028 TAO_Queued_Data::release (qd); 00029 } 00030 } 00031 00032 00033 TAO_Queued_Data * 00034 TAO_Incoming_Message_Queue::dequeue_head (void) 00035 { 00036 if (this->size_ == 0) 00037 return 0; 00038 00039 // Get the node on the head of the queue... 00040 TAO_Queued_Data * const head = this->last_added_->next (); 00041 00042 // Reset the head node.. 00043 this->last_added_->next (head->next ()); 00044 00045 // Decrease the size and reset last_added_ if empty 00046 if (--this->size_ == 0) 00047 this->last_added_ = 0; 00048 00049 return head; 00050 } 00051 00052 TAO_Queued_Data * 00053 TAO_Incoming_Message_Queue::dequeue_tail (void) 00054 { 00055 // This is a bit painful stuff... 00056 if (this->size_ == 0) 00057 return 0; 00058 00059 // Get the node on the head of the queue... 00060 TAO_Queued_Data *head = this->last_added_->next (); 00061 00062 while (head->next () != this->last_added_) 00063 { 00064 head = head->next (); 00065 } 00066 00067 // Put the head in tmp. 00068 head->next (this->last_added_->next ()); 00069 00070 TAO_Queued_Data *ret_qd = this->last_added_; 00071 00072 this->last_added_ = head; 00073 00074 // Decrease the size 00075 if (--this->size_ == 0) 00076 this->last_added_ = 0; 00077 00078 return ret_qd; 00079 } 00080 00081 int 00082 TAO_Incoming_Message_Queue::enqueue_tail (TAO_Queued_Data *nd) 00083 { 00084 if (this->size_ == 0) 00085 { 00086 this->last_added_ = nd; 00087 this->last_added_->next (this->last_added_); 00088 } 00089 else 00090 { 00091 nd->next (this->last_added_->next ()); 00092 this->last_added_->next (nd); 00093 this->last_added_ = nd; 00094 } 00095 00096 ++this->size_; 00097 return 0; 00098 } 00099 00100 TAO_END_VERSIONED_NAMESPACE_DECL