| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 enum Turn { | 56 enum Turn { |
| 57 FILL_CACHE, | 57 FILL_CACHE, |
| 58 CLEAN_CACHE, | 58 CLEAN_CACHE, |
| 59 SECOND_TIME_FILL_CACHE, | 59 SECOND_TIME_FILL_CACHE, |
| 60 DONE | 60 DONE |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 static Turn turn = FILL_CACHE; | 63 static Turn turn = FILL_CACHE; |
| 64 | 64 |
| 65 | 65 |
| 66 class ThreadA: public v8::internal::Thread { | 66 class ThreadA : public v8::internal::Thread { |
| 67 public: | 67 public: |
| 68 ThreadA() : Thread("ThreadA") { } | 68 ThreadA() : Thread("ThreadA") { } |
| 69 void Run() { | 69 void Run() { |
| 70 v8::Locker locker; | 70 v8::Locker locker; |
| 71 v8::HandleScope scope; | 71 v8::HandleScope scope; |
| 72 v8::Context::Scope context_scope(v8::Context::New()); | 72 v8::Context::Scope context_scope(v8::Context::New()); |
| 73 | 73 |
| 74 CHECK_EQ(FILL_CACHE, turn); | 74 CHECK_EQ(FILL_CACHE, turn); |
| 75 | 75 |
| 76 // Fill String.search cache. | 76 // Fill String.search cache. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 92 } while (turn != SECOND_TIME_FILL_CACHE); | 92 } while (turn != SECOND_TIME_FILL_CACHE); |
| 93 | 93 |
| 94 // Rerun the script. | 94 // Rerun the script. |
| 95 CHECK(script->Run()->IsTrue()); | 95 CHECK(script->Run()->IsTrue()); |
| 96 | 96 |
| 97 turn = DONE; | 97 turn = DONE; |
| 98 } | 98 } |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 | 101 |
| 102 class ThreadB: public v8::internal::Thread { | 102 class ThreadB : public v8::internal::Thread { |
| 103 public: | 103 public: |
| 104 ThreadB() : Thread("ThreadB") { } | 104 ThreadB() : Thread("ThreadB") { } |
| 105 void Run() { | 105 void Run() { |
| 106 do { | 106 do { |
| 107 { | 107 { |
| 108 v8::Locker locker; | 108 v8::Locker locker; |
| 109 if (turn == CLEAN_CACHE) { | 109 if (turn == CLEAN_CACHE) { |
| 110 v8::HandleScope scope; | 110 v8::HandleScope scope; |
| 111 v8::Context::Scope context_scope(v8::Context::New()); | 111 v8::Context::Scope context_scope(v8::Context::New()); |
| 112 | 112 |
| 113 // Clear the caches by forcing major GC. | 113 // Clear the caches by forcing major GC. |
| 114 HEAP->CollectAllGarbage(false); | 114 HEAP->CollectAllGarbage(v8::internal::Heap::kNoGCFlags); |
| 115 turn = SECOND_TIME_FILL_CACHE; | 115 turn = SECOND_TIME_FILL_CACHE; |
| 116 break; | 116 break; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 Thread::YieldCPU(); | 120 Thread::YieldCPU(); |
| 121 } while (true); | 121 } while (true); |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 refs.Add(i::ThreadId::Invalid()); | 183 refs.Add(i::ThreadId::Invalid()); |
| 184 } | 184 } |
| 185 prev->Start(); | 185 prev->Start(); |
| 186 for (int i = 0; i < kNThreads; i++) { | 186 for (int i = 0; i < kNThreads; i++) { |
| 187 semaphore->Wait(); | 187 semaphore->Wait(); |
| 188 } | 188 } |
| 189 for (int i = 0; i < kNThreads; i++) { | 189 for (int i = 0; i < kNThreads; i++) { |
| 190 delete threads[i]; | 190 delete threads[i]; |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 |
| 194 |
| 195 class ThreadC : public v8::internal::Thread { |
| 196 public: |
| 197 ThreadC() : Thread("ThreadC") { } |
| 198 void Run() { |
| 199 Join(); |
| 200 } |
| 201 }; |
| 202 |
| 203 |
| 204 TEST(ThreadJoinSelf) { |
| 205 ThreadC thread; |
| 206 thread.Start(); |
| 207 thread.Join(); |
| 208 } |
| OLD | NEW |