Skip to content

Commit

Permalink
process: remove spinner
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trevnorris committed May 30, 2013
1 parent 9a6c085 commit b846842
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
42 changes: 0 additions & 42 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> tick_callback_sym;

static uv_check_t check_immediate_watcher;
static uv_idle_t idle_immediate_dummy;
Expand Down Expand Up @@ -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<Value> cb_v = process->Get(String::New("_tickFromSpinner"));
if (!cb_v->IsFunction()) {
fprintf(stderr, "process._tickFromSpinner assigned to non-function\n");
abort();
}
Local<Function> cb = cb_v.As<Function>();
process_tickFromSpinner = Persistent<Function>::New(node_isolate, cb);
}

TryCatch try_catch;

process_tickFromSpinner->Call(process, 0, NULL);

if (try_catch.HasCaught()) {
FatalException(try_catch);
}
}


static Handle<Value> 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);
Expand Down Expand Up @@ -2378,7 +2337,6 @@ Handle<Object> 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);
Expand Down
19 changes: 2 additions & 17 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
Expand Down Expand Up @@ -316,7 +316,6 @@
};

startup.processNextTick = function() {
var _needTickCallback = process._needTickCallback;
var lastThrew = false;
var nextTickQueue = [];
var needSpinner = true;
Expand All @@ -336,7 +335,6 @@
process._nextDomainTick = _nextDomainTick;
process._tickCallback = _tickCallback;
process._tickDomainCallback = _tickDomainCallback;
process._tickFromSpinner = _tickFromSpinner;

function tickDone() {
if (infoBox[length] !== 0) {
Expand All @@ -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() {
Expand Down Expand Up @@ -396,7 +381,7 @@

if (lastThrew) {
lastThrew = false;
return _needTickCallback();
return;
}

if (inTick) return;
Expand Down

0 comments on commit b846842

Please sign in to comment.