OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_BACKGROUND_PARSER_THREAD_H_ |
| 6 #define V8_BACKGROUND_PARSER_THREAD_H_ |
| 7 |
| 8 #include "src/base/platform/platform.h" |
| 9 #include "src/base/platform/semaphore.h" |
| 10 #include "src/compiler.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 |
| 15 class BackgroundParsingTask { |
| 16 public: |
| 17 BackgroundParsingTask(ScriptCompiler::StreamedSource* source, |
| 18 ScriptCompiler::StreamingCompleteCallback callback, |
| 19 void* callback_data, bool allow_lazy, Isolate* isolate) |
| 20 : source_(source), |
| 21 callback_(callback), |
| 22 callback_data_(callback_data), |
| 23 script_data_(NULL), |
| 24 hash_seed_(isolate->heap()->HashSeed()), |
| 25 allow_lazy_(allow_lazy), |
| 26 isolate_(isolate) {} |
| 27 |
| 28 void Run(); |
| 29 |
| 30 private: |
| 31 friend class v8::ScriptCompiler; |
| 32 |
| 33 ScriptCompiler::StreamedSource* source_; |
| 34 ScriptCompiler::StreamingCompleteCallback callback_; |
| 35 void* callback_data_; |
| 36 ScriptData* script_data_; |
| 37 uint32_t hash_seed_; |
| 38 bool allow_lazy_; |
| 39 Isolate* isolate_; |
| 40 }; |
| 41 |
| 42 |
| 43 // For compiling on the background. |
| 44 class BackgroundParserThread : public base::Thread { |
| 45 public: |
| 46 BackgroundParserThread(); |
| 47 |
| 48 virtual void Run(); |
| 49 |
| 50 void Stop(); |
| 51 // This can only be called after the previous task has finished. |
| 52 void SetTask(BackgroundParsingTask* task); |
| 53 |
| 54 bool HasTask() const { return task_ != NULL; } |
| 55 |
| 56 private: |
| 57 BackgroundParsingTask* task_; |
| 58 base::Semaphore have_work_; |
| 59 bool should_stop_; |
| 60 }; |
| 61 } |
| 62 } // namespace v8::internal |
| 63 |
| 64 #endif // V8_BACKGROUND_PARSER_THREAD_H_ |
OLD | NEW |