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>
This commit is contained in:
Andreas Madsen 2017-09-26 15:50:10 +02:00
parent f9e5709ea0
commit 3a69ef55e0
No known key found for this signature in database
GPG key ID: 2FEE61B3C9E40F20
21 changed files with 270 additions and 250 deletions

View file

@ -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);
}