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
|
|
|
|
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(
|
2014-09-02 07:07:52 +00:00
|
|
|
Task* task, ExpectedRuntime expected_runtime) OVERRIDE;
|
2014-07-03 09:33:36 +00:00
|
|
|
virtual void CallOnForegroundThread(v8::Isolate* isolate,
|
2014-09-02 07:07:52 +00:00
|
|
|
Task* task) OVERRIDE;
|
2014-10-06 12:22:25 +00:00
|
|
|
virtual 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
|
|
|
|
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
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-01 08:15:09 +00:00
|
|
|
} } // namespace v8::platform
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#endif // V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
|