From b846842aff39cfbf0325ca895e661d2bd4a82fa2 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Thu, 30 May 2013 10:33:29 -0700 Subject: [PATCH] process: remove spinner Remove the need to call start/stop the uv_idle spinner between MakeCallbacks. The one place where the tick processor needs to be kicked is where a user catches uncaughtException. For that we'll now use setImmediate, which accomplishes the same task. --- src/node.cc | 42 ------------------------------------------ src/node.js | 19 ++----------------- 2 files changed, 2 insertions(+), 59 deletions(-) diff --git a/src/node.cc b/src/node.cc index 792e20facbf..461ecf4777b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -140,8 +140,6 @@ bool using_domains = false; bool no_deprecation = false; static uv_idle_t tick_spinner; -static bool need_tick_cb; -static Persistent tick_callback_sym; static uv_check_t check_immediate_watcher; static uv_idle_t idle_immediate_dummy; @@ -177,45 +175,6 @@ static uv_async_t emit_debug_enabled_async; Isolate* node_isolate = NULL; -static void Spin(uv_idle_t* handle, int status) { - assert(handle == &tick_spinner); - assert(status == 0); - - // Avoid entering a V8 scope. - if (!need_tick_cb) return; - need_tick_cb = false; - - uv_idle_stop(&tick_spinner); - - HandleScope scope(node_isolate); - - if (process_tickFromSpinner.IsEmpty()) { - Local cb_v = process->Get(String::New("_tickFromSpinner")); - if (!cb_v->IsFunction()) { - fprintf(stderr, "process._tickFromSpinner assigned to non-function\n"); - abort(); - } - Local cb = cb_v.As(); - process_tickFromSpinner = Persistent::New(node_isolate, cb); - } - - TryCatch try_catch; - - process_tickFromSpinner->Call(process, 0, NULL); - - if (try_catch.HasCaught()) { - FatalException(try_catch); - } -} - - -static Handle NeedTickCallback(const Arguments& args) { - need_tick_cb = true; - uv_idle_start(&tick_spinner, Spin); - return Undefined(node_isolate); -} - - static void CheckImmediate(uv_check_t* handle, int status) { assert(handle == &check_immediate_watcher); assert(status == 0); @@ -2378,7 +2337,6 @@ Handle SetupProcessObject(int argc, char *argv[]) { // define various internal methods NODE_SET_METHOD(process, "_getActiveRequests", GetActiveRequests); NODE_SET_METHOD(process, "_getActiveHandles", GetActiveHandles); - NODE_SET_METHOD(process, "_needTickCallback", NeedTickCallback); NODE_SET_METHOD(process, "reallyExit", Exit); NODE_SET_METHOD(process, "abort", Abort); NODE_SET_METHOD(process, "chdir", Chdir); diff --git a/src/node.js b/src/node.js index 6a09e68c56c..88d068aaa89 100644 --- a/src/node.js +++ b/src/node.js @@ -285,7 +285,7 @@ } // if we handled an error, then make sure any ticks get processed if (caught) - process._needTickCallback(); + setImmediate(process._tickCallback); return caught; }; }; @@ -316,7 +316,6 @@ }; startup.processNextTick = function() { - var _needTickCallback = process._needTickCallback; var lastThrew = false; var nextTickQueue = []; var needSpinner = true; @@ -336,7 +335,6 @@ process._nextDomainTick = _nextDomainTick; process._tickCallback = _tickCallback; process._tickDomainCallback = _tickDomainCallback; - process._tickFromSpinner = _tickFromSpinner; function tickDone() { if (infoBox[length] !== 0) { @@ -348,23 +346,10 @@ infoBox[length] = nextTickQueue.length; } } - if (needSpinner) { - _needTickCallback(); - needSpinner = false; - } inTick = false; infoBox[index] = 0; } - function _tickFromSpinner() { - needSpinner = true; - // no callbacks to run - if (infoBox[length] === 0) - infoBox[index] = 0; - else - process._tickCallback(); - } - // run callbacks that have no domain // using domains will cause this to be overridden function _tickCallback() { @@ -396,7 +381,7 @@ if (lastThrew) { lastThrew = false; - return _needTickCallback(); + return; } if (inTick) return;