OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 int thread_no_; | 152 int thread_no_; |
153 i::Thread* thread_to_start_; | 153 i::Thread* thread_to_start_; |
154 i::Semaphore* semaphore_; | 154 i::Semaphore* semaphore_; |
155 }; | 155 }; |
156 | 156 |
157 | 157 |
158 TEST(ThreadIdValidation) { | 158 TEST(ThreadIdValidation) { |
159 const int kNThreads = 100; | 159 const int kNThreads = 100; |
160 i::List<ThreadIdValidationThread*> threads(kNThreads); | 160 i::List<ThreadIdValidationThread*> threads(kNThreads); |
161 i::List<i::ThreadId> refs(kNThreads); | 161 i::List<i::ThreadId> refs(kNThreads); |
162 i::Semaphore* semaphore = new i::Semaphore(0); | 162 i::Semaphore semaphore(0); |
163 ThreadIdValidationThread* prev = NULL; | 163 ThreadIdValidationThread* prev = NULL; |
164 for (int i = kNThreads - 1; i >= 0; i--) { | 164 for (int i = kNThreads - 1; i >= 0; i--) { |
165 ThreadIdValidationThread* newThread = | 165 ThreadIdValidationThread* newThread = |
166 new ThreadIdValidationThread(prev, &refs, i, semaphore); | 166 new ThreadIdValidationThread(prev, &refs, i, &semaphore); |
167 threads.Add(newThread); | 167 threads.Add(newThread); |
168 prev = newThread; | 168 prev = newThread; |
169 refs.Add(i::ThreadId::Invalid()); | 169 refs.Add(i::ThreadId::Invalid()); |
170 } | 170 } |
171 prev->Start(); | 171 prev->Start(); |
172 for (int i = 0; i < kNThreads; i++) { | 172 for (int i = 0; i < kNThreads; i++) { |
173 semaphore->Wait(); | 173 semaphore.Wait(); |
174 } | 174 } |
175 for (int i = 0; i < kNThreads; i++) { | 175 for (int i = 0; i < kNThreads; i++) { |
176 delete threads[i]; | 176 delete threads[i]; |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 class ThreadC : public v8::internal::Thread { | 181 class ThreadC : public v8::internal::Thread { |
182 public: | 182 public: |
183 ThreadC() : Thread("ThreadC") { } | 183 ThreadC() : Thread("ThreadC") { } |
184 void Run() { | 184 void Run() { |
185 Join(); | 185 Join(); |
186 } | 186 } |
187 }; | 187 }; |
188 | 188 |
189 | 189 |
190 TEST(ThreadJoinSelf) { | 190 TEST(ThreadJoinSelf) { |
191 ThreadC thread; | 191 ThreadC thread; |
192 thread.Start(); | 192 thread.Start(); |
193 thread.Join(); | 193 thread.Join(); |
194 } | 194 } |
OLD | NEW |