| OLD | NEW |
| 1 // Copyright 2007-2011 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2011 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 | 135 |
| 136 void Start() { | 136 void Start() { |
| 137 thread_.Start(); | 137 thread_.Start(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void Join() { | 140 void Join() { |
| 141 semaphore_->Wait(); | 141 semaphore_->Wait(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 virtual void Run() = 0; | 144 virtual void Run() = 0; |
| 145 |
| 145 private: | 146 private: |
| 146 class ThreadWithSemaphore : public i::Thread { | 147 class ThreadWithSemaphore : public i::Thread { |
| 147 public: | 148 public: |
| 148 explicit ThreadWithSemaphore(JoinableThread* joinable_thread) | 149 explicit ThreadWithSemaphore(JoinableThread* joinable_thread) |
| 149 : Thread(joinable_thread->name_), | 150 : Thread(joinable_thread->name_), |
| 150 joinable_thread_(joinable_thread) { | 151 joinable_thread_(joinable_thread) { |
| 151 } | 152 } |
| 152 | 153 |
| 153 virtual void Run() { | 154 virtual void Run() { |
| 154 joinable_thread_->Run(); | 155 joinable_thread_->Run(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); | 371 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
| 371 thread.Start(); | 372 thread.Start(); |
| 372 thread.Join(); | 373 thread.Join(); |
| 373 } | 374 } |
| 374 isolate_->Enter(); | 375 isolate_->Enter(); |
| 375 { | 376 { |
| 376 v8::Context::Scope context_scope(context); | 377 v8::Context::Scope context_scope(context); |
| 377 CalcFibAndCheck(); | 378 CalcFibAndCheck(); |
| 378 } | 379 } |
| 379 } | 380 } |
| 381 |
| 380 private: | 382 private: |
| 381 v8::Isolate* isolate_; | 383 v8::Isolate* isolate_; |
| 382 }; | 384 }; |
| 383 | 385 |
| 384 // Use unlocker inside of a Locker, multiple threads. | 386 // Use unlocker inside of a Locker, multiple threads. |
| 385 TEST(LockerUnlocker) { | 387 TEST(LockerUnlocker) { |
| 386 #ifdef V8_TARGET_ARCH_ARM | 388 #ifdef V8_TARGET_ARCH_ARM |
| 387 const int kNThreads = 50; | 389 const int kNThreads = 50; |
| 388 #else | 390 #else |
| 389 const int kNThreads = 100; | 391 const int kNThreads = 100; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 thread.Start(); | 424 thread.Start(); |
| 423 thread.Join(); | 425 thread.Join(); |
| 424 } | 426 } |
| 425 } | 427 } |
| 426 isolate_->Enter(); | 428 isolate_->Enter(); |
| 427 { | 429 { |
| 428 v8::Context::Scope context_scope(context); | 430 v8::Context::Scope context_scope(context); |
| 429 CalcFibAndCheck(); | 431 CalcFibAndCheck(); |
| 430 } | 432 } |
| 431 } | 433 } |
| 434 |
| 432 private: | 435 private: |
| 433 v8::Isolate* isolate_; | 436 v8::Isolate* isolate_; |
| 434 }; | 437 }; |
| 435 | 438 |
| 436 // Use Unlocker inside two Lockers. | 439 // Use Unlocker inside two Lockers. |
| 437 TEST(LockTwiceAndUnlock) { | 440 TEST(LockTwiceAndUnlock) { |
| 438 #ifdef V8_TARGET_ARCH_ARM | 441 #ifdef V8_TARGET_ARCH_ARM |
| 439 const int kNThreads = 50; | 442 const int kNThreads = 50; |
| 440 #else | 443 #else |
| 441 const int kNThreads = 100; | 444 const int kNThreads = 100; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 CHECK(v8::Locker::IsLocked(isolate2_)); | 494 CHECK(v8::Locker::IsLocked(isolate2_)); |
| 492 v8::Isolate::Scope isolate_scope(isolate2_); | 495 v8::Isolate::Scope isolate_scope(isolate2_); |
| 493 v8::HandleScope handle_scope; | 496 v8::HandleScope handle_scope; |
| 494 v8::Context::Scope context_scope(context2); | 497 v8::Context::Scope context_scope(context2); |
| 495 LockIsolateAndCalculateFibSharedContextThread thread(isolate1_, context1); | 498 LockIsolateAndCalculateFibSharedContextThread thread(isolate1_, context1); |
| 496 thread.Start(); | 499 thread.Start(); |
| 497 CalcFibAndCheck(); | 500 CalcFibAndCheck(); |
| 498 thread.Join(); | 501 thread.Join(); |
| 499 } | 502 } |
| 500 } | 503 } |
| 504 |
| 501 private: | 505 private: |
| 502 v8::Isolate* isolate1_; | 506 v8::Isolate* isolate1_; |
| 503 v8::Isolate* isolate2_; | 507 v8::Isolate* isolate2_; |
| 504 }; | 508 }; |
| 505 | 509 |
| 506 // Lock two isolates and unlock one of them. | 510 // Lock two isolates and unlock one of them. |
| 507 TEST(LockAndUnlockDifferentIsolates) { | 511 TEST(LockAndUnlockDifferentIsolates) { |
| 508 v8::Isolate* isolate1 = v8::Isolate::New(); | 512 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 509 v8::Isolate* isolate2 = v8::Isolate::New(); | 513 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 510 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); | 514 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 v8::Context::Scope context_scope(context); | 632 v8::Context::Scope context_scope(context); |
| 629 v8::Handle<String> source = v8::String::New("1+1"); | 633 v8::Handle<String> source = v8::String::New("1+1"); |
| 630 v8::Handle<Script> script = v8::Script::Compile(source); | 634 v8::Handle<Script> script = v8::Script::Compile(source); |
| 631 v8::Handle<Value> result = script->Run(); | 635 v8::Handle<Value> result = script->Run(); |
| 632 v8::String::AsciiValue ascii(result); | 636 v8::String::AsciiValue ascii(result); |
| 633 context.Dispose(); | 637 context.Dispose(); |
| 634 } | 638 } |
| 635 isolate->Dispose(); | 639 isolate->Dispose(); |
| 636 } | 640 } |
| 637 } | 641 } |
| OLD | NEW |