default-platform.h 1.41 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
#define V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
7

8 9
#include <map>
#include <queue>
10 11
#include <vector>

12 13
#include "include/v8-platform.h"
#include "src/base/macros.h"
14
#include "src/base/platform/mutex.h"
15
#include "src/libplatform/task-queue.h"
16 17

namespace v8 {
18
namespace platform {
19

20 21 22 23
class TaskQueue;
class Thread;
class WorkerThread;

24 25 26 27 28
class DefaultPlatform : public Platform {
 public:
  DefaultPlatform();
  virtual ~DefaultPlatform();

29 30
  void SetThreadPoolSize(int thread_pool_size);

31 32
  void EnsureInitialized();

33 34
  bool PumpMessageLoop(v8::Isolate* isolate);

35 36
  // v8::Platform implementation.
  virtual void CallOnBackgroundThread(
37
      Task* task, ExpectedRuntime expected_runtime) OVERRIDE;
38
  virtual void CallOnForegroundThread(v8::Isolate* isolate,
39
                                      Task* task) OVERRIDE;
40
  double MonotonicallyIncreasingTime() OVERRIDE;
41 42

 private:
43
  static const int kMaxThreadPoolSize;
44

45
  base::Mutex lock_;
46
  bool initialized_;
47
  int thread_pool_size_;
48 49
  std::vector<WorkerThread*> thread_pool_;
  TaskQueue queue_;
50
  std::map<v8::Isolate*, std::queue<Task*> > main_thread_queue_;
51

52 53 54 55
  DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
};


56
} }  // namespace v8::platform
57 58


59
#endif  // V8_LIBPLATFORM_DEFAULT_PLATFORM_H_