diff options
author | Andreas Madsen <amwebdk@gmail.com> | 2017-09-26 15:50:10 +0200 |
---|---|---|
committer | Andreas Madsen <amwebdk@gmail.com> | 2017-09-26 15:50:10 +0200 |
commit | 3a69ef55e06cda552e7ad295ddf904e1c70ae13f (patch) | |
tree | a33643b534a256e0cefdb0a275b38ee5ee9defcf /lib | |
parent | f9e5709ea0bad223d44ade1760917764dca4c0cb (diff) | |
download | android-node-v8-3a69ef55e06cda552e7ad295ddf904e1c70ae13f.tar.gz android-node-v8-3a69ef55e06cda552e7ad295ddf904e1c70ae13f.tar.bz2 android-node-v8-3a69ef55e06cda552e7ad295ddf904e1c70ae13f.zip |
async_hooks: consistent internal naming
PR-URL: https://github.com/nodejs/node/pull/15569
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/async_hooks.js | 66 | ||||
-rw-r--r-- | lib/internal/bootstrap_node.js | 17 | ||||
-rw-r--r-- | lib/internal/process/next_tick.js | 26 | ||||
-rw-r--r-- | lib/timers.js | 34 |
4 files changed, 77 insertions, 66 deletions
diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 37ff565064..9bb3a993af 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -6,20 +6,21 @@ const errors = require('internal/errors'); * Environment::AsyncHooks::fields_[]. Each index tracks the number of active * hooks for each type. * - * async_uid_fields is a Float64Array wrapping the double array of + * async_id_fields is a Float64Array wrapping the double array of * Environment::AsyncHooks::uid_fields_[]. Each index contains the ids for the * various asynchronous states of the application. These are: - * kCurrentAsyncId: The async_id assigned to the resource responsible for the + * kExecutionAsyncId: The async_id assigned to the resource responsible for the * current execution stack. - * kCurrentTriggerId: The trigger_async_id of the resource responsible for the - * current execution stack. - * kAsyncUidCntr: Incremental counter tracking the next assigned async_id. - * kInitTriggerId: Written immediately before a resource's constructor that - * sets the value of the init()'s triggerAsyncId. The order of retrieving - * the triggerAsyncId value is passing directly to the constructor -> value - * set in kInitTriggerId -> executionAsyncId of the current resource. + * kTriggerAsyncId: The trigger_async_id of the resource responsible for + * the current execution stack. + * kAsyncIdCounter: Incremental counter tracking the next assigned async_id. + * kInitTriggerAsyncId: Written immediately before a resource's constructor + * that sets the value of the init()'s triggerAsyncId. The order of + * retrieving the triggerAsyncId value is passing directly to the + * constructor -> value set in kInitTriggerAsyncId -> executionAsyncId of + * the current resource. */ -const { async_hook_fields, async_uid_fields } = async_wrap; +const { async_hook_fields, async_id_fields } = async_wrap; // Store the pair executionAsyncId and triggerAsyncId in a std::stack on // Environment::AsyncHooks::ids_stack_ tracks the resource responsible for the // current execution stack. This is unwound as each resource exits. In the case @@ -58,14 +59,14 @@ const active_hooks = { // Each constant tracks how many callbacks there are for any given step of // async execution. These are tracked so if the user didn't include callbacks // for a given step, that step can bail out early. -const { kInit, kBefore, kAfter, kDestroy, kPromiseResolve, kTotals, - kCurrentAsyncId, kCurrentTriggerId, kAsyncUidCntr, - kInitTriggerId } = async_wrap.constants; +const { kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve, + kExecutionAsyncId, kTriggerAsyncId, kAsyncIdCounter, + kInitTriggerAsyncId } = async_wrap.constants; // Symbols used to store the respective ids on both AsyncResource instances and // internal resources. They will also be assigned to arbitrary objects passed // in by the user that take place of internally constructed objects. -const { async_id_symbol, trigger_id_symbol } = async_wrap; +const { async_id_symbol, trigger_async_id_symbol } = async_wrap; // Used in AsyncHook and AsyncResource. const init_symbol = Symbol('init'); @@ -234,12 +235,12 @@ function createHook(fns) { function executionAsyncId() { - return async_uid_fields[kCurrentAsyncId]; + return async_id_fields[kExecutionAsyncId]; } function triggerAsyncId() { - return async_uid_fields[kCurrentTriggerId]; + return async_id_fields[kTriggerAsyncId]; } @@ -258,14 +259,16 @@ class AsyncResource { triggerAsyncId); } - this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr]; - this[trigger_id_symbol] = triggerAsyncId; + this[async_id_symbol] = ++async_id_fields[kAsyncIdCounter]; + this[trigger_async_id_symbol] = triggerAsyncId; - emitInitScript(this[async_id_symbol], type, this[trigger_id_symbol], this); + emitInitScript( + this[async_id_symbol], type, this[trigger_async_id_symbol], this + ); } emitBefore() { - emitBeforeScript(this[async_id_symbol], this[trigger_id_symbol]); + emitBeforeScript(this[async_id_symbol], this[trigger_async_id_symbol]); return this; } @@ -284,7 +287,7 @@ class AsyncResource { } triggerAsyncId() { - return this[trigger_id_symbol]; + return this[trigger_async_id_symbol]; } } @@ -308,7 +311,7 @@ function runInAsyncIdScope(asyncId, cb) { // counter increment first. Since it's done the same way in // Environment::new_async_uid() function newUid() { - return ++async_uid_fields[kAsyncUidCntr]; + return ++async_id_fields[kAsyncIdCounter]; } @@ -316,20 +319,20 @@ function newUid() { // the user to safeguard this call and make sure it's zero'd out when the // constructor is complete. function initTriggerId() { - var tId = async_uid_fields[kInitTriggerId]; + var triggerAsyncId = async_id_fields[kInitTriggerAsyncId]; // Reset value after it's been called so the next constructor doesn't // inherit it by accident. - async_uid_fields[kInitTriggerId] = 0; - if (tId <= 0) - tId = async_uid_fields[kCurrentAsyncId]; - return tId; + async_id_fields[kInitTriggerAsyncId] = 0; + if (triggerAsyncId <= 0) + triggerAsyncId = async_id_fields[kExecutionAsyncId]; + return triggerAsyncId; } function setInitTriggerId(triggerAsyncId) { // CHECK(Number.isSafeInteger(triggerAsyncId)) // CHECK(triggerAsyncId > 0) - async_uid_fields[kInitTriggerId] = triggerAsyncId; + async_id_fields[kInitTriggerAsyncId] = triggerAsyncId; } @@ -346,8 +349,9 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) { if (triggerAsyncId === null) { triggerAsyncId = initTriggerId(); } else { - // If a triggerAsyncId was passed, any kInitTriggerId still must be null'd. - async_uid_fields[kInitTriggerId] = 0; + // If a triggerAsyncId was passed, any kInitTriggerAsyncId still must be + // null'd. + async_id_fields[kInitTriggerAsyncId] = 0; } if (!Number.isSafeInteger(asyncId) || asyncId < -1) { @@ -446,7 +450,7 @@ function emitDestroyScript(asyncId) { // Return early if there are no destroy callbacks, or invalid asyncId. if (async_hook_fields[kDestroy] === 0 || asyncId <= 0) return; - async_wrap.addIdToDestroyList(asyncId); + async_wrap.queueDestroyAsyncId(asyncId); } diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 3ce558611e..4a941b5385 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -354,17 +354,18 @@ function setupProcessFatal() { const async_wrap = process.binding('async_wrap'); // Arrays containing hook flags and ids for async_hook calls. - const { async_hook_fields, async_uid_fields } = async_wrap; + const { async_hook_fields, async_id_fields } = async_wrap; // Internal functions needed to manipulate the stack. - const { clearIdStack, asyncIdStackSize } = async_wrap; - const { kAfter, kCurrentAsyncId, kInitTriggerId } = async_wrap.constants; + const { clearAsyncIdStack, asyncIdStackSize } = async_wrap; + const { kAfter, kExecutionAsyncId, + kInitTriggerAsyncId } = async_wrap.constants; process._fatalException = function(er) { var caught; - // It's possible that kInitTriggerId was set for a constructor call that - // threw and was never cleared. So clear it now. - async_uid_fields[kInitTriggerId] = 0; + // It's possible that kInitTriggerAsyncId was set for a constructor call + // that threw and was never cleared. So clear it now. + async_id_fields[kInitTriggerAsyncId] = 0; if (process.domain && process.domain._errorHandler) caught = process.domain._errorHandler(er); @@ -392,11 +393,11 @@ if (async_hook_fields[kAfter] > 0) { do { NativeModule.require('async_hooks').emitAfter( - async_uid_fields[kCurrentAsyncId]); + async_id_fields[kExecutionAsyncId]); } while (asyncIdStackSize() > 0); // Or completely empty the id stack. } else { - clearIdStack(); + clearAsyncIdStack(); } } diff --git a/lib/internal/process/next_tick.js b/lib/internal/process/next_tick.js index 00698aee23..3854389a0e 100644 --- a/lib/internal/process/next_tick.js +++ b/lib/internal/process/next_tick.js @@ -54,12 +54,12 @@ function setupNextTick() { const emitPendingUnhandledRejections = promises.setup(scheduleMicrotasks); const initTriggerId = async_hooks.initTriggerId; // Two arrays that share state between C++ and JS. - const { async_hook_fields, async_uid_fields } = async_wrap; + const { async_hook_fields, async_id_fields } = async_wrap; // Used to change the state of the async id stack. const { emitInit, emitBefore, emitAfter, emitDestroy } = async_hooks; // Grab the constants necessary for working with internal arrays. - const { kInit, kDestroy, kAsyncUidCntr } = async_wrap.constants; - const { async_id_symbol, trigger_id_symbol } = async_wrap; + const { kInit, kDestroy, kAsyncIdCounter } = async_wrap.constants; + const { async_id_symbol, trigger_async_id_symbol } = async_wrap; var nextTickQueue = new NextTickQueue(); var microtasksScheduled = false; @@ -102,7 +102,7 @@ function setupNextTick() { args: undefined, domain: null, [async_id_symbol]: 0, - [trigger_id_symbol]: 0 + [trigger_async_id_symbol]: 0 }; function scheduleMicrotasks() { if (microtasksScheduled) @@ -158,10 +158,10 @@ function setupNextTick() { // CHECK(Number.isSafeInteger(tock[async_id_symbol])) // CHECK(tock[async_id_symbol] > 0) - // CHECK(Number.isSafeInteger(tock[trigger_id_symbol])) - // CHECK(tock[trigger_id_symbol] > 0) + // CHECK(Number.isSafeInteger(tock[trigger_async_id_symbol])) + // CHECK(tock[trigger_async_id_symbol] > 0) - emitBefore(tock[async_id_symbol], tock[trigger_id_symbol]); + emitBefore(tock[async_id_symbol], tock[trigger_async_id_symbol]); // emitDestroy() places the async_id_symbol into an asynchronous queue // that calls the destroy callback in the future. It's called before // calling tock.callback so destroy will be called even if the callback @@ -203,10 +203,10 @@ function setupNextTick() { // CHECK(Number.isSafeInteger(tock[async_id_symbol])) // CHECK(tock[async_id_symbol] > 0) - // CHECK(Number.isSafeInteger(tock[trigger_id_symbol])) - // CHECK(tock[trigger_id_symbol] > 0) + // CHECK(Number.isSafeInteger(tock[trigger_async_id_symbol])) + // CHECK(tock[trigger_async_id_symbol] > 0) - emitBefore(tock[async_id_symbol], tock[trigger_id_symbol]); + emitBefore(tock[async_id_symbol], tock[trigger_async_id_symbol]); // TODO(trevnorris): See comment in _tickCallback() as to why this // isn't a good solution. if (async_hook_fields[kDestroy] > 0) @@ -236,7 +236,7 @@ function setupNextTick() { this.args = args; this.domain = process.domain || null; this[async_id_symbol] = asyncId; - this[trigger_id_symbol] = triggerAsyncId; + this[trigger_async_id_symbol] = triggerAsyncId; } } @@ -261,7 +261,7 @@ function setupNextTick() { args[i - 1] = arguments[i]; } - const asyncId = ++async_uid_fields[kAsyncUidCntr]; + const asyncId = ++async_id_fields[kAsyncIdCounter]; const triggerAsyncId = initTriggerId(); const obj = new TickObject(callback, args, asyncId, triggerAsyncId); nextTickQueue.push(obj); @@ -297,7 +297,7 @@ function setupNextTick() { args[i - 2] = arguments[i]; } - const asyncId = ++async_uid_fields[kAsyncUidCntr]; + const asyncId = ++async_id_fields[kAsyncIdCounter]; const obj = new TickObject(callback, args, asyncId, triggerAsyncId); nextTickQueue.push(obj); ++tickInfo[kLength]; diff --git a/lib/timers.js b/lib/timers.js index 7bfed79d15..1c41d5d0f3 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -34,14 +34,14 @@ const debug = util.debuglog('timer'); const kOnTimeout = TimerWrap.kOnTimeout | 0; const initTriggerId = async_hooks.initTriggerId; // Two arrays that share state between C++ and JS. -const { async_hook_fields, async_uid_fields } = async_wrap; +const { async_hook_fields, async_id_fields } = async_wrap; // The needed emit*() functions. const { emitInit, emitBefore, emitAfter, emitDestroy } = async_hooks; // Grab the constants necessary for working with internal arrays. -const { kInit, kDestroy, kAsyncUidCntr } = async_wrap.constants; +const { kInit, kDestroy, kAsyncIdCounter } = async_wrap.constants; // Symbols for storing async id state. const async_id_symbol = Symbol('asyncId'); -const trigger_id_symbol = Symbol('triggerAsyncId'); +const trigger_async_id_symbol = Symbol('triggerAsyncId'); // Timeout values > TIMEOUT_MAX are set to 1. const TIMEOUT_MAX = 2147483647; // 2^31-1 @@ -169,10 +169,12 @@ function insert(item, unrefed) { if (!item[async_id_symbol] || item._destroyed) { item._destroyed = false; - item[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr]; - item[trigger_id_symbol] = initTriggerId(); + item[async_id_symbol] = ++async_id_fields[kAsyncIdCounter]; + item[trigger_async_id_symbol] = initTriggerId(); if (async_hook_fields[kInit] > 0) - emitInit(item[async_id_symbol], 'Timeout', item[trigger_id_symbol], item); + emitInit( + item[async_id_symbol], 'Timeout', item[trigger_async_id_symbol], item + ); } L.append(list, item); @@ -291,7 +293,7 @@ function tryOnTimeout(timer, list) { timer[async_id_symbol] : null; var threw = true; if (timerAsyncId !== null) - emitBefore(timerAsyncId, timer[trigger_id_symbol]); + emitBefore(timerAsyncId, timer[trigger_async_id_symbol]); try { ontimeout(timer); threw = false; @@ -560,10 +562,12 @@ function Timeout(after, callback, args) { this._timerArgs = args; this._repeat = null; this._destroyed = false; - this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr]; - this[trigger_id_symbol] = initTriggerId(); + this[async_id_symbol] = ++async_id_fields[kAsyncIdCounter]; + this[trigger_async_id_symbol] = initTriggerId(); if (async_hook_fields[kInit] > 0) - emitInit(this[async_id_symbol], 'Timeout', this[trigger_id_symbol], this); + emitInit( + this[async_id_symbol], 'Timeout', this[trigger_async_id_symbol], this + ); } @@ -733,7 +737,7 @@ function processImmediate() { // 4.7) what is in this smaller function. function tryOnImmediate(immediate, oldTail) { var threw = true; - emitBefore(immediate[async_id_symbol], immediate[trigger_id_symbol]); + emitBefore(immediate[async_id_symbol], immediate[trigger_async_id_symbol]); try { // make the actual call outside the try/finally to allow it to be optimized runCallback(immediate); @@ -798,10 +802,12 @@ function Immediate() { this._onImmediate = null; this._destroyed = false; this.domain = process.domain; - this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr]; - this[trigger_id_symbol] = initTriggerId(); + this[async_id_symbol] = ++async_id_fields[kAsyncIdCounter]; + this[trigger_async_id_symbol] = initTriggerId(); if (async_hook_fields[kInit] > 0) - emitInit(this[async_id_symbol], 'Immediate', this[trigger_id_symbol], this); + emitInit( + this[async_id_symbol], 'Immediate', this[trigger_async_id_symbol], this + ); } function setImmediate(callback, arg1, arg2, arg3) { |