Rename some of SamplingCircularQueue methods

Renamed StartDequeue -> Peek, FinishDequeue -> Remove.

BUG=None
R=bmeurer@chromium.org, loislo@chromium.org

Review URL: https://codereview.chromium.org/23686006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16549 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yurys@chromium.org 2013-09-05 10:31:18 +00:00
parent 8d6a096c42
commit e9c47357e6
4 changed files with 40 additions and 41 deletions

View File

@ -46,7 +46,7 @@ SamplingCircularQueue<T, L>::~SamplingCircularQueue() {
template<typename T, unsigned L>
T* SamplingCircularQueue<T, L>::StartDequeue() {
T* SamplingCircularQueue<T, L>::Peek() {
MemoryBarrier();
if (Acquire_Load(&dequeue_pos_->marker) == kFull) {
return &dequeue_pos_->record;
@ -56,7 +56,7 @@ T* SamplingCircularQueue<T, L>::StartDequeue() {
template<typename T, unsigned L>
void SamplingCircularQueue<T, L>::FinishDequeue() {
void SamplingCircularQueue<T, L>::Remove() {
Release_Store(&dequeue_pos_->marker, kEmpty);
dequeue_pos_ = Next(dequeue_pos_);
}

View File

@ -55,12 +55,11 @@ class SamplingCircularQueue {
void FinishEnqueue();
// Executed on the consumer (analyzer) thread.
// StartDequeue returns a pointer to a memory location for retrieving
// the next record. After the record had been read by a consumer,
// FinishDequeue must be called. Until that moment, subsequent calls
// to StartDequeue will return the same pointer.
T* StartDequeue();
void FinishDequeue();
// Retrieves, but does not remove, the head of this queue, returning NULL
// if this queue is empty. After the record had been read by a consumer,
// Remove must be called.
T* Peek();
void Remove();
private:
// Reserved values for the entry marker.

View File

@ -114,11 +114,11 @@ bool ProfilerEventsProcessor::ProcessOneSample() {
return false;
}
const TickSampleEventRecord* record = ticks_buffer_.StartDequeue();
const TickSampleEventRecord* record = ticks_buffer_.Peek();
if (record == NULL) return true;
if (record->order != last_processed_code_event_id_) return true;
generator_->RecordTickSample(record->sample);
ticks_buffer_.FinishDequeue();
ticks_buffer_.Remove();
return false;
}

View File

@ -41,7 +41,7 @@ TEST(SamplingCircularQueue) {
// Check that we are using non-reserved values.
// Fill up the first chunk.
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
for (Record i = 1; i < 1 + kMaxRecordsInQueue; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartEnqueue());
CHECK_NE(NULL, rec);
@ -53,27 +53,27 @@ TEST(SamplingCircularQueue) {
CHECK_EQ(NULL, scq.StartEnqueue());
// Try to enqueue when the the queue is full. Consumption must be available.
CHECK_NE(NULL, scq.StartDequeue());
CHECK_NE(NULL, scq.Peek());
for (int i = 0; i < 10; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartEnqueue());
CHECK_EQ(NULL, rec);
CHECK_NE(NULL, scq.StartDequeue());
CHECK_NE(NULL, scq.Peek());
}
// Consume all records.
for (Record i = 1; i < 1 + kMaxRecordsInQueue; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartDequeue());
Record* rec = reinterpret_cast<Record*>(scq.Peek());
CHECK_NE(NULL, rec);
CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
scq.FinishDequeue();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek()));
scq.Remove();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek()));
}
// The queue is empty.
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
for (Record i = 0; i < kMaxRecordsInQueue / 2; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartEnqueue());
CHECK_NE(NULL, rec);
@ -82,18 +82,18 @@ TEST(SamplingCircularQueue) {
}
// Consume all available kMaxRecordsInQueue / 2 records.
CHECK_NE(NULL, scq.StartDequeue());
CHECK_NE(NULL, scq.Peek());
for (Record i = 0; i < kMaxRecordsInQueue / 2; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartDequeue());
Record* rec = reinterpret_cast<Record*>(scq.Peek());
CHECK_NE(NULL, rec);
CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
scq.FinishDequeue();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek()));
scq.Remove();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek()));
}
// The queue is empty.
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
}
@ -148,41 +148,41 @@ TEST(SamplingCircularQueueMultithreading) {
ProducerThread producer2(&scq, kRecordsPerChunk, 10, &semaphore);
ProducerThread producer3(&scq, kRecordsPerChunk, 20, &semaphore);
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
producer1.Start();
semaphore.Wait();
for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartDequeue());
Record* rec = reinterpret_cast<Record*>(scq.Peek());
CHECK_NE(NULL, rec);
CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
scq.FinishDequeue();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek()));
scq.Remove();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek()));
}
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
producer2.Start();
semaphore.Wait();
for (Record i = 10; i < 10 + kRecordsPerChunk; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartDequeue());
Record* rec = reinterpret_cast<Record*>(scq.Peek());
CHECK_NE(NULL, rec);
CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
scq.FinishDequeue();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek()));
scq.Remove();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek()));
}
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
producer3.Start();
semaphore.Wait();
for (Record i = 20; i < 20 + kRecordsPerChunk; ++i) {
Record* rec = reinterpret_cast<Record*>(scq.StartDequeue());
Record* rec = reinterpret_cast<Record*>(scq.Peek());
CHECK_NE(NULL, rec);
CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
scq.FinishDequeue();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue()));
CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek()));
scq.Remove();
CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek()));
}
CHECK_EQ(NULL, scq.StartDequeue());
CHECK_EQ(NULL, scq.Peek());
}