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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } // namespace | 135 } // namespace |
136 | 136 |
137 TEST(SamplingCircularQueueMultithreading) { | 137 TEST(SamplingCircularQueueMultithreading) { |
138 // Emulate multiple VM threads working 'one thread at a time.' | 138 // Emulate multiple VM threads working 'one thread at a time.' |
139 // This test enqueues data from different threads. This corresponds | 139 // This test enqueues data from different threads. This corresponds |
140 // to the case of profiling under Linux, where signal handler that | 140 // to the case of profiling under Linux, where signal handler that |
141 // does sampling is called in the context of different VM threads. | 141 // does sampling is called in the context of different VM threads. |
142 | 142 |
143 const int kRecordsPerChunk = 4; | 143 const int kRecordsPerChunk = 4; |
144 TestSampleQueue scq; | 144 TestSampleQueue scq; |
145 i::Semaphore* semaphore = i::OS::CreateSemaphore(0); | 145 i::Semaphore semaphore(0); |
146 | 146 |
147 ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore); | 147 ProducerThread producer1(&scq, kRecordsPerChunk, 1, &semaphore); |
148 ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore); | 148 ProducerThread producer2(&scq, kRecordsPerChunk, 10, &semaphore); |
149 ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore); | 149 ProducerThread producer3(&scq, kRecordsPerChunk, 20, &semaphore); |
150 | 150 |
151 CHECK_EQ(NULL, scq.StartDequeue()); | 151 CHECK_EQ(NULL, scq.StartDequeue()); |
152 producer1.Start(); | 152 producer1.Start(); |
153 semaphore->Wait(); | 153 semaphore.Wait(); |
154 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { | 154 for (Record i = 1; i < 1 + kRecordsPerChunk; ++i) { |
155 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); | 155 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); |
156 CHECK_NE(NULL, rec); | 156 CHECK_NE(NULL, rec); |
157 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 157 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
158 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 158 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
159 scq.FinishDequeue(); | 159 scq.FinishDequeue(); |
160 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 160 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
161 } | 161 } |
162 | 162 |
163 CHECK_EQ(NULL, scq.StartDequeue()); | 163 CHECK_EQ(NULL, scq.StartDequeue()); |
164 producer2.Start(); | 164 producer2.Start(); |
165 semaphore->Wait(); | 165 semaphore.Wait(); |
166 for (Record i = 10; i < 10 + kRecordsPerChunk; ++i) { | 166 for (Record i = 10; i < 10 + kRecordsPerChunk; ++i) { |
167 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); | 167 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); |
168 CHECK_NE(NULL, rec); | 168 CHECK_NE(NULL, rec); |
169 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)); |
170 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 170 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
171 scq.FinishDequeue(); | 171 scq.FinishDequeue(); |
172 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 172 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
173 } | 173 } |
174 | 174 |
175 CHECK_EQ(NULL, scq.StartDequeue()); | 175 CHECK_EQ(NULL, scq.StartDequeue()); |
176 producer3.Start(); | 176 producer3.Start(); |
177 semaphore->Wait(); | 177 semaphore.Wait(); |
178 for (Record i = 20; i < 20 + kRecordsPerChunk; ++i) { | 178 for (Record i = 20; i < 20 + kRecordsPerChunk; ++i) { |
179 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); | 179 Record* rec = reinterpret_cast<Record*>(scq.StartDequeue()); |
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.StartDequeue())); | 182 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
183 scq.FinishDequeue(); | 183 scq.FinishDequeue(); |
184 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 184 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
185 } | 185 } |
186 | 186 |
187 CHECK_EQ(NULL, scq.StartDequeue()); | 187 CHECK_EQ(NULL, scq.StartDequeue()); |
188 | |
189 delete semaphore; | |
190 } | 188 } |
OLD | NEW |