| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_D8_H_ | 5 #ifndef V8_D8_H_ |
| 6 #define V8_D8_H_ | 6 #define V8_D8_H_ |
| 7 | 7 |
| 8 #ifndef V8_SHARED | 8 #ifndef V8_SHARED |
| 9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 i::List<SerializationData*> data_; | 233 i::List<SerializationData*> data_; |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 | 236 |
| 237 class Worker { | 237 class Worker { |
| 238 public: | 238 public: |
| 239 Worker(); | 239 Worker(); |
| 240 ~Worker(); | 240 ~Worker(); |
| 241 | 241 |
| 242 void StartExecuteInThread(Isolate* isolate, const char* script); | 242 void StartExecuteInThread(Isolate* isolate, const char* script); |
| 243 // Post a message to the worker's incoming message queue. The worker will |
| 244 // take ownership of the SerializationData. |
| 243 void PostMessage(SerializationData* data); | 245 void PostMessage(SerializationData* data); |
| 246 // Synchronously retrieve messages from the worker's outgoing message queue. |
| 247 // If there is no message in the queue, block until a message is available. |
| 248 // If there are no messages in the queue and the worker is no longer running, |
| 249 // return nullptr. |
| 244 SerializationData* GetMessage(); | 250 SerializationData* GetMessage(); |
| 251 // Terminate the worker's event loop. Messages from the worker that have been |
| 252 // queued can still be read via GetMessage(). |
| 245 void Terminate(); | 253 void Terminate(); |
| 254 // Terminate and join the thread. |
| 255 void WaitForThread(); |
| 246 | 256 |
| 247 private: | 257 private: |
| 248 class WorkerThread : public base::Thread { | 258 class WorkerThread : public base::Thread { |
| 249 public: | 259 public: |
| 250 explicit WorkerThread(Worker* worker) | 260 explicit WorkerThread(Worker* worker) |
| 251 : base::Thread(base::Thread::Options("WorkerThread")), | 261 : base::Thread(base::Thread::Options("WorkerThread")), |
| 252 worker_(worker) {} | 262 worker_(worker) {} |
| 253 | 263 |
| 254 virtual void Run() { worker_->ExecuteInThread(); } | 264 virtual void Run() { worker_->ExecuteInThread(); } |
| 255 | 265 |
| 256 private: | 266 private: |
| 257 Worker* worker_; | 267 Worker* worker_; |
| 258 }; | 268 }; |
| 259 | 269 |
| 260 enum State { IDLE, RUNNING, TERMINATED }; | 270 enum State { |
| 271 IDLE, // The worker thread hasn't been started yet |
| 272 RUNNING, // The worker thread is running and hasn't been terminated |
| 273 TERMINATED // The worker thread has been terminated and will soon finish |
| 274 }; |
| 261 | 275 |
| 262 void ExecuteInThread(); | 276 void ExecuteInThread(); |
| 263 void Cleanup(); | 277 void Cleanup(); |
| 264 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args); | 278 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 265 | 279 |
| 266 base::Semaphore in_semaphore_; | 280 base::Semaphore in_semaphore_; |
| 267 base::Semaphore out_semaphore_; | 281 base::Semaphore out_semaphore_; |
| 268 SerializationDataQueue in_queue_; | 282 SerializationDataQueue in_queue_; |
| 269 SerializationDataQueue out_queue_; | 283 SerializationDataQueue out_queue_; |
| 270 base::Thread* thread_; | 284 base::Thread* thread_; |
| 271 char* script_; | 285 char* script_; |
| 272 base::Atomic32 state_; | 286 base::Atomic32 state_; |
| 287 base::Atomic32 join_called_; |
| 273 }; | 288 }; |
| 274 #endif // !V8_SHARED | 289 #endif // !V8_SHARED |
| 275 | 290 |
| 276 | 291 |
| 277 class ShellOptions { | 292 class ShellOptions { |
| 278 public: | 293 public: |
| 279 ShellOptions() | 294 ShellOptions() |
| 280 : script_executed(false), | 295 : script_executed(false), |
| 281 last_run(true), | 296 last_run(true), |
| 282 send_idle_notification(false), | 297 send_idle_notification(false), |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 static void RunShell(Isolate* isolate); | 493 static void RunShell(Isolate* isolate); |
| 479 static bool SetOptions(int argc, char* argv[]); | 494 static bool SetOptions(int argc, char* argv[]); |
| 480 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); | 495 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); |
| 481 }; | 496 }; |
| 482 | 497 |
| 483 | 498 |
| 484 } // namespace v8 | 499 } // namespace v8 |
| 485 | 500 |
| 486 | 501 |
| 487 #endif // V8_D8_H_ | 502 #endif // V8_D8_H_ |
| OLD | NEW |