Skip to content

Commit c0bde73

Browse files
trevnorrisaddaleax
authored andcommitted
src: implement native changes for async_hooks
Changes in the native code for the upcoming async_hooks module. These have been separated to help with review and testing. Changes include: * Introduce an async id stack that tracks recursive calls into async execution contexts. For performance reasons the id stack is held as a double* and assigned to a Float64Array. If the stack grows too large it is then placed in it's own stack and replaced with a new double*. This should accommodate arbitrarily large stacks. I'm not especially happy with the complexity involved with this async id stack, but it's also the fastest and most full proof way of handling it that I have found. * Add helper functions in Environment and AsyncWrap to work with the async id stack. * Add AsyncWrap::Reset() to allow AsyncWrap instances that have been placed in a resource pool, instead of being released, to be reinitialized. AsyncWrap::AsyncWrap() also now uses Reset() for initialization. * AsyncWrap* parent no longer needs to be passed via the constructor. * Introduce Environment::AsyncHooks class to contain the needed native functionality. This includes the pointer to the async id stack, and array of v8::Eternal<v8::String>'s that hold the names of all providers, mechanisms for storing/retrieving the trigger id, etc. * Introduce Environment::AsyncHooks::ExecScope as a way to track the current id and trigger id of function execution via RAII. * If the user passes --abort-on-uncaught-exception then instead of throwing the application will print a stack trace and abort. PR-URL: #12892 Ref: #11883 Ref: #8531 Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent fe2df3b commit c0bde73

23 files changed

+525
-292
lines changed

src/async-wrap-inl.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@
3636

3737
namespace node {
3838

39-
inline bool AsyncWrap::ran_init_callback() const {
40-
return static_cast<bool>(bits_ & 1);
39+
inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
40+
return provider_type_;
4141
}
4242

4343

44-
inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
45-
return static_cast<ProviderType>(bits_ >> 1);
44+
inline double AsyncWrap::get_id() const {
45+
return async_id_;
4646
}
4747

4848

49-
inline double AsyncWrap::get_id() const {
50-
return id_;
49+
inline double AsyncWrap::get_trigger_id() const {
50+
return trigger_id_;
5151
}
5252

5353

0 commit comments

Comments
 (0)