summaryrefslogtreecommitdiff
path: root/deps/v8/src/libplatform/default-platform.h
blob: f887eb32e8ae9535ec9ff2b53f0fcef21afdccd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
#define V8_LIBPLATFORM_DEFAULT_PLATFORM_H_

#include <vector>

#include "../../include/v8-platform.h"
#include "../base/macros.h"
#include "../platform/mutex.h"
#include "task-queue.h"

namespace v8 {
namespace internal {

class TaskQueue;
class Thread;
class WorkerThread;

class DefaultPlatform : public Platform {
 public:
  DefaultPlatform();
  virtual ~DefaultPlatform();

  void SetThreadPoolSize(int thread_pool_size);

  void EnsureInitialized();

  // v8::Platform implementation.
  virtual void CallOnBackgroundThread(
      Task *task, ExpectedRuntime expected_runtime) V8_OVERRIDE;
  virtual void CallOnForegroundThread(v8::Isolate *isolate,
                                      Task *task) V8_OVERRIDE;

 private:
  static const int kMaxThreadPoolSize;

  Mutex lock_;
  bool initialized_;
  int thread_pool_size_;
  std::vector<WorkerThread*> thread_pool_;
  TaskQueue queue_;

  DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
};


} }  // namespace v8::internal


#endif  // V8_LIBPLATFORM_DEFAULT_PLATFORM_H_