| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 | 36 |
| 37 TEST(SamplingCircularQueue) { | 37 TEST(SamplingCircularQueue) { |
| 38 typedef SamplingCircularQueue::Cell Record; | 38 typedef SamplingCircularQueue::Cell Record; |
| 39 const int kRecordsPerChunk = 4; | 39 const int kRecordsPerChunk = 4; |
| 40 SamplingCircularQueue scq(sizeof(Record), | 40 SamplingCircularQueue scq(sizeof(Record), |
| 41 kRecordsPerChunk * sizeof(Record), | 41 kRecordsPerChunk * sizeof(Record), |
| 42 3); | 42 3); |
| 43 | 43 |
| 44 // Check that we are using non-reserved values. | 44 // Check that we are using non-reserved values. |
| 45 CHECK_NE(SamplingCircularQueue::kClear, 1); | |
| 46 CHECK_NE(SamplingCircularQueue::kEnd, 1); | |
| 47 // Fill up the first chunk. | 45 // Fill up the first chunk. |
| 48 CHECK_EQ(NULL, scq.StartDequeue()); | 46 CHECK_EQ(NULL, scq.StartDequeue()); |
| 49 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { | 47 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { |
| 50 Record* rec = reinterpret_cast<Record*>(scq.Enqueue()); | 48 Record* rec = reinterpret_cast<Record*>(scq.Enqueue()); |
| 51 CHECK_NE(NULL, rec); | 49 CHECK_NE(NULL, rec); |
| 52 *rec = i; | 50 *rec = i; |
| 53 CHECK_EQ(NULL, scq.StartDequeue()); | 51 CHECK_EQ(NULL, scq.StartDequeue()); |
| 54 } | 52 } |
| 55 | 53 |
| 56 // Fill up the second chunk. Consumption must still be unavailable. | 54 // Fill up the second chunk. Consumption must still be unavailable. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 const int kRecordsPerChunk = 4; | 144 const int kRecordsPerChunk = 4; |
| 147 SamplingCircularQueue scq(sizeof(Record), | 145 SamplingCircularQueue scq(sizeof(Record), |
| 148 kRecordsPerChunk * sizeof(Record), | 146 kRecordsPerChunk * sizeof(Record), |
| 149 3); | 147 3); |
| 150 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); | 148 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); |
| 151 // Don't poll ahead, making possible to check data in the buffer | 149 // Don't poll ahead, making possible to check data in the buffer |
| 152 // immediately after enqueuing. | 150 // immediately after enqueuing. |
| 153 scq.FlushResidualRecords(); | 151 scq.FlushResidualRecords(); |
| 154 | 152 |
| 155 // Check that we are using non-reserved values. | 153 // Check that we are using non-reserved values. |
| 156 CHECK_NE(SamplingCircularQueue::kClear, 1); | |
| 157 CHECK_NE(SamplingCircularQueue::kEnd, 1); | |
| 158 ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore); | 154 ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore); |
| 159 ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore); | 155 ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore); |
| 160 ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore); | 156 ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore); |
| 161 | 157 |
| 162 CHECK_EQ(NULL, scq.StartDequeue()); | 158 CHECK_EQ(NULL, scq.StartDequeue()); |
| 163 producer1.Start(); | 159 producer1.Start(); |
| 164 semaphore->Wait(); | 160 semaphore->Wait(); |
| 165 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { | 161 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { |
| 166 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); | 162 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); |
| 167 CHECK_NE(NULL, rec); | 163 CHECK_NE(NULL, rec); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 192 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 188 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
| 193 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 189 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 194 scq.FinishDequeue(); | 190 scq.FinishDequeue(); |
| 195 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 191 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 196 } | 192 } |
| 197 | 193 |
| 198 CHECK_EQ(NULL, scq.StartDequeue()); | 194 CHECK_EQ(NULL, scq.StartDequeue()); |
| 199 | 195 |
| 200 delete semaphore; | 196 delete semaphore; |
| 201 } | 197 } |
| OLD | NEW |