Browse Source

process: separate nextTick domain logic

It's cleaner to only load domain ticker logic when the domains are being
used. This makes execution slightly quicker in both cases, and simpler
from the spinner since there is no need to check if the latest callback
requires use of domains.
v0.9.11-release
Trevor Norris 12 years ago
committed by isaacs
parent
commit
0c1e7b53d0
  1. 4
      lib/domain.js
  2. 33
      src/node.js
  3. 2
      test/message/max_tick_depth_trace.out

4
lib/domain.js

@ -32,6 +32,10 @@ var endMethods = ['end', 'abort', 'destroy', 'destroySoon'];
// a few side effects. // a few side effects.
events.usingDomains = true; events.usingDomains = true;
// replace tickers with domain specific implementation
process.nextTick = process._nextDomainTick;
process._tickCallback = process._tickDomainCallback;
exports.Domain = Domain; exports.Domain = Domain;
exports.create = exports.createDomain = function(cb) { exports.create = exports.createDomain = function(cb) {

33
src/node.js

@ -305,7 +305,6 @@
startup.processNextTick = function() { startup.processNextTick = function() {
var _needTickCallback = process._needTickCallback; var _needTickCallback = process._needTickCallback;
var nextTickQueue = []; var nextTickQueue = [];
var usingDomains = false;
var needSpinner = true; var needSpinner = true;
var inTick = false; var inTick = false;
@ -324,6 +323,7 @@
// needs to be accessible from cc land // needs to be accessible from cc land
process._tickDomainCallback = _tickDomainCallback; process._tickDomainCallback = _tickDomainCallback;
process.nextTick = nextTick; process.nextTick = nextTick;
process._nextDomainTick = _nextDomainTick;
// the maximum number of times it'll process something like // the maximum number of times it'll process something like
// nextTick(function f(){nextTick(f)}) // nextTick(function f(){nextTick(f)})
@ -372,10 +372,7 @@
// no callbacks to run // no callbacks to run
if (infoBox[length] === 0) if (infoBox[length] === 0)
return infoBox[index] = infoBox[depth] = 0; return infoBox[index] = infoBox[depth] = 0;
if (nextTickQueue[infoBox[length] - 1].domain) process._tickCallback();
_tickDomainCallback();
else
_tickCallback();
} }
// run callbacks that have no domain // run callbacks that have no domain
@ -467,15 +464,25 @@
if (infoBox[depth] >= process.maxTickDepth) if (infoBox[depth] >= process.maxTickDepth)
maxTickWarn(); maxTickWarn();
var obj = { callback: callback }; var obj = { callback: callback, domain: null };
if (process.domain !== null) {
obj.domain = process.domain; nextTickQueue.push(obj);
// user has opt'd to use domains, so override default functionality infoBox[length]++;
if (!usingDomains) {
process._tickCallback = _tickDomainCallback; if (needSpinner) {
usingDomains = true; _needTickCallback();
} needSpinner = false;
} }
}
function _nextDomainTick(callback) {
// on the way out, don't bother. it won't get fired anyway.
if (process._exiting)
return;
if (infoBox[depth] >= process.maxTickDepth)
maxTickWarn();
var obj = { callback: callback, domain: process.domain };
nextTickQueue.push(obj); nextTickQueue.push(obj);
infoBox[length]++; infoBox[length]++;

2
test/message/max_tick_depth_trace.out

@ -30,6 +30,6 @@ Trace: (node) warning: Recursive process.nextTick detected. This will break in t
at maxTickWarn (node.js:*:*) at maxTickWarn (node.js:*:*)
at process.nextTick (node.js:*:*) at process.nextTick (node.js:*:*)
at f (*test*message*max_tick_depth_trace.js:*:*) at f (*test*message*max_tick_depth_trace.js:*:*)
at _tickCallback (node.js:*:*) at process._tickCallback (node.js:*:*)
at process._tickFromSpinner (node.js:*:*) at process._tickFromSpinner (node.js:*:*)
tick 0 tick 0

Loading…
Cancel
Save