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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 "}" | 122 "}" |
123 "fib(10)"); | 123 "fib(10)"); |
124 CHECK(v->IsNumber()); | 124 CHECK(v->IsNumber()); |
125 CHECK_EQ(55, static_cast<int>(v->NumberValue())); | 125 CHECK_EQ(55, static_cast<int>(v->NumberValue())); |
126 } | 126 } |
127 | 127 |
128 class JoinableThread { | 128 class JoinableThread { |
129 public: | 129 public: |
130 explicit JoinableThread(const char* name) | 130 explicit JoinableThread(const char* name) |
131 : name_(name), | 131 : name_(name), |
132 semaphore_(i::OS::CreateSemaphore(0)), | 132 semaphore_(0), |
133 thread_(this) { | 133 thread_(this) { |
134 } | 134 } |
135 | 135 |
136 virtual ~JoinableThread() { | 136 virtual ~JoinableThread() {} |
137 delete semaphore_; | |
138 } | |
139 | 137 |
140 void Start() { | 138 void Start() { |
141 thread_.Start(); | 139 thread_.Start(); |
142 } | 140 } |
143 | 141 |
144 void Join() { | 142 void Join() { |
145 semaphore_->Wait(); | 143 semaphore_.Wait(); |
146 } | 144 } |
147 | 145 |
148 virtual void Run() = 0; | 146 virtual void Run() = 0; |
149 | 147 |
150 private: | 148 private: |
151 class ThreadWithSemaphore : public i::Thread { | 149 class ThreadWithSemaphore : public i::Thread { |
152 public: | 150 public: |
153 explicit ThreadWithSemaphore(JoinableThread* joinable_thread) | 151 explicit ThreadWithSemaphore(JoinableThread* joinable_thread) |
154 : Thread(joinable_thread->name_), | 152 : Thread(joinable_thread->name_), |
155 joinable_thread_(joinable_thread) { | 153 joinable_thread_(joinable_thread) { |
156 } | 154 } |
157 | 155 |
158 virtual void Run() { | 156 virtual void Run() { |
159 joinable_thread_->Run(); | 157 joinable_thread_->Run(); |
160 joinable_thread_->semaphore_->Signal(); | 158 joinable_thread_->semaphore_.Signal(); |
161 } | 159 } |
162 | 160 |
163 private: | 161 private: |
164 JoinableThread* joinable_thread_; | 162 JoinableThread* joinable_thread_; |
165 }; | 163 }; |
166 | 164 |
167 const char* name_; | 165 const char* name_; |
168 i::Semaphore* semaphore_; | 166 i::Semaphore semaphore_; |
169 ThreadWithSemaphore thread_; | 167 ThreadWithSemaphore thread_; |
170 | 168 |
171 friend class ThreadWithSemaphore; | 169 friend class ThreadWithSemaphore; |
172 | 170 |
173 DISALLOW_COPY_AND_ASSIGN(JoinableThread); | 171 DISALLOW_COPY_AND_ASSIGN(JoinableThread); |
174 }; | 172 }; |
175 | 173 |
176 | 174 |
177 class IsolateLockingThreadWithLocalContext : public JoinableThread { | 175 class IsolateLockingThreadWithLocalContext : public JoinableThread { |
178 public: | 176 public: |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 kSimpleExtensionSource)); | 731 kSimpleExtensionSource)); |
734 const char* extension_names[] = { "test0", "test1", | 732 const char* extension_names[] = { "test0", "test1", |
735 "test2", "test3", "test4", | 733 "test2", "test3", "test4", |
736 "test5", "test6", "test7" }; | 734 "test5", "test6", "test7" }; |
737 i::List<JoinableThread*> threads(kNThreads); | 735 i::List<JoinableThread*> threads(kNThreads); |
738 for (int i = 0; i < kNThreads; i++) { | 736 for (int i = 0; i < kNThreads; i++) { |
739 threads.Add(new IsolateGenesisThread(8, extension_names)); | 737 threads.Add(new IsolateGenesisThread(8, extension_names)); |
740 } | 738 } |
741 StartJoinAndDeleteThreads(threads); | 739 StartJoinAndDeleteThreads(threads); |
742 } | 740 } |
OLD | NEW |