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 79011 2007-07-24 10:38:59Z johnnyw $") 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 TAO_Incoming_Message_Queue::~TAO_Incoming_Message_Queue (void) 00019 { 00020 const CORBA::ULong 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 = 00061 this->last_added_->next (); 00062 00063 while (head->next () != this->last_added_) 00064 { 00065 head = head->next (); 00066 } 00067 00068 // Put the head in tmp. 00069 head->next (this->last_added_->next ()); 00070 00071 TAO_Queued_Data *ret_qd = this->last_added_; 00072 00073 this->last_added_ = head; 00074 00075 // Decrease the size 00076 if (--this->size_ == 0) 00077 this->last_added_ = 0; 00078 00079 return ret_qd; 00080 } 00081 00082 int 00083 TAO_Incoming_Message_Queue::enqueue_tail (TAO_Queued_Data *nd) 00084 { 00085 if (this->size_ == 0) 00086 { 00087 this->last_added_ = nd; 00088 this->last_added_->next (this->last_added_); 00089 } 00090 else 00091 { 00092 nd->next (this->last_added_->next ()); 00093 this->last_added_->next (nd); 00094 this->last_added_ = nd; 00095 } 00096 00097 ++this->size_; 00098 return 0; 00099 } 00100 00101 TAO_END_VERSIONED_NAMESPACE_DECL