Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: test/cctest/test-thread-termination.cc

Issue 23748003: Cleanup Semaphore class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Build fix for Mac OS X. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-sockets.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 private: 166 private:
167 v8::Isolate* isolate_; 167 v8::Isolate* isolate_;
168 }; 168 };
169 169
170 170
171 // Test that a single thread of JavaScript execution can be terminated 171 // Test that a single thread of JavaScript execution can be terminated
172 // from the side by another thread. 172 // from the side by another thread.
173 TEST(TerminateOnlyV8ThreadFromOtherThread) { 173 TEST(TerminateOnlyV8ThreadFromOtherThread) {
174 semaphore = v8::internal::OS::CreateSemaphore(0); 174 semaphore = new v8::internal::Semaphore(0);
175 TerminatorThread thread(i::Isolate::Current()); 175 TerminatorThread thread(i::Isolate::Current());
176 thread.Start(); 176 thread.Start();
177 177
178 v8::HandleScope scope(v8::Isolate::GetCurrent()); 178 v8::HandleScope scope(v8::Isolate::GetCurrent());
179 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop); 179 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop);
180 v8::Handle<v8::Context> context = 180 v8::Handle<v8::Context> context =
181 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); 181 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
182 v8::Context::Scope context_scope(context); 182 v8::Context::Scope context_scope(context);
183 CHECK(!v8::V8::IsExecutionTerminating()); 183 CHECK(!v8::V8::IsExecutionTerminating());
184 // Run a loop that will be infinite if thread termination does not work. 184 // Run a loop that will be infinite if thread termination does not work.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 }; 218 };
219 219
220 220
221 // Test that multiple threads using default isolate can be terminated 221 // Test that multiple threads using default isolate can be terminated
222 // from another thread when using Lockers and preemption. 222 // from another thread when using Lockers and preemption.
223 TEST(TerminateMultipleV8ThreadsDefaultIsolate) { 223 TEST(TerminateMultipleV8ThreadsDefaultIsolate) {
224 { 224 {
225 v8::Locker locker(CcTest::default_isolate()); 225 v8::Locker locker(CcTest::default_isolate());
226 v8::V8::Initialize(); 226 v8::V8::Initialize();
227 v8::Locker::StartPreemption(1); 227 v8::Locker::StartPreemption(1);
228 semaphore = v8::internal::OS::CreateSemaphore(0); 228 semaphore = new v8::internal::Semaphore(0);
229 } 229 }
230 const int kThreads = 2; 230 const int kThreads = 2;
231 i::List<LoopingThread*> threads(kThreads); 231 i::List<LoopingThread*> threads(kThreads);
232 for (int i = 0; i < kThreads; i++) { 232 for (int i = 0; i < kThreads; i++) {
233 threads.Add(new LoopingThread()); 233 threads.Add(new LoopingThread());
234 } 234 }
235 for (int i = 0; i < kThreads; i++) { 235 for (int i = 0; i < kThreads; i++) {
236 threads[i]->Start(); 236 threads[i]->Start();
237 } 237 }
238 // Wait until all threads have signaled the semaphore. 238 // Wait until all threads have signaled the semaphore.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 v8::Handle<v8::Context> context = 397 v8::Handle<v8::Context> context =
398 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); 398 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
399 v8::Context::Scope context_scope(context); 399 v8::Context::Scope context_scope(context);
400 CHECK(!v8::V8::IsExecutionTerminating()); 400 CHECK(!v8::V8::IsExecutionTerminating());
401 v8::Handle<v8::String> source = 401 v8::Handle<v8::String> source =
402 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';"); 402 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';");
403 // Check that execution completed with correct return value. 403 // Check that execution completed with correct return value.
404 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); 404 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
405 } 405 }
406 406
OLDNEW
« no previous file with comments | « test/cctest/test-sockets.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698