Index: src/unbound-queue-inl.h |
diff --git a/src/unbound-queue-inl.h b/src/unbound-queue-inl.h |
index 86722f3a7cd18b24bbe44f5de9abbbdb51fcf7b4..796ba401d58664faccf1f8432dc5b7fdd073480d 100644 |
--- a/src/unbound-queue-inl.h |
+++ b/src/unbound-queue-inl.h |
@@ -68,11 +68,12 @@ void UnboundQueue<Record>::DeleteFirst() { |
template<typename Record> |
-void UnboundQueue<Record>::Dequeue(Record* rec) { |
- ASSERT(divider_ != last_); |
+bool UnboundQueue<Record>::Dequeue(Record* rec) { |
+ if (divider_ == Acquire_Load(&last_)) return false; |
Node* next = reinterpret_cast<Node*>(divider_)->next; |
*rec = next->value; |
Release_Store(÷r_, reinterpret_cast<AtomicWord>(next)); |
+ return true; |
} |
@@ -81,13 +82,22 @@ void UnboundQueue<Record>::Enqueue(const Record& rec) { |
Node*& next = reinterpret_cast<Node*>(last_)->next; |
next = new Node(rec); |
Release_Store(&last_, reinterpret_cast<AtomicWord>(next)); |
- while (first_ != reinterpret_cast<Node*>(divider_)) DeleteFirst(); |
+ |
+ while (first_ != reinterpret_cast<Node*>(Acquire_Load(÷r_))) { |
+ DeleteFirst(); |
+ } |
+} |
+ |
+ |
+template<typename Record> |
+bool UnboundQueue<Record>::IsEmpty() const { |
+ return NoBarrier_Load(÷r_) == NoBarrier_Load(&last_); |
} |
template<typename Record> |
-Record* UnboundQueue<Record>::Peek() { |
- ASSERT(divider_ != last_); |
+Record* UnboundQueue<Record>::Peek() const { |
+ if (divider_ == Acquire_Load(&last_)) return NULL; |
Node* next = reinterpret_cast<Node*>(divider_)->next; |
return &next->value; |
} |