Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / ACE / ace / Intrusive_List.cpp
blob0d4c5fdb690e3f9a334923ba05a07d9ef3771cb3
1 #ifndef ACE_INTRUSIVE_LIST_CPP
2 #define ACE_INTRUSIVE_LIST_CPP
4 #include "ace/Intrusive_List.h"
6 #if !defined (ACE_LACKS_PRAGMA_ONCE)
7 # pragma once
8 #endif /* ACE_LACKS_PRAGMA_ONCE */
10 #if !defined (__ACE_INLINE__)
11 #include "ace/Intrusive_List.inl"
12 #endif /* __ACE_INLINE__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 template<class T> void
17 ACE_Intrusive_List<T>::push_back (T *node)
19 if (this->tail_ == 0)
21 this->tail_ = node;
22 this->head_ = node;
23 node->next (0);
24 node->prev (0);
26 else
28 this->tail_->next (node);
29 node->prev (this->tail_);
30 node->next (0);
31 this->tail_ = node;
35 template<class T> void
36 ACE_Intrusive_List<T>::push_front (T *node)
38 if (this->head_ == 0)
40 this->tail_ = node;
41 this->head_ = node;
42 node->next (0);
43 node->prev (0);
45 else
47 this->head_->prev (node);
48 node->next (this->head_);
49 node->prev (0);
50 this->head_ = node;
54 template<class T> T *
55 ACE_Intrusive_List<T>::pop_front ()
57 T *node = this->head_;
58 if (node != 0)
60 this->unsafe_remove (node);
62 return node;
65 template<class T> T *
66 ACE_Intrusive_List<T>::pop_back ()
68 T *node = this->tail_;
69 if (node != 0)
71 this->unsafe_remove (node);
73 return node;
76 template<class T> void
77 ACE_Intrusive_List<T>::remove (T *node)
79 for (T *i = this->head_; i != 0; i = i->next ())
81 if (node == i)
83 this->unsafe_remove (node);
84 return;
89 template<class T> void
90 ACE_Intrusive_List<T>::unsafe_remove (T *node)
92 if (node->prev () != 0)
93 node->prev ()->next (node->next ());
94 else
95 this->head_ = node->next ();
97 if (node->next () != 0)
98 node->next ()->prev (node->prev ());
99 else
100 this->tail_ = node->prev ();
102 node->next (0);
103 node->prev (0);
106 ACE_END_VERSIONED_NAMESPACE_DECL
108 #endif /* ACE_INTRUSIVE_LIST_CPP */