From a8b45e9e96269929a6e47b7b7e5ae17708e96bc6 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 19 Oct 2015 17:14:05 -0600 Subject: [PATCH] async_wrap: new instances get uid New instances of AsyncWrap are automatically assigned a unique id. The value will be used in future commits to communicate additional information via the async hooks. While the largest value we can reliably communicate to JS is 2^53, even if a new AsyncWrap is created every 100ns the uid won't reach its end for 28.5 years. PR-URL: https://github.com/nodejs/node/pull/3461 Reviewed-By: Fedor Indutny --- src/async-wrap-inl.h | 8 +++++++- src/async-wrap.h | 3 +++ src/env-inl.h | 5 +++++ src/env.h | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index cac8175889dfbf..9aaf67d3a8c518 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -17,7 +17,8 @@ inline AsyncWrap::AsyncWrap(Environment* env, v8::Local object, ProviderType provider, AsyncWrap* parent) - : BaseObject(env, object), bits_(static_cast(provider) << 1) { + : BaseObject(env, object), bits_(static_cast(provider) << 1), + uid_(env->get_async_wrap_uid()) { CHECK_NE(provider, PROVIDER_NONE); CHECK_GE(object->InternalFieldCount(), 1); @@ -66,6 +67,11 @@ inline AsyncWrap::ProviderType AsyncWrap::provider_type() const { } +inline int64_t AsyncWrap::get_uid() const { + return uid_; +} + + inline v8::Local AsyncWrap::MakeCallback( const v8::Local symbol, int argc, diff --git a/src/async-wrap.h b/src/async-wrap.h index 330f3454f42d2c..5fbd2309383d87 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -55,6 +55,8 @@ class AsyncWrap : public BaseObject { inline ProviderType provider_type() const; + inline int64_t get_uid() const; + // Only call these within a valid HandleScope. v8::Local MakeCallback(const v8::Local cb, int argc, @@ -76,6 +78,7 @@ class AsyncWrap : public BaseObject { // expected the context object will receive a _asyncQueue object property // that will be used to call pre/post in MakeCallback. uint32_t bits_; + const int64_t uid_; }; void LoadAsyncWrapperInfo(Environment* env); diff --git a/src/env-inl.h b/src/env-inl.h index 2d965f9a519232..f73e9c6ba2000a 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -210,6 +210,7 @@ inline Environment::Environment(v8::Local context, using_domains_(false), printed_error_(false), trace_sync_io_(false), + async_wrap_uid_(0), debugger_agent_(this), http_parser_buffer_(nullptr), context_(context->GetIsolate(), context) { @@ -359,6 +360,10 @@ inline void Environment::set_trace_sync_io(bool value) { trace_sync_io_ = value; } +inline int64_t Environment::get_async_wrap_uid() { + return ++async_wrap_uid_; +} + inline uint32_t* Environment::heap_statistics_buffer() const { CHECK_NE(heap_statistics_buffer_, nullptr); return heap_statistics_buffer_; diff --git a/src/env.h b/src/env.h index 185cc17294ec05..e41863ac74a698 100644 --- a/src/env.h +++ b/src/env.h @@ -442,6 +442,8 @@ class Environment { void PrintSyncTrace() const; inline void set_trace_sync_io(bool value); + inline int64_t get_async_wrap_uid(); + bool KickNextTick(); inline uint32_t* heap_statistics_buffer() const; @@ -537,6 +539,7 @@ class Environment { bool using_domains_; bool printed_error_; bool trace_sync_io_; + int64_t async_wrap_uid_; debugger::Agent debugger_agent_; HandleWrapQueue handle_wrap_queue_;