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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/d8.cc » ('j') | src/d8.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_D8_H_ 5 #ifndef V8_D8_H_
6 #define V8_D8_H_ 6 #define V8_D8_H_
7 7
8 #ifndef V8_SHARED 8 #ifndef V8_SHARED
9 #include "src/allocation.h" 9 #include "src/allocation.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
11 #include "src/list.h"
11 #include "src/smart-pointers.h" 12 #include "src/smart-pointers.h"
12 #include "src/v8.h" 13 #include "src/v8.h"
13 #else 14 #else
14 #include "include/v8.h" 15 #include "include/v8.h"
15 #include "src/base/compiler-specific.h" 16 #include "src/base/compiler-specific.h"
16 #endif // !V8_SHARED 17 #endif // !V8_SHARED
17 18
18 namespace v8 { 19 namespace v8 {
19 20
20 21
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 #endif // !V8_SHARED 161 #endif // !V8_SHARED
161 162
162 void ExitShell(int exit_code); 163 void ExitShell(int exit_code);
163 Handle<String> ReadFile(Isolate* isolate, const char* name); 164 Handle<String> ReadFile(Isolate* isolate, const char* name);
164 165
165 const char** argv_; 166 const char** argv_;
166 int begin_offset_; 167 int begin_offset_;
167 int end_offset_; 168 int end_offset_;
168 }; 169 };
169 170
171 #ifndef V8_SHARED
172 class Worker {
173 public:
174 Worker();
175 ~Worker();
176
177 void StartExecuteInThread(Isolate* isolate, const char* function_string,
178 const v8::SharedArrayBuffer::Contents& contents =
179 v8::SharedArrayBuffer::Contents());
180 Handle<Value> WaitForThread(Isolate* isolate);
181
182 private:
183 class WorkerThread : public base::Thread {
184 public:
185 explicit WorkerThread(Worker* worker)
186 : base::Thread(base::Thread::Options("WorkerThread")),
187 worker_(worker) {}
188
189 virtual void Run() { worker_->ExecuteInThread(); }
190
191 private:
192 Worker* worker_;
193 };
194
195 void ExecuteInThread();
196 void Cleanup();
197
198 base::Mutex mutex_;
199 base::Thread* thread_;
200 char* script_;
201 char* result_json_;
202 v8::SharedArrayBuffer::Contents contents_;
203 };
204 #endif // !V8_SHARED
205
170 206
171 class ShellOptions { 207 class ShellOptions {
172 public: 208 public:
173 ShellOptions() 209 ShellOptions()
174 : script_executed(false), 210 : script_executed(false),
175 last_run(true), 211 last_run(true),
176 send_idle_notification(false), 212 send_idle_notification(false),
177 invoke_weak_callbacks(false), 213 invoke_weak_callbacks(false),
178 omit_quit(false), 214 omit_quit(false),
179 stress_opt(false), 215 stress_opt(false),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 static void ReportException(Isolate* isolate, TryCatch* try_catch); 275 static void ReportException(Isolate* isolate, TryCatch* try_catch);
240 static Handle<String> ReadFile(Isolate* isolate, const char* name); 276 static Handle<String> ReadFile(Isolate* isolate, const char* name);
241 static Local<Context> CreateEvaluationContext(Isolate* isolate); 277 static Local<Context> CreateEvaluationContext(Isolate* isolate);
242 static int RunMain(Isolate* isolate, int argc, char* argv[]); 278 static int RunMain(Isolate* isolate, int argc, char* argv[]);
243 static int Main(int argc, char* argv[]); 279 static int Main(int argc, char* argv[]);
244 static void Exit(int exit_code); 280 static void Exit(int exit_code);
245 static void OnExit(Isolate* isolate); 281 static void OnExit(Isolate* isolate);
246 static void CollectGarbage(Isolate* isolate); 282 static void CollectGarbage(Isolate* isolate);
247 283
248 #ifndef V8_SHARED 284 #ifndef V8_SHARED
285 static void CleanupWorker(Isolate* isolate);
249 static Handle<Array> GetCompletions(Isolate* isolate, 286 static Handle<Array> GetCompletions(Isolate* isolate,
250 Handle<String> text, 287 Handle<String> text,
251 Handle<String> full); 288 Handle<String> full);
252 static int* LookupCounter(const char* name); 289 static int* LookupCounter(const char* name);
253 static void* CreateHistogram(const char* name, 290 static void* CreateHistogram(const char* name,
254 int min, 291 int min,
255 int max, 292 int max,
256 size_t buckets); 293 size_t buckets);
257 static void AddHistogramSample(void* histogram, int sample); 294 static void AddHistogramSample(void* histogram, int sample);
258 static void MapCounters(v8::Isolate* isolate, const char* name); 295 static void MapCounters(v8::Isolate* isolate, const char* name);
(...skipping 23 matching lines...) Expand all
282 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args); 319 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
283 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); 320 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
284 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); 321 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
285 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); 322 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
286 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); 323 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
287 static Handle<String> ReadFromStdin(Isolate* isolate); 324 static Handle<String> ReadFromStdin(Isolate* isolate);
288 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { 325 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
289 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); 326 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
290 } 327 }
291 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args); 328 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
329 static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args);
330 static void WorkerJoin(const v8::FunctionCallbackInfo<v8::Value>& args);
292 // The OS object on the global object contains methods for performing 331 // The OS object on the global object contains methods for performing
293 // operating system calls: 332 // operating system calls:
294 // 333 //
295 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will 334 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
296 // run the command, passing the arguments to the program. The standard output 335 // run the command, passing the arguments to the program. The standard output
297 // of the program will be picked up and returned as a multiline string. If 336 // of the program will be picked up and returned as a multiline string. If
298 // timeout1 is present then it should be a number. -1 indicates no timeout 337 // timeout1 is present then it should be a number. -1 indicates no timeout
299 // and a positive number is used as a timeout in milliseconds that limits the 338 // and a positive number is used as a timeout in milliseconds that limits the
300 // time spent waiting between receiving output characters from the program. 339 // time spent waiting between receiving output characters from the program.
301 // timeout2, if present, should be a number indicating the limit in 340 // timeout2, if present, should be a number indicating the limit in
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 #ifndef V8_SHARED 373 #ifndef V8_SHARED
335 static Persistent<Context> utility_context_; 374 static Persistent<Context> utility_context_;
336 static CounterMap* counter_map_; 375 static CounterMap* counter_map_;
337 // We statically allocate a set of local counters to be used if we 376 // We statically allocate a set of local counters to be used if we
338 // don't want to store the stats in a memory-mapped file 377 // don't want to store the stats in a memory-mapped file
339 static CounterCollection local_counters_; 378 static CounterCollection local_counters_;
340 static CounterCollection* counters_; 379 static CounterCollection* counters_;
341 static base::OS::MemoryMappedFile* counters_file_; 380 static base::OS::MemoryMappedFile* counters_file_;
342 static base::Mutex context_mutex_; 381 static base::Mutex context_mutex_;
343 static const base::TimeTicks kInitialTicks; 382 static const base::TimeTicks kInitialTicks;
383 static Worker worker_;
384 static i::List<v8::SharedArrayBuffer::Contents> externalized_shared_contents_;
344 385
345 static Counter* GetCounter(const char* name, bool is_histogram); 386 static Counter* GetCounter(const char* name, bool is_histogram);
346 static void InstallUtilityScript(Isolate* isolate); 387 static void InstallUtilityScript(Isolate* isolate);
347 #endif // !V8_SHARED 388 #endif // !V8_SHARED
348 static void Initialize(Isolate* isolate); 389 static void Initialize(Isolate* isolate);
349 static void InitializeDebugger(Isolate* isolate); 390 static void InitializeDebugger(Isolate* isolate);
350 static void RunShell(Isolate* isolate); 391 static void RunShell(Isolate* isolate);
351 static bool SetOptions(int argc, char* argv[]); 392 static bool SetOptions(int argc, char* argv[]);
352 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); 393 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
353 }; 394 };
354 395
355 396
356 } // namespace v8 397 } // namespace v8
357 398
358 399
359 #endif // V8_D8_H_ 400 #endif // V8_D8_H_
OLDNEW
« 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