16 #ifndef IMPALA_UTIL_INTERNAL_QUEUE_H
17 #define IMPALA_UTIL_INTERNAL_QUEUE_H
19 #include <boost/thread/locks.hpp>
50 return reinterpret_cast<T*
>(
next);
54 return reinterpret_cast<T*
>(
prev);
71 boost::lock_guard<SpinLock> lock(
lock_);
72 if (
empty())
return NULL;
73 return reinterpret_cast<T*
>(
head_);
79 boost::lock_guard<SpinLock> lock(
lock_);
80 if (
empty())
return NULL;
81 return reinterpret_cast<T*
>(
tail_);
87 DCHECK(node->next == NULL);
88 DCHECK(node->prev == NULL);
89 DCHECK(node->parent_queue == NULL);
90 node->parent_queue =
this;
92 boost::lock_guard<SpinLock> lock(
lock_);
106 boost::lock_guard<SpinLock> lock(
lock_);
107 if (
empty())
return NULL;
117 DCHECK(result != NULL);
118 result->next = result->prev = NULL;
119 result->parent_queue = NULL;
120 return reinterpret_cast<T*
>(result);
128 boost::lock_guard<SpinLock> lock(
lock_);
129 if (
empty())
return NULL;
139 DCHECK(result != NULL);
140 result->next = result->prev = NULL;
141 result->parent_queue = NULL;
142 return reinterpret_cast<T*
>(result);
149 if (node->parent_queue == NULL)
return;
150 DCHECK(node->parent_queue ==
this);
152 boost::lock_guard<SpinLock> lock(
lock_);
153 if (node->next == NULL && node->prev == NULL) {
155 DCHECK(node ==
head_);
156 DCHECK(
tail_ == node);
159 node->parent_queue = NULL;
164 DCHECK(node->prev == NULL);
167 DCHECK(node->prev != NULL);
168 node->prev->next = node->next;
172 DCHECK(node->next == NULL);
174 }
else if (node->next != NULL) {
179 node->next = node->prev = NULL;
180 node->parent_queue = NULL;
185 boost::lock_guard<SpinLock> lock(
lock_);
187 while (cur != NULL) {
190 tmp->prev = tmp->next = NULL;
191 tmp->parent_queue = NULL;
203 return target->parent_queue ==
this;
208 int num_elements_found = 0;
209 boost::lock_guard<SpinLock> lock(
lock_);
211 if (
tail_ != NULL)
return false;
212 if (
size() != 0)
return false;
218 while (current != NULL) {
219 if (current->parent_queue !=
this)
return false;
220 ++num_elements_found;
221 Node* next = current->next;
223 if (current !=
tail_)
return false;
225 if (next->prev != current)
return false;
229 if (num_elements_found !=
size())
return false;
235 std::stringstream ss;
238 boost::lock_guard<SpinLock> lock(
lock_);
240 while (curr != NULL) {
bool Contains(const T *target) const
void Enqueue(T *n)
Enqueue node onto the queue's tail. This is O(1).
void Clear()
Clears all elements in the list.
std::string DebugString()
Prints the queue ptrs to a string.
InternalQueue * parent_queue
Pointer to the queue this Node is on. NULL if not on any queue.
T must be a subclass of InternalQueue::Node.
T * Next() const
Returns the Next/Prev node or NULL if this is the end/front.
bool Validate()
Validates the internal structure of the list.