Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_UNBOUND_QUEUE_INL_H_ | 5 #ifndef V8_UNBOUND_QUEUE_INL_H_ |
| 6 #define V8_UNBOUND_QUEUE_INL_H_ | 6 #define V8_UNBOUND_QUEUE_INL_H_ |
| 7 | 7 |
| 8 #include "src/unbound-queue.h" | 8 #include "src/unbound-queue.h" |
| 9 | 9 |
| 10 #include "src/atomicops.h" | 10 #include "src/base/atomicops.h" |
|
Jakob Kummerow
2014/06/05 11:49:06
You can drop this here if you move it to unbound-q
| |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 template<typename Record> | 15 template<typename Record> |
| 16 struct UnboundQueue<Record>::Node: public Malloced { | 16 struct UnboundQueue<Record>::Node: public Malloced { |
| 17 explicit Node(const Record& value) | 17 explicit Node(const Record& value) |
| 18 : value(value), next(NULL) { | 18 : value(value), next(NULL) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 Record value; | 21 Record value; |
| 22 Node* next; | 22 Node* next; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 | 25 |
| 26 template<typename Record> | 26 template<typename Record> |
| 27 UnboundQueue<Record>::UnboundQueue() { | 27 UnboundQueue<Record>::UnboundQueue() { |
| 28 first_ = new Node(Record()); | 28 first_ = new Node(Record()); |
| 29 divider_ = last_ = reinterpret_cast<AtomicWord>(first_); | 29 divider_ = last_ = reinterpret_cast<base::AtomicWord>(first_); |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| 33 template<typename Record> | 33 template<typename Record> |
| 34 UnboundQueue<Record>::~UnboundQueue() { | 34 UnboundQueue<Record>::~UnboundQueue() { |
| 35 while (first_ != NULL) DeleteFirst(); | 35 while (first_ != NULL) DeleteFirst(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 template<typename Record> | 39 template<typename Record> |
| 40 void UnboundQueue<Record>::DeleteFirst() { | 40 void UnboundQueue<Record>::DeleteFirst() { |
| 41 Node* tmp = first_; | 41 Node* tmp = first_; |
| 42 first_ = tmp->next; | 42 first_ = tmp->next; |
| 43 delete tmp; | 43 delete tmp; |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 template<typename Record> | 47 template<typename Record> |
| 48 bool UnboundQueue<Record>::Dequeue(Record* rec) { | 48 bool UnboundQueue<Record>::Dequeue(Record* rec) { |
| 49 if (divider_ == Acquire_Load(&last_)) return false; | 49 if (divider_ == base::Acquire_Load(&last_)) return false; |
| 50 Node* next = reinterpret_cast<Node*>(divider_)->next; | 50 Node* next = reinterpret_cast<Node*>(divider_)->next; |
| 51 *rec = next->value; | 51 *rec = next->value; |
| 52 Release_Store(÷r_, reinterpret_cast<AtomicWord>(next)); | 52 base::Release_Store(÷r_, reinterpret_cast<base::AtomicWord>(next)); |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 template<typename Record> | 57 template<typename Record> |
| 58 void UnboundQueue<Record>::Enqueue(const Record& rec) { | 58 void UnboundQueue<Record>::Enqueue(const Record& rec) { |
| 59 Node*& next = reinterpret_cast<Node*>(last_)->next; | 59 Node*& next = reinterpret_cast<Node*>(last_)->next; |
| 60 next = new Node(rec); | 60 next = new Node(rec); |
| 61 Release_Store(&last_, reinterpret_cast<AtomicWord>(next)); | 61 base::Release_Store(&last_, reinterpret_cast<base::AtomicWord>(next)); |
| 62 | 62 |
| 63 while (first_ != reinterpret_cast<Node*>(Acquire_Load(÷r_))) { | 63 while (first_ != reinterpret_cast<Node*>(base::Acquire_Load(÷r_))) { |
| 64 DeleteFirst(); | 64 DeleteFirst(); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 template<typename Record> | 69 template<typename Record> |
| 70 bool UnboundQueue<Record>::IsEmpty() const { | 70 bool UnboundQueue<Record>::IsEmpty() const { |
| 71 return NoBarrier_Load(÷r_) == NoBarrier_Load(&last_); | 71 return base::NoBarrier_Load(÷r_) == base::NoBarrier_Load(&last_); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 template<typename Record> | 75 template<typename Record> |
| 76 Record* UnboundQueue<Record>::Peek() const { | 76 Record* UnboundQueue<Record>::Peek() const { |
| 77 if (divider_ == Acquire_Load(&last_)) return NULL; | 77 if (divider_ == base::Acquire_Load(&last_)) return NULL; |
| 78 Node* next = reinterpret_cast<Node*>(divider_)->next; | 78 Node* next = reinterpret_cast<Node*>(divider_)->next; |
| 79 return &next->value; | 79 return &next->value; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } } // namespace v8::internal | 82 } } // namespace v8::internal |
| 83 | 83 |
| 84 #endif // V8_UNBOUND_QUEUE_INL_H_ | 84 #endif // V8_UNBOUND_QUEUE_INL_H_ |
| OLD | NEW |