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.
5 #ifndef V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
6 #define V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
13 #include "include/v8-platform.h"
14 #include "src/base/macros.h"
15 #include "src/base/platform/mutex.h"
16 #include "src/libplatform/task-queue.h"
25 class DefaultPlatform : public Platform {
28 virtual ~DefaultPlatform();
30 void SetThreadPoolSize(int thread_pool_size);
32 void EnsureInitialized();
34 bool PumpMessageLoop(v8::Isolate* isolate);
36 // v8::Platform implementation.
37 virtual void CallOnBackgroundThread(
38 Task* task, ExpectedRuntime expected_runtime) override;
39 virtual void CallOnForegroundThread(v8::Isolate* isolate,
41 virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
42 double delay_in_seconds) override;
43 virtual void CallIdleOnForegroundThread(Isolate* isolate,
44 IdleTask* task) override;
45 virtual bool IdleTasksEnabled(Isolate* isolate) override;
46 double MonotonicallyIncreasingTime() override;
49 static const int kMaxThreadPoolSize;
51 Task* PopTaskInMainThreadQueue(v8::Isolate* isolate);
52 Task* PopTaskInMainThreadDelayedQueue(v8::Isolate* isolate);
56 int thread_pool_size_;
57 std::vector<WorkerThread*> thread_pool_;
59 std::map<v8::Isolate*, std::queue<Task*> > main_thread_queue_;
61 typedef std::pair<double, Task*> DelayedEntry;
62 std::map<v8::Isolate*,
63 std::priority_queue<DelayedEntry, std::vector<DelayedEntry>,
64 std::greater<DelayedEntry> > >
65 main_thread_delayed_queue_;
67 DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
71 } } // namespace v8::platform
74 #endif // V8_LIBPLATFORM_DEFAULT_PLATFORM_H_