| 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 17 matching lines...) Expand all Loading... |
| 28 // Tests of the circular queue. | 28 // Tests of the circular queue. |
| 29 | 29 |
| 30 #include "src/v8.h" | 30 #include "src/v8.h" |
| 31 #include "src/circular-queue-inl.h" | 31 #include "src/circular-queue-inl.h" |
| 32 #include "test/cctest/cctest.h" | 32 #include "test/cctest/cctest.h" |
| 33 | 33 |
| 34 using i::SamplingCircularQueue; | 34 using i::SamplingCircularQueue; |
| 35 | 35 |
| 36 | 36 |
| 37 TEST(SamplingCircularQueue) { | 37 TEST(SamplingCircularQueue) { |
| 38 typedef i::AtomicWord Record; | 38 typedef v8::base::AtomicWord Record; |
| 39 const int kMaxRecordsInQueue = 4; | 39 const int kMaxRecordsInQueue = 4; |
| 40 SamplingCircularQueue<Record, kMaxRecordsInQueue> scq; | 40 SamplingCircularQueue<Record, kMaxRecordsInQueue> scq; |
| 41 | 41 |
| 42 // Check that we are using non-reserved values. | 42 // Check that we are using non-reserved values. |
| 43 // Fill up the first chunk. | 43 // Fill up the first chunk. |
| 44 CHECK_EQ(NULL, scq.Peek()); | 44 CHECK_EQ(NULL, scq.Peek()); |
| 45 for (Record i = 1; i < 1 + kMaxRecordsInQueue; ++i) { | 45 for (Record i = 1; i < 1 + kMaxRecordsInQueue; ++i) { |
| 46 Record* rec = reinterpret_cast<Record*>(scq.StartEnqueue()); | 46 Record* rec = reinterpret_cast<Record*>(scq.StartEnqueue()); |
| 47 CHECK_NE(NULL, rec); | 47 CHECK_NE(NULL, rec); |
| 48 *rec = i; | 48 *rec = i; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek())); | 92 CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // The queue is empty. | 95 // The queue is empty. |
| 96 CHECK_EQ(NULL, scq.Peek()); | 96 CHECK_EQ(NULL, scq.Peek()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 | 99 |
| 100 namespace { | 100 namespace { |
| 101 | 101 |
| 102 typedef i::AtomicWord Record; | 102 typedef v8::base::AtomicWord Record; |
| 103 typedef SamplingCircularQueue<Record, 12> TestSampleQueue; | 103 typedef SamplingCircularQueue<Record, 12> TestSampleQueue; |
| 104 | 104 |
| 105 class ProducerThread: public i::Thread { | 105 class ProducerThread: public i::Thread { |
| 106 public: | 106 public: |
| 107 ProducerThread(TestSampleQueue* scq, | 107 ProducerThread(TestSampleQueue* scq, |
| 108 int records_per_chunk, | 108 int records_per_chunk, |
| 109 Record value, | 109 Record value, |
| 110 i::Semaphore* finished) | 110 i::Semaphore* finished) |
| 111 : Thread("producer"), | 111 : Thread("producer"), |
| 112 scq_(scq), | 112 scq_(scq), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 Record* rec = reinterpret_cast<Record*>(scq.Peek()); | 179 Record* rec = reinterpret_cast<Record*>(scq.Peek()); |
| 180 CHECK_NE(NULL, rec); | 180 CHECK_NE(NULL, rec); |
| 181 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 181 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
| 182 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek())); | 182 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.Peek())); |
| 183 scq.Remove(); | 183 scq.Remove(); |
| 184 CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek())); | 184 CHECK_NE(rec, reinterpret_cast<Record*>(scq.Peek())); |
| 185 } | 185 } |
| 186 | 186 |
| 187 CHECK_EQ(NULL, scq.Peek()); | 187 CHECK_EQ(NULL, scq.Peek()); |
| 188 } | 188 } |
| OLD | NEW |