2013-11-21 14:07:06 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#ifndef V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
|
|
|
|
#define V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2015-06-17 12:09:34 +00:00
|
|
|
#include <functional>
|
2014-07-03 09:33:36 +00:00
|
|
|
#include <map>
|
|
|
|
#include <queue>
|
2013-12-20 07:52:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "include/v8-platform.h"
|
|
|
|
#include "src/base/macros.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/mutex.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/libplatform/task-queue.h"
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
2014-07-01 08:15:09 +00:00
|
|
|
namespace platform {
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
class TaskQueue;
|
|
|
|
class Thread;
|
|
|
|
class WorkerThread;
|
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
class DefaultPlatform : public Platform {
|
|
|
|
public:
|
|
|
|
DefaultPlatform();
|
|
|
|
virtual ~DefaultPlatform();
|
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
void SetThreadPoolSize(int thread_pool_size);
|
|
|
|
|
2014-02-20 19:32:27 +00:00
|
|
|
void EnsureInitialized();
|
|
|
|
|
2014-07-03 09:33:36 +00:00
|
|
|
bool PumpMessageLoop(v8::Isolate* isolate);
|
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
// v8::Platform implementation.
|
|
|
|
virtual void CallOnBackgroundThread(
|
2015-04-20 13:08:11 +00:00
|
|
|
Task* task, ExpectedRuntime expected_runtime) override;
|
2014-07-03 09:33:36 +00:00
|
|
|
virtual void CallOnForegroundThread(v8::Isolate* isolate,
|
2015-04-20 13:08:11 +00:00
|
|
|
Task* task) override;
|
2015-06-17 12:09:34 +00:00
|
|
|
virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
|
|
|
double delay_in_seconds) override;
|
2015-07-15 11:50:48 +00:00
|
|
|
virtual void CallIdleOnForegroundThread(Isolate* isolate,
|
|
|
|
IdleTask* task) override;
|
|
|
|
virtual bool IdleTasksEnabled(Isolate* isolate) override;
|
2015-04-20 13:08:11 +00:00
|
|
|
double MonotonicallyIncreasingTime() override;
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-25 13:43:58 +00:00
|
|
|
static const int kMaxThreadPoolSize;
|
2013-12-20 07:52:58 +00:00
|
|
|
|
2015-06-17 12:09:34 +00:00
|
|
|
Task* PopTaskInMainThreadQueue(v8::Isolate* isolate);
|
|
|
|
Task* PopTaskInMainThreadDelayedQueue(v8::Isolate* isolate);
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Mutex lock_;
|
2013-12-20 07:52:58 +00:00
|
|
|
bool initialized_;
|
2013-12-20 08:34:42 +00:00
|
|
|
int thread_pool_size_;
|
2013-12-20 07:52:58 +00:00
|
|
|
std::vector<WorkerThread*> thread_pool_;
|
|
|
|
TaskQueue queue_;
|
2014-07-03 09:33:36 +00:00
|
|
|
std::map<v8::Isolate*, std::queue<Task*> > main_thread_queue_;
|
2013-12-20 07:52:58 +00:00
|
|
|
|
2015-06-17 12:09:34 +00:00
|
|
|
typedef std::pair<double, Task*> DelayedEntry;
|
|
|
|
std::map<v8::Isolate*,
|
|
|
|
std::priority_queue<DelayedEntry, std::vector<DelayedEntry>,
|
|
|
|
std::greater<DelayedEntry> > >
|
|
|
|
main_thread_delayed_queue_;
|
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace platform
|
|
|
|
} // namespace v8
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#endif // V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
|