Reviewers: Erik Corry,

Description:
The method yield is now available in the context created for threads in
the developer shell.

Added options --preemption/--no-preemption and --preemption-interval to
control preemption in the developer shell when running several threads.
Default is still to enable preemption with interval 1ms if threads are
created.

Please review this at http://codereview.chromium.org/48001

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/d8.h
   M     src/d8.cc


Index: src/d8.cc
===================================================================
--- src/d8.cc   (revision 1509)
+++ src/d8.cc   (working copy)
@@ -174,6 +174,12 @@
  }


+Handle<Value> Shell::Yield(const Arguments& args) {
+  v8::Unlocker unlocker;
+  return Undefined();
+}
+
+
  Handle<Value> Shell::Quit(const Arguments& args) {
    int exit_code = args[0]->Int32Value();
    OnExit();
@@ -481,6 +487,8 @@
                         FunctionTemplate::New(Shell::Print));
    global_template->Set(String::New("load"),
                         FunctionTemplate::New(Shell::Load));
+  global_template->Set(String::New("yield"),
+                       FunctionTemplate::New(Shell::Yield));
    global_template->Set(String::New("version"),
                         FunctionTemplate::New(Shell::Version));

@@ -530,6 +538,14 @@
    }
    Initialize();
    bool run_shell = (argc == 1);
+
+  // Default use preemption if threads are created.
+  bool use_preemption = true;
+
+  // Default to use lowest possible thread preemption interval to test as  
many
+  // edgecases as possible.
+  int preemption_interval = 1;
+
    i::List<i::Thread*> threads(1);

    {
@@ -542,6 +558,12 @@
        char* str = argv[i];
        if (strcmp(str, "--shell") == 0) {
          run_shell = true;
+      } else if (strcmp(str, "--preemption") == 0) {
+        use_preemption = true;
+      } else if (strcmp(str, "--no-preemption") == 0) {
+        use_preemption = false;
+      } else if (strcmp(str, "--preemption-interval") == 0 && i + 1 <  
argc) {
+        preemption_interval = strtol(argv[++i], NULL, 10);
        } else if (strcmp(str, "-f") == 0) {
          // Ignore any -f flags for compatibility with other stand-alone
          // JavaScript engines.
@@ -557,9 +579,6 @@
            return 1;
          i++;
        } else if (strcmp(str, "-p") == 0 && i + 1 < argc) {
-        // Use the lowest possible thread preemption interval to test as  
many
-        // edgecases as possible.
-        Locker::StartPreemption(1);
          int size = 0;
          const char *files = ReadChars(argv[++i], &size);
          if (files == NULL) return 1;
@@ -582,6 +601,11 @@
        }
      }

+    // Start preemption if threads have been created and preemption is  
enabled.
+    if (threads.length() > 0 && use_preemption) {
+      Locker::StartPreemption(preemption_interval);
+    }
+
      // Run the remote debugger if requested.
      if (i::FLAG_remote_debugger) {
        RunRemoteDebugger(i::FLAG_debugger_port);
Index: src/d8.h
===================================================================
--- src/d8.h    (revision 1509)
+++ src/d8.h    (working copy)
@@ -92,6 +92,7 @@
    static Handle<Value> DebugCommandToJSONRequest(Handle<String> command);

    static Handle<Value> Print(const Arguments& args);
+  static Handle<Value> Yield(const Arguments& args);
    static Handle<Value> Quit(const Arguments& args);
    static Handle<Value> Version(const Arguments& args);
    static Handle<Value> Load(const Arguments& args);



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to