Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / Free_List.h
bloba6252fe85edb051cb39ff76a392ceb05d36c52a8
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Free_List.h
7 * @author Darrell Brunsch (brunsch@cs.wustl.edu)
8 */
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)
18 # 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
27 /**
28 * @class ACE_Free_List
30 * @brief Implements a free list.
32 * This class maintains a free list of nodes of type T.
34 template <class T>
35 class ACE_Free_List
37 public:
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
42 /// water mark).
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;
56 /**
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>
69 public:
70 /**
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
76 * grow.
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
88 /// water mark).
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.
93 virtual T *remove ();
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;
103 protected:
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.
112 int mode_;
114 /// Pointer to the first node in the freelist.
115 T *free_list_;
117 /// Low water mark.
118 size_t lwm_;
120 /// High water mark.
121 size_t hwm_;
123 /// Increment value.
124 size_t inc_;
126 /// Keeps track of the size of the list.
127 size_t size_;
129 /// Synchronization variable for ACE_Timer_Queue.
130 ACE_LOCK mutex_;
132 private:
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 */