Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_CIRCULAR_QUEUE_INL_H_ | 28 #ifndef V8_CIRCULAR_QUEUE_INL_H_ |
| 29 #define V8_CIRCULAR_QUEUE_INL_H_ | 29 #define V8_CIRCULAR_QUEUE_INL_H_ |
| 30 | 30 |
| 31 #include "circular-queue.h" | 31 #include "circular-queue.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 | 36 template<typename T, unsigned L> |
| 37 void* SamplingCircularQueue::Enqueue() { | 37 SamplingCircularQueue<T, L>::SamplingCircularQueue() |
| 38 if (producer_pos_->enqueue_pos == producer_pos_->next_chunk_pos) { | 38 : enqueue_pos_(buffer_), |
| 39 if (producer_pos_->enqueue_pos == buffer_ + buffer_size_) { | 39 dequeue_pos_(buffer_) { |
| 40 producer_pos_->next_chunk_pos = buffer_; | |
| 41 producer_pos_->enqueue_pos = buffer_; | |
| 42 } | |
| 43 Acquire_Store(producer_pos_->next_chunk_pos, kEnqueueStarted); | |
| 44 // Skip marker. | |
| 45 producer_pos_->enqueue_pos += 1; | |
| 46 producer_pos_->next_chunk_pos += chunk_size_; | |
| 47 } | |
| 48 void* result = producer_pos_->enqueue_pos; | |
| 49 producer_pos_->enqueue_pos += record_size_; | |
| 50 return result; | |
| 51 } | 40 } |
| 52 | 41 |
| 53 | 42 |
| 54 void SamplingCircularQueue::WrapPositionIfNeeded( | 43 template<typename T, unsigned L> |
| 55 SamplingCircularQueue::Cell** pos) { | 44 SamplingCircularQueue<T, L>::~SamplingCircularQueue() { |
| 56 if (*pos == buffer_ + buffer_size_) *pos = buffer_; | |
| 57 } | 45 } |
| 58 | 46 |
| 59 | 47 |
| 48 template<typename T, unsigned L> | |
| 49 T* SamplingCircularQueue<T, L>::StartDequeue() { | |
| 50 MemoryBarrier(); | |
| 51 if (NoBarrier_Load(&dequeue_pos_->marker) == kFull) { | |
|
Benedikt Meurer
2013/08/13 14:29:42
Thinking about this again, we may need an Acquire_
yurys
2013/08/13 14:52:37
Done.
| |
| 52 return &dequeue_pos_->record; | |
| 53 } | |
| 54 return NULL; | |
| 55 } | |
| 56 | |
| 57 | |
| 58 template<typename T, unsigned L> | |
| 59 void SamplingCircularQueue<T, L>::FinishDequeue() { | |
| 60 Release_Store(&dequeue_pos_->marker, kEmpty); | |
| 61 dequeue_pos_ = Next(dequeue_pos_); | |
| 62 } | |
| 63 | |
| 64 | |
| 65 template<typename T, unsigned L> | |
| 66 T* SamplingCircularQueue<T, L>::StartEnqueue() { | |
| 67 MemoryBarrier(); | |
| 68 if (NoBarrier_Load(&enqueue_pos_->marker) == kEmpty) { | |
|
Benedikt Meurer
2013/08/13 14:29:42
Also use Acquire_Load() here to be sure.
yurys
2013/08/13 14:52:37
Done.
| |
| 69 return &enqueue_pos_->record; | |
| 70 } | |
| 71 return NULL; | |
| 72 } | |
| 73 | |
| 74 | |
| 75 template<typename T, unsigned L> | |
| 76 void SamplingCircularQueue<T, L>::FinishEnqueue() { | |
| 77 Release_Store(&enqueue_pos_->marker, kFull); | |
| 78 enqueue_pos_ = Next(enqueue_pos_); | |
| 79 } | |
| 80 | |
| 81 | |
| 82 template<typename T, unsigned L> | |
| 83 typename SamplingCircularQueue<T, L>::Entry* SamplingCircularQueue<T, L>::Next( | |
| 84 Entry* entry) { | |
| 85 Entry* next = entry + 1; | |
| 86 if (next == &buffer_[L]) return buffer_; | |
| 87 return next; | |
| 88 } | |
| 89 | |
| 60 } } // namespace v8::internal | 90 } } // namespace v8::internal |
| 61 | 91 |
| 62 #endif // V8_CIRCULAR_QUEUE_INL_H_ | 92 #endif // V8_CIRCULAR_QUEUE_INL_H_ |
| OLD | NEW |