diff options
author | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-10-20 19:19:34 +0000 |
---|---|---|
committer | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-10-20 19:19:34 +0000 |
commit | 79c2cc2cde3626ae71b26d4a4226dcfa8691c487 (patch) | |
tree | 6f9298b4fa6810a3f6f57f35252b9e27195e4b04 /ace/Containers.h | |
parent | 5a99875cf459e5cf8baa1e79f1c8a0af200bddc3 (diff) | |
download | ATCD-79c2cc2cde3626ae71b26d4a4226dcfa8691c487.tar.gz |
Changed to use double-linked list to hold the thread descriptor.
Changed to cache the pointer to thread descriptor in TSS instead
of caching some individual values.
Diffstat (limited to 'ace/Containers.h')
-rw-r--r-- | ace/Containers.h | 221 |
1 files changed, 76 insertions, 145 deletions
diff --git a/ace/Containers.h b/ace/Containers.h index f065d07f754..72ecf381c04 100644 --- a/ace/Containers.h +++ b/ace/Containers.h @@ -197,127 +197,20 @@ private: // Current value of the item in this node. }; -#if defined (NANBOR_EXP_CODES) -class ACE_DNode_Base - // = TITLE - // Implement the minimum stuff a node in a double - // linked list should have. - // - // = DESCRIPTION - // Basic functionalities an element in double-linked - // lists. This is an abstract class and can't be - // instantiated. -{ - friend class ACE_Double_Linked_List_Iterator_Base; - friend class ACE_Double_Linked_List_Base; - -public: - ACE_DNode_Base (void); - // Default do nothing ctor. - - // ACE_DNode_Base (ACE_DNode_Base *n, ACE_DNode_Base *p); - // Build and set ctor. - -protected: - ACE_DNode_Base *prev_; - // Pointer to previous element in the list. - - ACE_DNode_Base *next_; - // Pointer to next element in the list. -}; - -class ACE_Double_Linked_List_Base; -// forward declaration - -class ACE_Double_Linked_List_Iterator_Base - // = TITLE - // Basic double-linked list iterator functionalities. - // - // = DESCRIPTION - // -{ -public: - ACE_Double_Linked_List_Iterator_Base - (ACE_Double_Linked_List_Base &dll); - // Constructor. - -protected: - ACE_DNode_Base *not_done (void) ; - // Check if we reach the end of the list. Can also be used to get - // the *current* element in the list. Return the address of the - // current item if there are still elements left , 0 if we run out of element. - - ACE_DNode_Base *do_advance (void); - // Advance to the next element in the list. Return the address of the - // next element if there are more, 0 otherwise. - - // @@ This function seems redundant. -// ACE_DNode_Base *next (void); -// // Get the next unvisit element from the list. Return address if succeed, -// // 0 otherwise. - - ACE_DNode_Base *current_; - // Remember where we are. - - ACE_Double_Linked_List_Base &dllist_; -}; - -class ACE_Double_Linked_List_Base - // = TITLE - // Basic double-linked list implementation. - // - // = DESCRIPTION - // This is a barebone implementation of double-linked lists. - // It only provide a minimum set of functionalities to - // work. You must subclass from it and other related classes - // for them to work correctly. -{ - friend class ACE_Double_Linked_List_Iterator_Base; - -public: - size_t size (void); - // Return current size of the list. - -protected: - // We hide these function here because they are not supposed to - // be used directly. Notice that all these functions have only - // limited error detections. - - ACE_Double_Linked_List_Base (void); - // Default ctor. - - void init_head (void); - // Setup header pointer. Called after we create the head node in ctor. - - int insert_element (ACE_DNode_Base *new_item, - int before = 0, - ACE_DNode_Base *old_item = 0); - // Insert a <new_element> into the list. It will be added before - // or after <old_item>. Default is to insert the new item *after* - // <head_>. Return 0 if succeed, -1 if error occured. - - int remove_element (ACE_DNode_Base *item); - // Remove an <item> from the list. Return 0 if succeed, -1 otherwise. - // Notice that this function only checks if item is <head_>. Users - // must ensure the item is in the list. - - ACE_Double_Linked_List_Iterator_Base *iter (void); - // Iterator factory. - - ACE_DNode_Base *head_; - // Head of the circular double-linked list. - - size_t size_; - // Size of this list. -}; +#if 0 +// Forward declaration. +template <class T> class ACE_Double_Linked_List; +template <class T> class ACE_Double_Linked_List_Iterator; template <class T> -class ACE_DNode : public ACE_DNode_Base +class ACE_DNode // = TITLE // Implementation element in a Double-linked List. { friend class ACE_Double_Linked_List<T>; friend class ACE_Double_Linked_List_Iterator<T>; +public: + T* item (); protected: ACE_DNode (const T &i, ACE_DNode<T> *n = 0, ACE_DNode<T> *p = 0); ACE_DNode (const ACE_DNode<T> &i); @@ -325,8 +218,14 @@ protected: ~ACE_DNode (void); T item_; + + ACE_DNode *prev_; + // Pointer to previous element in the list. + + ACE_DNode *next_; + // Pointer to next element in the list. }; -#endif /* NANBOR_EXP_CODES */ +#endif /* 0 */ template <class T> class ACE_Unbounded_Stack @@ -580,7 +479,6 @@ protected: // Allocation Strategy of the queue. }; -#if defined (NANBOR_EXP_CODES) template <class T> class ACE_Double_Linked_List; @@ -593,7 +491,9 @@ class ACE_Double_Linked_List_Iterator // Iterate thru the double-linked list. This class provide // an interface that let users access the internal element // addresses directly, which (IMHO) seems to break the - // encasulation. + // encasulation. Notice <class T> must delcare + // ACE_Double_Linked_List<T> and + // ACE_Double_Linked_List_Iterator as friend classes. { public: // = Initialization method. @@ -601,14 +501,10 @@ public: // = Iteration methods. - ACE_DNode<T> *next (void); + T *next (void) const; // Return the address of next (current) unvisited ACE_DNode, // 0 if there is no more element available. - int next (T *&next_item); - // Pass back the <next_item> that hasn't been seen in the Stack. - // Returns 0 when all items have been seen, else 1. - int advance (void); // Move forward by one element in the Stack. Returns 0 when all the // items in the Stack have been seen, else 1. @@ -621,6 +517,22 @@ public: ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. + +protected: + T *not_done (void) const ; + // Check if we reach the end of the list. Can also be used to get + // the *current* element in the list. Return the address of the + // current item if there are still elements left , 0 if we run out + // of element. + + T *do_advance (void); + // Advance to the next element in the list. Return the address of the + // next element if there are more, 0 otherwise. + + T *current_; + // Remember where we are. + + ACE_Double_Linked_List<T> &dllist_; }; @@ -630,9 +542,10 @@ class ACE_Double_Linked_List // A double-linked list implementation. // // = DESCRIPTION - // This implementation of an unbounded double-linked list uses a circular - // linked list with a dummy node. It is pretty much like the ACE_Unbounded_Queue - // except that it allows removing of a specific element from a specific location. + // This implementation of an unbounded double-linked list uses a + // circular linked list with a dummy node. It is pretty much + // like the ACE_Unbounded_Queue except that it allows removing + // of a specific element from a specific location. { friend class ACE_Double_Linked_List_Iterator<T>; public: @@ -641,10 +554,10 @@ public: // construction. Use user specified allocation strategy // if specified. - ACE_Double_Linked_List (const ACE_Double_Linked_List<T> &); + ACE_Double_Linked_List (ACE_Double_Linked_List<T> &); // Copy constructor. - void operator= (const ACE_Double_Linked_List<T> &); + void operator= (ACE_Double_Linked_List<T> &); // Assignment operator. ~ACE_Double_Linked_List (void); @@ -660,56 +573,54 @@ public: // = Classic queue operations. - ACE_DNode<T> *insert_tail (const T &new_item); + T *insert_tail (T *new_item); // Adds <new_item> to the tail of the list. Returns 0 on success, // -1 on failure. - ACE_DNode<T> *insert_head (const T &new_item); + T *insert_head (T *new_item); // Adds <new_item> to the head of the list. Returns 0 on success, // -1 on failure. - int delete_head (T &item); + T* delete_head (void); // Removes and returns the first <item> in the list. Returns 0 on - // success, -1 if the queue was empty. This method will free the + // success, -1 if the queue was empty. This method will *not* free the // internal node. - int delete_tail (T &item); + T *delete_tail (void); // Removes and returns the last <item> in the list. Returns 0 on - // success, -1 if the queue was empty. This method will free the + // success, -1 if the queue was empty. This method will *not* free the // internal node. // = Additional utility methods. void reset (void); // Reset the <ACE_Double_Linked_List> to be empty. + // Notice that since no one is interested in the items within, + // This operation will delete all items. - int get (T *&item, size_t index = 0) const; + int get (T *&item, size_t index = 0); // Get the <index>th element in the set. Returns -1 if the element // isn't in the range <0..size() - 1>, else 0. - int set (const T &item, size_t index); - // Set the <index>th element in the set. Will pad out the set with - // empty nodes if <index> is beyond the range <0..size() - 1>. - // Returns -1 on failure, 0 if <index> isn't initially in range, and - // 0 otherwise. - size_t size (void) const; // The number of items in the queue. void dump (void) const; // Dump the state of an object. - ACE_DNode<T> *find (const T &item); +#if 0 + T *find (const T &item); // Locate the DNode address that contains the item. Return // an address if succeed, 0 otherwise. - int remove (const T &item); + T *remove (const T &item); // This function will iterate thru the double-linked list and remove // it from the list. Return Node address if succeed, 0 otherwise. // Notice that this method will *not* free the internal node. The // node is simple unlinked from the list. +#endif /* 0 */ - int remove (ACE_DNode<T> *n); + int remove (T *n); // Use DNode address directly. ACE_ALLOC_HOOK_DECLARE; @@ -719,13 +630,33 @@ protected: void delete_nodes (void); // Delete all the nodes in the list. - void copy_nodes (const ACE_Double_Linked_List<T> &); + void copy_nodes (ACE_Double_Linked_List<T> &); // Copy nodes into this list. + void init_head (void); + // Setup header pointer. Called after we create the head node in ctor. + + int insert_element (T *new_item, + int before = 0, + T *old_item = 0); + // Insert a <new_element> into the list. It will be added before + // or after <old_item>. Default is to insert the new item *after* + // <head_>. Return 0 if succeed, -1 if error occured. + + int remove_element (T *item); + // Remove an <item> from the list. Return 0 if succeed, -1 otherwise. + // Notice that this function only checks if item is <head_>. Users + // must ensure the item is in the list. + + T *head_; + // Head of the circular double-linked list. + + size_t size_; + // Size of this list. + ACE_Allocator *allocator_; // Allocation Strategy of the queue. }; -#endif /* NANBOR_EXP_CODES */ template <class T> class ACE_Unbounded_Set_Iterator |