forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gin] Add a v8::Platform implementation to allow for v8 posting tasks
This currently has no effect unless concurrent sweeping and job based sweeping is turned on in v8. BUG=v8:3015 R=abarth@chromium.org,dcarney@chromium.org Review URL: https://codereview.chromium.org/225413004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261872 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
jochen@chromium.org
committed
Apr 4, 2014
1 parent
4df54e8
commit b64e521
Showing
7 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2014 The Chromium 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 GIN_PUBLIC_V8_PLATFORM_H_ | ||
#define GIN_PUBLIC_V8_PLATFORM_H_ | ||
|
||
#include "base/basictypes.h" | ||
#include "base/compiler_specific.h" | ||
#include "base/lazy_instance.h" | ||
#include "gin/gin_export.h" | ||
#include "v8/include/v8-platform.h" | ||
|
||
namespace gin { | ||
|
||
// A v8::Platform implementation to use with gin. | ||
class GIN_EXPORT V8Platform : public NON_EXPORTED_BASE(v8::Platform) { | ||
public: | ||
static V8Platform* Get(); | ||
|
||
// v8::Platform implementation. | ||
virtual void CallOnBackgroundThread( | ||
v8::Task* task, | ||
v8::Platform::ExpectedRuntime expected_runtime) OVERRIDE; | ||
virtual void CallOnForegroundThread(v8::Isolate* isolate, | ||
v8::Task* task) OVERRIDE; | ||
private: | ||
friend struct base::DefaultLazyInstanceTraits<V8Platform>; | ||
|
||
V8Platform(); | ||
virtual ~V8Platform(); | ||
|
||
DISALLOW_COPY_AND_ASSIGN(V8Platform); | ||
}; | ||
|
||
} // namespace gin | ||
|
||
#endif // GIN_PUBLIC_V8_PLATFORM_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "gin/public/v8_platform.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/location.h" | ||
#include "base/message_loop/message_loop_proxy.h" | ||
#include "base/threading/worker_pool.h" | ||
#include "gin/per_isolate_data.h" | ||
|
||
namespace gin { | ||
|
||
namespace { | ||
|
||
base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; | ||
|
||
} // namespace | ||
|
||
// static | ||
V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); } | ||
|
||
V8Platform::V8Platform() {} | ||
|
||
V8Platform::~V8Platform() {} | ||
|
||
void V8Platform::CallOnBackgroundThread( | ||
v8::Task* task, | ||
v8::Platform::ExpectedRuntime expected_runtime) { | ||
base::WorkerPool::PostTask( | ||
FROM_HERE, | ||
base::Bind(&v8::Task::Run, base::Owned(task)), | ||
expected_runtime == v8::Platform::kLongRunningTask); | ||
} | ||
|
||
void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { | ||
PerIsolateData::From(isolate)->message_loop_proxy()->PostTask( | ||
FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task))); | ||
} | ||
|
||
} // namespace gin |