summaryrefslogtreecommitdiff
path: root/ace/Free_List.i
diff options
context:
space:
mode:
authorbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-06-04 00:28:45 +0000
committerbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-06-04 00:28:45 +0000
commit1e92c1984331cacea0b72d9d817f28b8dacdc218 (patch)
treedf56cae7425595d3da052496955161fadc6bc852 /ace/Free_List.i
parent35d1135d0091ec71142a95fdbc7c3a3bb741ebec (diff)
downloadATCD-1e92c1984331cacea0b72d9d817f28b8dacdc218.tar.gz
*** empty log message ***
Diffstat (limited to 'ace/Free_List.i')
-rw-r--r--ace/Free_List.i65
1 files changed, 65 insertions, 0 deletions
diff --git a/ace/Free_List.i b/ace/Free_List.i
new file mode 100644
index 00000000000..e9447fe4ba5
--- /dev/null
+++ b/ace/Free_List.i
@@ -0,0 +1,65 @@
+/* -*- C++ -*- */
+
+// Inserts an element onto the free list (if it isn't past the high water mark)
+
+template <class T, class LOCK> ACE_INLINE void
+ACE_Locked_Free_List<T, LOCK>::add (T *element)
+{
+ ACE_MT (ACE_GUARD (LOCK, ace_mon, *this->mutex_));
+ // Check to see that we not at the high water mark
+ if (this->size_ >= this->hwm_)
+ {
+ element->set_next (this->free_list_);
+ this->free_list_ = element;
+ this->size_++;
+ }
+ else
+ delete element;
+}
+
+
+// Takes a element off the freelist and returns it. It creates <inc> new elements
+// if the size is at the low water mark.
+
+template <class T, class LOCK> ACE_INLINE T *
+ACE_Locked_Free_List<T, LOCK>::remove (void)
+{
+ ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, *this->mutex_, 0));
+ T *temp;
+
+ // If we are at the low water mark, add some nodes
+ if (this->size_ <= this->lwm_)
+ this->alloc (this->inc_);
+
+ // Remove a node
+ temp = this->free_list_;
+ this->free_list_ = this->free_list_->get_next ();
+ this->size_--;
+
+ return temp;
+}
+
+
+// Returns the current size of the free list
+
+template <class T, class LOCK> ACE_INLINE size_t
+ACE_Locked_Free_List<T, LOCK>::size ()
+{
+ return this->size_;
+}
+
+
+// Resizes the free list to <newsize>
+
+template <class T, class LOCK> ACE_INLINE void
+ACE_Locked_Free_List<T, LOCK>::resize (size_t newsize)
+{
+ ACE_MT (ACE_GUARD (LOCK, ace_mon, *this->mutex_));
+ // Check to see if we grow or shrink
+ if (newsize < this->size_)
+ this->dealloc (this->size_ - newsize);
+ else
+ this->alloc (newsize - this->size_);
+}
+
+