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(SamplingCircularQueue* scq, | 87 ProducerThread(i::Isolate* isolate, |
| 88 SamplingCircularQueue* scq, |
88 int records_per_chunk, | 89 int records_per_chunk, |
89 Record value, | 90 Record value, |
90 i::Semaphore* finished) | 91 i::Semaphore* finished) |
91 : scq_(scq), | 92 : Thread(isolate), |
| 93 scq_(scq), |
92 records_per_chunk_(records_per_chunk), | 94 records_per_chunk_(records_per_chunk), |
93 value_(value), | 95 value_(value), |
94 finished_(finished) { } | 96 finished_(finished) { } |
95 | 97 |
96 virtual void Run() { | 98 virtual void Run() { |
97 for (Record i = value_; i < value_ + records_per_chunk_; ++i) { | 99 for (Record i = value_; i < value_ + records_per_chunk_; ++i) { |
98 Record* rec = reinterpret_cast<Record*>(scq_->Enqueue()); | 100 Record* rec = reinterpret_cast<Record*>(scq_->Enqueue()); |
99 CHECK_NE(NULL, rec); | 101 CHECK_NE(NULL, rec); |
100 *rec = i; | 102 *rec = i; |
101 } | 103 } |
(...skipping 22 matching lines...) Expand all Loading... |
124 kRecordsPerChunk * sizeof(Record), | 126 kRecordsPerChunk * sizeof(Record), |
125 3); | 127 3); |
126 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); | 128 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); |
127 // Don't poll ahead, making possible to check data in the buffer | 129 // Don't poll ahead, making possible to check data in the buffer |
128 // immediately after enqueuing. | 130 // immediately after enqueuing. |
129 scq.FlushResidualRecords(); | 131 scq.FlushResidualRecords(); |
130 | 132 |
131 // Check that we are using non-reserved values. | 133 // Check that we are using non-reserved values. |
132 CHECK_NE(SamplingCircularQueue::kClear, 1); | 134 CHECK_NE(SamplingCircularQueue::kClear, 1); |
133 CHECK_NE(SamplingCircularQueue::kEnd, 1); | 135 CHECK_NE(SamplingCircularQueue::kEnd, 1); |
134 ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore); | 136 i::Isolate* isolate = i::Isolate::Current(); |
135 ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore); | 137 ProducerThread producer1(isolate, &scq, kRecordsPerChunk, 1, semaphore); |
136 ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore); | 138 ProducerThread producer2(isolate, &scq, kRecordsPerChunk, 10, semaphore); |
| 139 ProducerThread producer3(isolate, &scq, kRecordsPerChunk, 20, semaphore); |
137 | 140 |
138 CHECK_EQ(NULL, scq.StartDequeue()); | 141 CHECK_EQ(NULL, scq.StartDequeue()); |
139 producer1.Start(); | 142 producer1.Start(); |
140 semaphore->Wait(); | 143 semaphore->Wait(); |
141 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { | 144 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { |
142 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); | 145 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); |
143 CHECK_NE(NULL, rec); | 146 CHECK_NE(NULL, rec); |
144 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 147 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
145 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 148 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
146 scq.FinishDequeue(); | 149 scq.FinishDequeue(); |
(...skipping 21 matching lines...) Expand all Loading... |
168 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 171 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
169 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 172 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
170 scq.FinishDequeue(); | 173 scq.FinishDequeue(); |
171 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 174 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
172 } | 175 } |
173 | 176 |
174 CHECK_EQ(NULL, scq.StartDequeue()); | 177 CHECK_EQ(NULL, scq.StartDequeue()); |
175 | 178 |
176 delete semaphore; | 179 delete semaphore; |
177 } | 180 } |
OLD | NEW |