Free_List.h

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

Generated on Thu Nov 9 09:41:51 2006 for ACE by doxygen 1.3.6