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.
|
2016-02-05 15:37:02 +00:00
|
|
|
size_t NumberOfAvailableBackgroundThreads() override;
|
2015-11-04 13:08:27 +00:00
|
|
|
void CallOnBackgroundThread(Task* task,
|
|
|
|
ExpectedRuntime expected_runtime) override;
|
|
|
|
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override;
|
|
|
|
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
|
|
|
double delay_in_seconds) override;
|
|
|
|
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override;
|
|
|
|
bool IdleTasksEnabled(Isolate* isolate) override;
|
2015-04-20 13:08:11 +00:00
|
|
|
double MonotonicallyIncreasingTime() override;
|
2015-12-17 18:48:07 +00:00
|
|
|
const uint8_t* GetCategoryGroupEnabled(const char* name) override;
|
|
|
|
const char* GetCategoryGroupName(
|
|
|
|
const uint8_t* category_enabled_flag) override;
|
2016-02-26 17:24:14 +00:00
|
|
|
uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
|
|
|
|
const char* name, const char* scope, uint64_t id,
|
|
|
|
uint64_t bind_id, int32_t num_args,
|
|
|
|
const char** arg_names, const uint8_t* arg_types,
|
|
|
|
const uint64_t* arg_values,
|
|
|
|
unsigned int flags) override;
|
2015-12-17 18:48:07 +00:00
|
|
|
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
|
|
|
|
const char* name, uint64_t handle) 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_
|