3 //=============================================================================
7 * @author Darrell Brunsch (brunsch@cs.wustl.edu)
9 //=============================================================================
11 #ifndef ACE_FREE_LIST_H
12 #define ACE_FREE_LIST_H
13 #include /**/ "ace/pre.h"
15 #include /**/ "ace/config-all.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/Global_Macros.h"
22 #include "ace/Default_Constants.h"
23 #include "ace/os_include/os_stddef.h"
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
28 * @class ACE_Free_List
30 * @brief Implements a free list.
32 * This class maintains a free list of nodes of type T.
38 /// Destructor - removes all the elements from the free_list.
39 virtual ~ACE_Free_List () = default;
41 /// Inserts an element onto the free list (if it isn't past the high
43 virtual void add (T
*element
) = 0;
45 /// Takes a element off the freelist and returns it. It creates
46 /// <inc> new elements if the size is at or below the low water mark.
47 virtual T
*remove () = 0;
49 /// Returns the current size of the free list.
50 virtual size_t size () = 0;
52 /// Resizes the free list to @a newsize.
53 virtual void resize (size_t newsize
) = 0;
57 * @class ACE_Locked_Free_List
59 * @brief Implements a free list.
61 * This class maintains a free list of nodes of type T. It
62 * depends on the type T having a get_next() and set_next()
63 * method. It maintains a mutex so the freelist can be used in
64 * a multithreaded program .
66 template <class T
, class ACE_LOCK
>
67 class ACE_Locked_Free_List
: public ACE_Free_List
<T
>
71 * Constructor takes a @a mode (i.e., ACE_FREE_LIST_WITH_POOL or
72 * ACE_PURE_FREE_LIST), a count of the number of nodes to
73 * @a prealloc, a low and high water mark (@a lwm and @a hwm) that
74 * indicate when to allocate more nodes, an increment value (@a inc)
75 * that indicates how many nodes to allocate when the list must
78 ACE_Locked_Free_List (int mode
= ACE_FREE_LIST_WITH_POOL
,
79 size_t prealloc
= ACE_DEFAULT_FREE_LIST_PREALLOC
,
80 size_t lwm
= ACE_DEFAULT_FREE_LIST_LWM
,
81 size_t hwm
= ACE_DEFAULT_FREE_LIST_HWM
,
82 size_t inc
= ACE_DEFAULT_FREE_LIST_INC
);
84 /// Destructor - removes all the elements from the free_list.
85 virtual ~ACE_Locked_Free_List ();
87 /// Inserts an element onto the free list (if it isn't past the high
89 virtual void add (T
*element
);
91 /// Takes a element off the freelist and returns it. It creates
92 /// <inc> new elements if the size is at or below the low water mark.
95 /// Returns the current size of the free list.
96 virtual size_t size ();
98 /// Resizes the free list to @a newsize.
99 virtual void resize (size_t newsize
);
101 ACE_ALLOC_HOOK_DECLARE
;
104 /// Allocates @a n extra nodes for the freelist.
105 virtual void alloc (size_t n
);
107 /// Removes and frees @a n nodes from the freelist.
108 virtual void dealloc (size_t n
);
110 /// Free list operation mode, either ACE_FREE_LIST_WITH_POOL or
111 /// ACE_PURE_FREE_LIST.
114 /// Pointer to the first node in the freelist.
126 /// Keeps track of the size of the list.
129 /// Synchronization variable for ACE_Timer_Queue.
133 // = Don't allow these operations for now.
134 ACE_Locked_Free_List (const ACE_Locked_Free_List
<T
, ACE_LOCK
> &) = delete;
135 void operator= (const ACE_Locked_Free_List
<T
, ACE_LOCK
> &) = delete;
138 ACE_END_VERSIONED_NAMESPACE_DECL
140 #include "ace/Free_List.cpp"
142 #include /**/ "ace/post.h"
143 #endif /* ACE_FREE_LIST_H */