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

Free_List.cpp

Go to the documentation of this file.
00001 // $Id: Free_List.cpp,v 1.1.1.2 2001/12/04 14:33:01 chad Exp $
00002 
00003 #ifndef ACE_FREE_LIST_C
00004 #define ACE_FREE_LIST_C
00005 
00006 #include "ace/Free_List.h"
00007 
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif /* ACE_LACKS_PRAGMA_ONCE */
00011 
00012 #if !defined (__ACE_INLINE__)
00013 #include "ace/Free_List.i"
00014 #endif /* __ACE_INLINE__ */
00015 
00016 ACE_RCSID(ace, Free_List, "$Id: Free_List.cpp,v 1.1.1.2 2001/12/04 14:33:01 chad Exp $")
00017 
00018 // Empty constructor
00019 
00020 template <class T>
00021 ACE_Free_List<T>::~ACE_Free_List (void)
00022 {
00023   // Nothing
00024 }
00025 
00026 // Default constructor that takes in a preallocation number
00027 // (<prealloc>), a low and high water mark (<lwm> and <hwm>) and an
00028 // increment value (<inc>)
00029 
00030 template <class T, class ACE_LOCK>
00031 ACE_Locked_Free_List<T, ACE_LOCK>::ACE_Locked_Free_List (int mode,
00032                                                      size_t prealloc,
00033                                                      size_t lwm,
00034                                                      size_t hwm,
00035                                                      size_t inc)
00036   : mode_ (mode),
00037     free_list_ (0),
00038     lwm_ (lwm),
00039     hwm_ (hwm),
00040     inc_ (inc),
00041     size_ (0)
00042 {
00043   this->alloc (prealloc);
00044 }
00045 
00046 // Destructor - removes all the elements from the free_list
00047 
00048 template <class T, class ACE_LOCK>
00049 ACE_Locked_Free_List<T, ACE_LOCK>::~ACE_Locked_Free_List (void)
00050 {
00051   if (this->mode_ != ACE_PURE_FREE_LIST)
00052     while (this->free_list_ != 0)
00053       {
00054         T *temp = this->free_list_;
00055         this->free_list_ = this->free_list_->get_next ();
00056         delete temp;
00057       }
00058 }
00059 
00060 // Allocates <n> extra nodes for the freelist
00061 
00062 template <class T, class ACE_LOCK> void
00063 ACE_Locked_Free_List<T, ACE_LOCK>::alloc (size_t n)
00064 {
00065   for (; n > 0; n--)
00066     {
00067       T *temp = 0;
00068       ACE_NEW (temp, T);
00069       temp->set_next (this->free_list_);
00070       this->free_list_ = temp;
00071       this->size_++;
00072     }
00073 }
00074 
00075 // Removes and frees <n> nodes from the freelist.
00076 
00077 template <class T, class ACE_LOCK> void
00078 ACE_Locked_Free_List<T, ACE_LOCK>::dealloc (size_t n)
00079 {
00080   for (; this->free_list_ != 0 && n > 0;
00081        n--)
00082     {
00083       T *temp = this->free_list_;
00084       this->free_list_ = this->free_list_->get_next ();
00085       delete temp;
00086       this->size_--;
00087     }
00088 }
00089 
00090 #endif /* ACE_FREE_LIST_C */

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