Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Free_List.i

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // $Id: Free_List.i,v 1.1.1.2 2001/12/04 14:33:01 chad Exp $
00003 
00004 
00005 // Inserts an element onto the free list (if we are allowed to manage
00006 // elements withing and it pasts the high water mark, delete the
00007 // element)
00008 
00009 template <class T, class ACE_LOCK> ACE_INLINE void 
00010 ACE_Locked_Free_List<T, ACE_LOCK>::add (T *element)
00011 {
00012   ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00013 
00014   // Check to see that we not at the high water mark.
00015   if (this->mode_ == ACE_PURE_FREE_LIST 
00016       || this->size_ < this->hwm_)
00017     {
00018       element->set_next (this->free_list_);
00019       this->free_list_ = element;
00020       this->size_++;
00021     }
00022   else
00023     delete element;
00024 }
00025 
00026 // Takes a element off the freelist and returns it.  It creates <inc>
00027 // new elements if we are allowed to do it and the size is at the low
00028 // water mark.
00029 
00030 template <class T, class ACE_LOCK> ACE_INLINE T *
00031 ACE_Locked_Free_List<T, ACE_LOCK>::remove (void)
00032 {
00033   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, 0));
00034 
00035   // If we are at the low water mark, add some nodes
00036   if (this->mode_ != ACE_PURE_FREE_LIST && this->size_ <= this->lwm_)
00037     this->alloc (this->inc_);
00038 
00039   // Remove a node
00040   T *temp = this->free_list_;
00041 
00042   if (temp != 0)
00043     {
00044       this->free_list_ = this->free_list_->get_next ();
00045       this->size_--;
00046     }
00047 
00048   return temp;
00049 }
00050 
00051 
00052 // Returns the current size of the free list
00053 
00054 template <class T, class ACE_LOCK> ACE_INLINE size_t 
00055 ACE_Locked_Free_List<T, ACE_LOCK>::size (void)
00056 {
00057   return this->size_;
00058 }
00059 
00060 // Resizes the free list to <newsize>
00061 
00062 template <class T, class ACE_LOCK> ACE_INLINE void 
00063 ACE_Locked_Free_List<T, ACE_LOCK>::resize (size_t newsize)
00064 {
00065   ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00066 
00067   // Check if we are allowed to resize
00068   if (this->mode_ != ACE_PURE_FREE_LIST)
00069     // Check to see if we grow or shrink
00070     if (newsize < this->size_)
00071       this->dealloc (this->size_ - newsize);
00072     else 
00073       this->alloc (newsize - this->size_);
00074 }
00075 
00076 

Generated on Mon Jun 16 11:19:43 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002