OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4671 // k'th time, then all calls return. Each ThreadBarrier object can only | 4671 // k'th time, then all calls return. Each ThreadBarrier object can only |
4672 // be used once. | 4672 // be used once. |
4673 class ThreadBarrier { | 4673 class ThreadBarrier { |
4674 public: | 4674 public: |
4675 explicit ThreadBarrier(int num_threads); | 4675 explicit ThreadBarrier(int num_threads); |
4676 ~ThreadBarrier(); | 4676 ~ThreadBarrier(); |
4677 void Wait(); | 4677 void Wait(); |
4678 private: | 4678 private: |
4679 int num_threads_; | 4679 int num_threads_; |
4680 int num_blocked_; | 4680 int num_blocked_; |
4681 v8::internal::Mutex* lock_; | 4681 v8::internal::Mutex lock_; |
4682 v8::internal::Semaphore* sem_; | 4682 v8::internal::Semaphore* sem_; |
4683 bool invalid_; | 4683 bool invalid_; |
4684 }; | 4684 }; |
4685 | 4685 |
4686 ThreadBarrier::ThreadBarrier(int num_threads) | 4686 ThreadBarrier::ThreadBarrier(int num_threads) |
4687 : num_threads_(num_threads), num_blocked_(0) { | 4687 : num_threads_(num_threads), num_blocked_(0) { |
4688 lock_ = OS::CreateMutex(); | |
4689 sem_ = OS::CreateSemaphore(0); | 4688 sem_ = OS::CreateSemaphore(0); |
4690 invalid_ = false; // A barrier may only be used once. Then it is invalid. | 4689 invalid_ = false; // A barrier may only be used once. Then it is invalid. |
4691 } | 4690 } |
4692 | 4691 |
4693 | 4692 |
4694 // Do not call, due to race condition with Wait(). | 4693 // Do not call, due to race condition with Wait(). |
4695 // Could be resolved with Pthread condition variables. | 4694 // Could be resolved with Pthread condition variables. |
4696 ThreadBarrier::~ThreadBarrier() { | 4695 ThreadBarrier::~ThreadBarrier() { |
4697 lock_->Lock(); | |
4698 delete lock_; | |
4699 delete sem_; | 4696 delete sem_; |
4700 } | 4697 } |
4701 | 4698 |
4702 | 4699 |
4703 void ThreadBarrier::Wait() { | 4700 void ThreadBarrier::Wait() { |
4704 lock_->Lock(); | 4701 lock_.Lock(); |
4705 CHECK(!invalid_); | 4702 CHECK(!invalid_); |
4706 if (num_blocked_ == num_threads_ - 1) { | 4703 if (num_blocked_ == num_threads_ - 1) { |
4707 // Signal and unblock all waiting threads. | 4704 // Signal and unblock all waiting threads. |
4708 for (int i = 0; i < num_threads_ - 1; ++i) { | 4705 for (int i = 0; i < num_threads_ - 1; ++i) { |
4709 sem_->Signal(); | 4706 sem_->Signal(); |
4710 } | 4707 } |
4711 invalid_ = true; | 4708 invalid_ = true; |
4712 printf("BARRIER\n\n"); | 4709 printf("BARRIER\n\n"); |
4713 fflush(stdout); | 4710 fflush(stdout); |
4714 lock_->Unlock(); | 4711 lock_.Unlock(); |
4715 } else { // Wait for the semaphore. | 4712 } else { // Wait for the semaphore. |
4716 ++num_blocked_; | 4713 ++num_blocked_; |
4717 lock_->Unlock(); // Potential race condition with destructor because | 4714 lock_.Unlock(); // Potential race condition with destructor because |
4718 sem_->Wait(); // these two lines are not atomic. | 4715 sem_->Wait(); // these two lines are not atomic. |
4719 } | 4716 } |
4720 } | 4717 } |
4721 | 4718 |
4722 | 4719 |
4723 // A set containing enough barriers and semaphores for any of the tests. | 4720 // A set containing enough barriers and semaphores for any of the tests. |
4724 class Barriers { | 4721 class Barriers { |
4725 public: | 4722 public: |
4726 Barriers(); | 4723 Barriers(); |
4727 void Initialize(); | 4724 void Initialize(); |
(...skipping 2825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7553 TEST(LiveEditDisabled) { | 7550 TEST(LiveEditDisabled) { |
7554 v8::internal::FLAG_allow_natives_syntax = true; | 7551 v8::internal::FLAG_allow_natives_syntax = true; |
7555 LocalContext env; | 7552 LocalContext env; |
7556 v8::HandleScope scope(env->GetIsolate()); | 7553 v8::HandleScope scope(env->GetIsolate()); |
7557 v8::Debug::SetLiveEditEnabled(false); | 7554 v8::Debug::SetLiveEditEnabled(false); |
7558 CompileRun("%LiveEditCompareStrings('', '')"); | 7555 CompileRun("%LiveEditCompareStrings('', '')"); |
7559 } | 7556 } |
7560 | 7557 |
7561 | 7558 |
7562 #endif // ENABLE_DEBUGGER_SUPPORT | 7559 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |