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

Free_List.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Free_List.h
00006  *
00007  *  $Id: Free_List.h,v 1.1.1.3 2001/12/04 14:33:01 chad Exp $
00008  *
00009  *  @author Darrell Brunsch (brunsch@cs.wustl.edu)
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_FREE_LIST_H
00014 #define ACE_FREE_LIST_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/OS.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/Synch_T.h"
00024 
00025 /**
00026  * @class ACE_Free_List
00027  *
00028  * @brief Implements a free list.
00029  *
00030  * This class maintains a free list of nodes of type T.
00031  */
00032 template <class T>
00033 class ACE_Free_List
00034 {
00035 public:
00036   /// Destructor - removes all the elements from the free_list.
00037   virtual ~ACE_Free_List (void);
00038 
00039   /// Inserts an element onto the free list (if it isn't past the high
00040   /// water mark).
00041   virtual void add (T *element) = 0;
00042 
00043   /// Takes a element off the freelist and returns it.  It creates
00044   /// <inc> new elements if the size is at or below the low water mark.
00045   virtual T *remove (void) = 0;
00046 
00047   /// Returns the current size of the free list.
00048   virtual size_t size (void) = 0;
00049 
00050   /// Resizes the free list to <newsize>.
00051   virtual void resize (size_t newsize) = 0;
00052 };
00053 
00054 /**
00055  * @class ACE_Locked_Free_List
00056  *
00057  * @brief Implements a free list.
00058  *
00059  * This class maintains a free list of nodes of type T.  It
00060  * depends on the type T having a <get_next> and <set_next>
00061  * method.  It maintains a mutex so the freelist can be used in
00062  * a multithreaded program .
00063  */
00064 template <class T, class ACE_LOCK>
00065 class ACE_Locked_Free_List : public ACE_Free_List<T>
00066 {
00067 public:
00068   // = Initialization and termination.
00069   /**
00070    * Constructor takes a <mode> (i.e., ACE_FREE_LIST_WITH_POOL or
00071    * ACE_PURE_FREE_LIST), a count of the number of nodes to
00072    * <prealloc>, a low and high water mark (<lwm> and <hwm>) that
00073    * indicate when to allocate more nodes, an increment value (<inc>)
00074    * that indicates how many nodes to allocate when the list must
00075    * grow.
00076    */
00077   ACE_Locked_Free_List (int mode = ACE_FREE_LIST_WITH_POOL,
00078                         size_t prealloc = ACE_DEFAULT_FREE_LIST_PREALLOC,
00079                         size_t lwm = ACE_DEFAULT_FREE_LIST_LWM,
00080                         size_t hwm = ACE_DEFAULT_FREE_LIST_HWM,
00081                         size_t inc = ACE_DEFAULT_FREE_LIST_INC);
00082 
00083   /// Destructor - removes all the elements from the free_list.
00084   virtual ~ACE_Locked_Free_List (void);
00085 
00086   /// Inserts an element onto the free list (if it isn't past the high
00087   /// water mark).
00088   virtual void add (T *element);
00089 
00090   /// Takes a element off the freelist and returns it.  It creates
00091   /// <inc> new elements if the size is at or below the low water mark.
00092   virtual T *remove (void);
00093 
00094   /// Returns the current size of the free list.
00095   virtual size_t size (void);
00096 
00097   /// Resizes the free list to <newsize>.
00098   virtual void resize (size_t newsize);
00099 
00100 protected:
00101   /// Allocates <n> extra nodes for the freelist.
00102   virtual void alloc (size_t n);
00103 
00104   /// Removes and frees <n> nodes from the freelist.
00105   virtual void dealloc (size_t n);
00106 
00107   /// Free list operation mode, either ACE_FREE_LIST_WITH_POOL or
00108   /// ACE_PURE_FREE_LIST.
00109   int mode_;
00110 
00111   /// Pointer to the first node in the freelist.
00112   T *free_list_;
00113 
00114   /// Low water mark.
00115   size_t lwm_;
00116 
00117   /// High water mark.
00118   size_t hwm_;
00119 
00120   /// Increment value.
00121   size_t inc_;
00122 
00123   /// Keeps track of the size of the list.
00124   size_t size_;
00125 
00126   /// Synchronization variable for <ACE_Timer_Queue>.
00127   ACE_LOCK mutex_;
00128 
00129 private:
00130   // = Don't allow these operations for now.
00131   ACE_UNIMPLEMENTED_FUNC (ACE_Locked_Free_List (const ACE_Locked_Free_List<T, ACE_LOCK> &))
00132   ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Locked_Free_List<T, ACE_LOCK> &))
00133 };
00134 
00135 #if defined (__ACE_INLINE__)
00136 #include "ace/Free_List.i"
00137 #endif /* __ACE_INLINE__ */
00138 
00139 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00140 #include "ace/Free_List.cpp"
00141 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00142 
00143 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00144 #pragma implementation ("Free_List.cpp")
00145 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00146 
00147 #include "ace/post.h"
00148 #endif /* ACE_FREE_LIST_H */

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