Home | History | Annotate | Download | only in libplatform
      1 // Copyright 2013 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_LIBPLATFORM_DEFAULT_PLATFORM_H_
      6 #define V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
      7 
      8 #include <vector>
      9 
     10 #include "include/v8-platform.h"
     11 #include "src/base/macros.h"
     12 #include "src/platform/mutex.h"
     13 #include "src/libplatform/task-queue.h"
     14 
     15 namespace v8 {
     16 namespace internal {
     17 
     18 class TaskQueue;
     19 class Thread;
     20 class WorkerThread;
     21 
     22 class DefaultPlatform : public Platform {
     23  public:
     24   DefaultPlatform();
     25   virtual ~DefaultPlatform();
     26 
     27   void SetThreadPoolSize(int thread_pool_size);
     28 
     29   void EnsureInitialized();
     30 
     31   // v8::Platform implementation.
     32   virtual void CallOnBackgroundThread(
     33       Task *task, ExpectedRuntime expected_runtime) V8_OVERRIDE;
     34   virtual void CallOnForegroundThread(v8::Isolate *isolate,
     35                                       Task *task) V8_OVERRIDE;
     36 
     37  private:
     38   static const int kMaxThreadPoolSize;
     39 
     40   Mutex lock_;
     41   bool initialized_;
     42   int thread_pool_size_;
     43   std::vector<WorkerThread*> thread_pool_;
     44   TaskQueue queue_;
     45 
     46   DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
     47 };
     48 
     49 
     50 } }  // namespace v8::internal
     51 
     52 
     53 #endif  // V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
     54