#include <Free_List.h>
Inheritance diagram for ACE_Locked_Free_List:


Public Methods | |
| ACE_Locked_Free_List (int mode=ACE_FREE_LIST_WITH_POOL, size_t prealloc=ACE_DEFAULT_FREE_LIST_PREALLOC, size_t lwm=ACE_DEFAULT_FREE_LIST_LWM, size_t hwm=ACE_DEFAULT_FREE_LIST_HWM, size_t inc=ACE_DEFAULT_FREE_LIST_INC) | |
| virtual | ~ACE_Locked_Free_List (void) |
| Destructor - removes all the elements from the free_list. More... | |
| virtual void | add (T *element) |
| Inserts an element onto the free list (if it isn't past the high water mark). More... | |
| virtual T * | remove (void) |
| Takes a element off the freelist and returns it. It creates <inc> new elements if the size is at or below the low water mark. More... | |
| virtual size_t | size (void) |
| Returns the current size of the free list. More... | |
| virtual void | resize (size_t newsize) |
| Resizes the free list to <newsize>. More... | |
Protected Methods | |
| virtual void | alloc (size_t n) |
| Allocates <n> extra nodes for the freelist. More... | |
| virtual void | dealloc (size_t n) |
| Removes and frees <n> nodes from the freelist. More... | |
Protected Attributes | |
| int | mode_ |
| Free list operation mode, either ACE_FREE_LIST_WITH_POOL or ACE_PURE_FREE_LIST. More... | |
| T * | free_list_ |
| Pointer to the first node in the freelist. More... | |
| size_t | lwm_ |
| Low water mark. More... | |
| size_t | hwm_ |
| High water mark. More... | |
| size_t | inc_ |
| Increment value. More... | |
| size_t | size_ |
| Keeps track of the size of the list. More... | |
| ACE_LOCK | mutex_ |
| Synchronization variable for <ACE_Timer_Queue>. More... | |
Private Methods | |
| ACE_Locked_Free_List (const ACE_Locked_Free_List< T, ACE_LOCK > &) | |
| void | operator= (const ACE_Locked_Free_List< T, ACE_LOCK > &) |
This class maintains a free list of nodes of type T. It depends on the type T having a <get_next> and <set_next> method. It maintains a mutex so the freelist can be used in a multithreaded program .
Definition at line 65 of file Free_List.h.
|
||||||||||||||||||||||||||||
|
Constructor takes a <mode> (i.e., ACE_FREE_LIST_WITH_POOL or ACE_PURE_FREE_LIST), a count of the number of nodes to <prealloc>, a low and high water mark (<lwm> and <hwm>) that indicate when to allocate more nodes, an increment value (<inc>) that indicates how many nodes to allocate when the list must grow. Definition at line 31 of file Free_List.cpp. References alloc.
|
|
||||||||||
|
Destructor - removes all the elements from the free_list.
Definition at line 49 of file Free_List.cpp. References ACE_PURE_FREE_LIST, free_list_, and mode_.
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 }
|
|
||||||||||
|
|
|
||||||||||
|
Inserts an element onto the free list (if it isn't past the high water mark).
Implements ACE_Free_List. Definition at line 10 of file Free_List.i. References ACE_GUARD, ACE_MT, ACE_PURE_FREE_LIST, free_list_, hwm_, mode_, and size_.
00011 {
00012 ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00013
00014 // Check to see that we not at the high water mark.
00015 if (this->mode_ == ACE_PURE_FREE_LIST
00016 || this->size_ < this->hwm_)
00017 {
00018 element->set_next (this->free_list_);
00019 this->free_list_ = element;
00020 this->size_++;
00021 }
00022 else
00023 delete element;
00024 }
|
|
||||||||||
|
Allocates <n> extra nodes for the freelist.
Definition at line 63 of file Free_List.cpp. References ACE_NEW, free_list_, and size_. Referenced by ACE_Locked_Free_List, remove, and resize.
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 }
|
|
||||||||||
|
Removes and frees <n> nodes from the freelist.
Definition at line 78 of file Free_List.cpp. References free_list_, and size_. Referenced by resize.
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 }
|
|
||||||||||
|
|
|
||||||||||
|
Takes a element off the freelist and returns it. It creates <inc> new elements if the size is at or below the low water mark.
Implements ACE_Free_List. Definition at line 31 of file Free_List.i. References ACE_GUARD_RETURN, ACE_MT, ACE_PURE_FREE_LIST, alloc, free_list_, lwm_, mode_, and size_.
00032 {
00033 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, 0));
00034
00035 // If we are at the low water mark, add some nodes
00036 if (this->mode_ != ACE_PURE_FREE_LIST && this->size_ <= this->lwm_)
00037 this->alloc (this->inc_);
00038
00039 // Remove a node
00040 T *temp = this->free_list_;
00041
00042 if (temp != 0)
00043 {
00044 this->free_list_ = this->free_list_->get_next ();
00045 this->size_--;
00046 }
00047
00048 return temp;
00049 }
|
|
||||||||||
|
Resizes the free list to <newsize>.
Implements ACE_Free_List. Definition at line 63 of file Free_List.i. References ACE_GUARD, ACE_MT, ACE_PURE_FREE_LIST, alloc, dealloc, mode_, and size_.
00064 {
00065 ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00066
00067 // Check if we are allowed to resize
00068 if (this->mode_ != ACE_PURE_FREE_LIST)
00069 // Check to see if we grow or shrink
00070 if (newsize < this->size_)
00071 this->dealloc (this->size_ - newsize);
00072 else
00073 this->alloc (newsize - this->size_);
00074 }
|
|
||||||||||
|
Returns the current size of the free list.
Implements ACE_Free_List. Definition at line 55 of file Free_List.i. References size_.
00056 {
00057 return this->size_;
00058 }
|
|
|||||
|
Pointer to the first node in the freelist.
Definition at line 112 of file Free_List.h. Referenced by add, alloc, dealloc, remove, and ~ACE_Locked_Free_List. |
|
|||||
|
High water mark.
Definition at line 118 of file Free_List.h. Referenced by add. |
|
|||||
|
Increment value.
Definition at line 121 of file Free_List.h. |
|
|||||
|
Low water mark.
Definition at line 115 of file Free_List.h. Referenced by remove. |
|
|||||
|
Free list operation mode, either ACE_FREE_LIST_WITH_POOL or ACE_PURE_FREE_LIST.
Definition at line 109 of file Free_List.h. Referenced by add, remove, resize, and ~ACE_Locked_Free_List. |
|
|||||
|
Synchronization variable for <ACE_Timer_Queue>.
Definition at line 127 of file Free_List.h. |
|
|||||
|
Keeps track of the size of the list.
Definition at line 124 of file Free_List.h. Referenced by add, alloc, dealloc, remove, resize, and size. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002