| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests of the circular queue. | 3 // Tests of the circular queue. |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 #include "circular-queue-inl.h" | 6 #include "circular-queue-inl.h" |
| 7 #include "cctest.h" | 7 #include "cctest.h" |
| 8 | 8 |
| 9 namespace i = v8::internal; | 9 namespace i = v8::internal; |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 CHECK_NE(NULL, scq.StartDequeue()); | 77 CHECK_NE(NULL, scq.StartDequeue()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 namespace { | 81 namespace { |
| 82 | 82 |
| 83 class ProducerThread: public i::Thread { | 83 class ProducerThread: public i::Thread { |
| 84 public: | 84 public: |
| 85 typedef SamplingCircularQueue::Cell Record; | 85 typedef SamplingCircularQueue::Cell Record; |
| 86 | 86 |
| 87 ProducerThread(i::Isolate* isolate, | 87 ProducerThread(SamplingCircularQueue* scq, |
| 88 SamplingCircularQueue* scq, | |
| 89 int records_per_chunk, | 88 int records_per_chunk, |
| 90 Record value, | 89 Record value, |
| 91 i::Semaphore* finished) | 90 i::Semaphore* finished) |
| 92 : Thread(isolate, "producer"), | 91 : Thread("producer"), |
| 93 scq_(scq), | 92 scq_(scq), |
| 94 records_per_chunk_(records_per_chunk), | 93 records_per_chunk_(records_per_chunk), |
| 95 value_(value), | 94 value_(value), |
| 96 finished_(finished) { } | 95 finished_(finished) { } |
| 97 | 96 |
| 98 virtual void Run() { | 97 virtual void Run() { |
| 99 for (Record i = value_; i < value_ + records_per_chunk_; ++i) { | 98 for (Record i = value_; i < value_ + records_per_chunk_; ++i) { |
| 100 Record* rec = reinterpret_cast<Record*>(scq_->Enqueue()); | 99 Record* rec = reinterpret_cast<Record*>(scq_->Enqueue()); |
| 101 CHECK_NE(NULL, rec); | 100 CHECK_NE(NULL, rec); |
| 102 *rec = i; | 101 *rec = i; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 126 kRecordsPerChunk * sizeof(Record), | 125 kRecordsPerChunk * sizeof(Record), |
| 127 3); | 126 3); |
| 128 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); | 127 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); |
| 129 // Don't poll ahead, making possible to check data in the buffer | 128 // Don't poll ahead, making possible to check data in the buffer |
| 130 // immediately after enqueuing. | 129 // immediately after enqueuing. |
| 131 scq.FlushResidualRecords(); | 130 scq.FlushResidualRecords(); |
| 132 | 131 |
| 133 // Check that we are using non-reserved values. | 132 // Check that we are using non-reserved values. |
| 134 CHECK_NE(SamplingCircularQueue::kClear, 1); | 133 CHECK_NE(SamplingCircularQueue::kClear, 1); |
| 135 CHECK_NE(SamplingCircularQueue::kEnd, 1); | 134 CHECK_NE(SamplingCircularQueue::kEnd, 1); |
| 136 i::Isolate* isolate = i::Isolate::Current(); | 135 ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore); |
| 137 ProducerThread producer1(isolate, &scq, kRecordsPerChunk, 1, semaphore); | 136 ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore); |
| 138 ProducerThread producer2(isolate, &scq, kRecordsPerChunk, 10, semaphore); | 137 ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore); |
| 139 ProducerThread producer3(isolate, &scq, kRecordsPerChunk, 20, semaphore); | |
| 140 | 138 |
| 141 CHECK_EQ(NULL, scq.StartDequeue()); | 139 CHECK_EQ(NULL, scq.StartDequeue()); |
| 142 producer1.Start(); | 140 producer1.Start(); |
| 143 semaphore->Wait(); | 141 semaphore->Wait(); |
| 144 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { | 142 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { |
| 145 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); | 143 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); |
| 146 CHECK_NE(NULL, rec); | 144 CHECK_NE(NULL, rec); |
| 147 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 145 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
| 148 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 146 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 149 scq.FinishDequeue(); | 147 scq.FinishDequeue(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 171 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 169 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
| 172 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 170 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 173 scq.FinishDequeue(); | 171 scq.FinishDequeue(); |
| 174 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 172 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 175 } | 173 } |
| 176 | 174 |
| 177 CHECK_EQ(NULL, scq.StartDequeue()); | 175 CHECK_EQ(NULL, scq.StartDequeue()); |
| 178 | 176 |
| 179 delete semaphore; | 177 delete semaphore; |
| 180 } | 178 } |
| OLD | NEW |