| 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "src/v8.h" | 28 #include "src/v8.h" |
| 29 #include "test/cctest/cctest.h" | 29 #include "test/cctest/cctest.h" |
| 30 | 30 |
| 31 #include "src/base/platform/platform.h" | 31 #include "src/base/platform/platform.h" |
| 32 #include "src/isolate.h" | 32 #include "src/isolate.h" |
| 33 | 33 |
| 34 | 34 |
| 35 enum Turn { | 35 enum Turn { FILL_CACHE, CLEAN_CACHE, SECOND_TIME_FILL_CACHE, CACHE_DONE }; |
| 36 FILL_CACHE, | |
| 37 CLEAN_CACHE, | |
| 38 SECOND_TIME_FILL_CACHE, | |
| 39 DONE | |
| 40 }; | |
| 41 | 36 |
| 42 static Turn turn = FILL_CACHE; | 37 static Turn turn = FILL_CACHE; |
| 43 | 38 |
| 44 | 39 |
| 45 class ThreadA : public v8::base::Thread { | 40 class ThreadA : public v8::base::Thread { |
| 46 public: | 41 public: |
| 47 ThreadA() : Thread(Options("ThreadA")) {} | 42 ThreadA() : Thread(Options("ThreadA")) {} |
| 48 void Run() { | 43 void Run() { |
| 49 v8::Isolate* isolate = CcTest::isolate(); | 44 v8::Isolate* isolate = CcTest::isolate(); |
| 50 v8::Locker locker(isolate); | 45 v8::Locker locker(isolate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 69 turn = CLEAN_CACHE; | 64 turn = CLEAN_CACHE; |
| 70 do { | 65 do { |
| 71 { | 66 { |
| 72 v8::Unlocker unlocker(CcTest::isolate()); | 67 v8::Unlocker unlocker(CcTest::isolate()); |
| 73 } | 68 } |
| 74 } while (turn != SECOND_TIME_FILL_CACHE); | 69 } while (turn != SECOND_TIME_FILL_CACHE); |
| 75 | 70 |
| 76 // Rerun the script. | 71 // Rerun the script. |
| 77 CHECK(script->Run()->IsTrue()); | 72 CHECK(script->Run()->IsTrue()); |
| 78 | 73 |
| 79 turn = DONE; | 74 turn = CACHE_DONE; |
| 80 } | 75 } |
| 81 }; | 76 }; |
| 82 | 77 |
| 83 | 78 |
| 84 class ThreadB : public v8::base::Thread { | 79 class ThreadB : public v8::base::Thread { |
| 85 public: | 80 public: |
| 86 ThreadB() : Thread(Options("ThreadB")) {} | 81 ThreadB() : Thread(Options("ThreadB")) {} |
| 87 void Run() { | 82 void Run() { |
| 88 do { | 83 do { |
| 89 { | 84 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 109 TEST(JSFunctionResultCachesInTwoThreads) { | 104 TEST(JSFunctionResultCachesInTwoThreads) { |
| 110 ThreadA threadA; | 105 ThreadA threadA; |
| 111 ThreadB threadB; | 106 ThreadB threadB; |
| 112 | 107 |
| 113 threadA.Start(); | 108 threadA.Start(); |
| 114 threadB.Start(); | 109 threadB.Start(); |
| 115 | 110 |
| 116 threadA.Join(); | 111 threadA.Join(); |
| 117 threadB.Join(); | 112 threadB.Join(); |
| 118 | 113 |
| 119 CHECK_EQ(DONE, turn); | 114 CHECK_EQ(CACHE_DONE, turn); |
| 120 } | 115 } |
| 121 | 116 |
| 122 class ThreadIdValidationThread : public v8::base::Thread { | 117 class ThreadIdValidationThread : public v8::base::Thread { |
| 123 public: | 118 public: |
| 124 ThreadIdValidationThread(v8::base::Thread* thread_to_start, | 119 ThreadIdValidationThread(v8::base::Thread* thread_to_start, |
| 125 i::List<i::ThreadId>* refs, unsigned int thread_no, | 120 i::List<i::ThreadId>* refs, unsigned int thread_no, |
| 126 v8::base::Semaphore* semaphore) | 121 v8::base::Semaphore* semaphore) |
| 127 : Thread(Options("ThreadRefValidationThread")), | 122 : Thread(Options("ThreadRefValidationThread")), |
| 128 refs_(refs), | 123 refs_(refs), |
| 129 thread_no_(thread_no), | 124 thread_no_(thread_no), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 refs.Add(i::ThreadId::Invalid()); | 160 refs.Add(i::ThreadId::Invalid()); |
| 166 } | 161 } |
| 167 prev->Start(); | 162 prev->Start(); |
| 168 for (int i = 0; i < kNThreads; i++) { | 163 for (int i = 0; i < kNThreads; i++) { |
| 169 semaphore.Wait(); | 164 semaphore.Wait(); |
| 170 } | 165 } |
| 171 for (int i = 0; i < kNThreads; i++) { | 166 for (int i = 0; i < kNThreads; i++) { |
| 172 delete threads[i]; | 167 delete threads[i]; |
| 173 } | 168 } |
| 174 } | 169 } |
| OLD | NEW |