Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: src/d8.h

Issue 1185643004: Add d8 API for spawning function on a new thread. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/d8.cc » ('j') | src/d8.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index 3b06059323c81f1a4f7810d348d07a095790a22b..21cba88a3eda2fe82e4b99601947e7dabe414cd2 100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -8,6 +8,7 @@
#ifndef V8_SHARED
#include "src/allocation.h"
#include "src/hashmap.h"
+#include "src/list.h"
#include "src/smart-pointers.h"
#include "src/v8.h"
#else
@@ -167,6 +168,41 @@ class SourceGroup {
int end_offset_;
};
+#ifndef V8_SHARED
+class Worker {
+ public:
+ Worker();
+ ~Worker();
+
+ void StartExecuteInThread(Isolate* isolate, const char* function_string,
+ const v8::SharedArrayBuffer::Contents& contents =
+ v8::SharedArrayBuffer::Contents());
+ Handle<Value> WaitForThread(Isolate* isolate);
+
+ private:
+ class WorkerThread : public base::Thread {
+ public:
+ explicit WorkerThread(Worker* worker)
+ : base::Thread(base::Thread::Options("WorkerThread")),
+ worker_(worker) {}
+
+ virtual void Run() { worker_->ExecuteInThread(); }
+
+ private:
+ Worker* worker_;
+ };
+
+ void ExecuteInThread();
+ void Cleanup();
+
+ base::Mutex mutex_;
+ base::Thread* thread_;
+ char* script_;
+ char* result_json_;
+ v8::SharedArrayBuffer::Contents contents_;
+};
+#endif // !V8_SHARED
+
class ShellOptions {
public:
@@ -246,6 +282,7 @@ class Shell : public i::AllStatic {
static void CollectGarbage(Isolate* isolate);
#ifndef V8_SHARED
+ static void CleanupWorker(Isolate* isolate);
static Handle<Array> GetCompletions(Isolate* isolate,
Handle<String> text,
Handle<String> full);
@@ -289,6 +326,8 @@ class Shell : public i::AllStatic {
args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
}
static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void WorkerJoin(const v8::FunctionCallbackInfo<v8::Value>& args);
// The OS object on the global object contains methods for performing
// operating system calls:
//
@@ -341,6 +380,8 @@ class Shell : public i::AllStatic {
static base::OS::MemoryMappedFile* counters_file_;
static base::Mutex context_mutex_;
static const base::TimeTicks kInitialTicks;
+ static Worker worker_;
+ static i::List<v8::SharedArrayBuffer::Contents> externalized_shared_contents_;
static Counter* GetCounter(const char* name, bool is_histogram);
static void InstallUtilityScript(Isolate* isolate);
« no previous file with comments | « no previous file | src/d8.cc » ('j') | src/d8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698