| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 007b2fa commit c6d5af5
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -420,7 +420,7 @@ void Environment::RegisterHandleCleanups() { | |||
| 420 | 420 | } | |
| 421 | 421 | ||
| 422 | 422 | void Environment::CleanupHandles() { | |
| 423 | - for (ReqWrap<uv_req_t>* request : req_wrap_queue_) | ||
| 423 | + for (ReqWrapBase* request : req_wrap_queue_) | ||
| 424 | 424 | request->Cancel(); | |
| 425 | 425 | ||
| 426 | 426 | for (HandleWrap* handle : handle_wrap_queue_) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -877,8 +877,7 @@ class Environment { | |||
| 877 | 877 | #endif | |
| 878 | 878 | ||
| 879 | 879 | typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue; | |
| 880 | - typedef ListHead<ReqWrap<uv_req_t>, &ReqWrap<uv_req_t>::req_wrap_queue_> | ||
| 881 | - ReqWrapQueue; | ||
| 880 | + typedef ListHead<ReqWrapBase, &ReqWrapBase::req_wrap_queue_> ReqWrapQueue; | ||
| 882 | 881 | ||
| 883 | 882 | inline HandleWrapQueue* handle_wrap_queue() { return &handle_wrap_queue_; } | |
| 884 | 883 | inline ReqWrapQueue* req_wrap_queue() { return &req_wrap_queue_; } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,15 +28,14 @@ | |||
| 28 | 28 | V(Environment_HandleWrapQueue, head_, ListNode_HandleWrap, \ | |
| 29 | 29 | Environment::HandleWrapQueue::head_) \ | |
| 30 | 30 | V(ListNode_HandleWrap, next_, uintptr_t, ListNode<HandleWrap>::next_) \ | |
| 31 | - V(ReqWrap, req_wrap_queue_, ListNode_ReqWrapQueue, \ | ||
| 32 | - ReqWrap<uv_req_t>::req_wrap_queue_) \ | ||
| 33 | 31 | V(Environment_ReqWrapQueue, head_, ListNode_ReqWrapQueue, \ | |
| 34 | 32 | Environment::ReqWrapQueue::head_) \ | |
| 35 | - V(ListNode_ReqWrap, next_, uintptr_t, ListNode<ReqWrap<uv_req_t>>::next_) | ||
| 33 | + V(ListNode_ReqWrap, next_, uintptr_t, ListNode<ReqWrapBase>::next_) | ||
| 36 | 34 | ||
| 37 | 35 | extern "C" { | |
| 38 | 36 | int nodedbg_const_ContextEmbedderIndex__kEnvironment__int; | |
| 39 | 37 | uintptr_t nodedbg_offset_ExternalString__data__uintptr_t; | |
| 38 | + uintptr_t nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue; | ||
| 40 | 39 | ||
| 41 | 40 | #define V(Class, Member, Type, Accessor) \ | |
| 42 | 41 | NODE_EXTERN uintptr_t NODEDBG_OFFSET(Class, Member, Type); | |
@@ -51,6 +50,9 @@ int GenDebugSymbols() { | |||
| 51 | 50 | ContextEmbedderIndex::kEnvironment; | |
| 52 | 51 | ||
| 53 | 52 | nodedbg_offset_ExternalString__data__uintptr_t = NODE_OFF_EXTSTR_DATA; | |
| 53 | + nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue = | ||
| 54 | + OffsetOf<ListNode<ReqWrapBase>, ReqWrap<uv_req_t>>( | ||
| 55 | + &ReqWrap<uv_req_t>::req_wrap_queue_); | ||
| 54 | 56 | ||
| 55 | 57 | #define V(Class, Member, Type, Accessor) \ | |
| 56 | 58 | NODEDBG_OFFSET(Class, Member, Type) = OffsetOf(&Accessor); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -252,7 +252,8 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { | |||
| 252 | 252 | Environment* env = Environment::GetCurrent(args); | |
| 253 | 253 | ||
| 254 | 254 | std::vector<Local<Value>> request_v; | |
| 255 | - for (auto w : *env->req_wrap_queue()) { | ||
| 255 | + for (ReqWrapBase* req_wrap : *env->req_wrap_queue()) { | ||
| 256 | + AsyncWrap* w = req_wrap->GetAsyncWrap(); | ||
| 256 | 257 | if (w->persistent().IsEmpty()) | |
| 257 | 258 | continue; | |
| 258 | 259 | request_v.push_back(w->GetOwner()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,16 +11,16 @@ | |||
| 11 | 11 | ||
| 12 | 12 | namespace node { | |
| 13 | 13 | ||
| 14 | + ReqWrapBase::ReqWrapBase(Environment* env) { | ||
| 15 | + env->req_wrap_queue()->PushBack(this); | ||
| 16 | + } | ||
| 17 | + | ||
| 14 | 18 | template <typename T> | |
| 15 | 19 | ReqWrap<T>::ReqWrap(Environment* env, | |
| 16 | 20 | v8::Local<v8::Object> object, | |
| 17 | 21 | AsyncWrap::ProviderType provider) | |
| 18 | - : AsyncWrap(env, object, provider) { | ||
| 19 | - | ||
| 20 | - // FIXME(bnoordhuis) The fact that a reinterpret_cast is needed is | ||
| 21 | - // arguably a good indicator that there should be more than one queue. | ||
| 22 | - env->req_wrap_queue()->PushBack(reinterpret_cast<ReqWrap<uv_req_t>*>(this)); | ||
| 23 | - | ||
| 22 | + : AsyncWrap(env, object, provider), | ||
| 23 | + ReqWrapBase(env) { | ||
| 24 | 24 | Reset(); | |
| 25 | 25 | } | |
| 26 | 26 | ||
@@ -51,6 +51,11 @@ void ReqWrap<T>::Cancel() { | |||
| 51 | 51 | uv_cancel(reinterpret_cast<uv_req_t*>(&req_)); | |
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | + template <typename T> | ||
| 55 | + AsyncWrap* ReqWrap<T>::GetAsyncWrap() { | ||
| 56 | + return this; | ||
| 57 | + } | ||
| 58 | + | ||
| 54 | 59 | // Below is dark template magic designed to invoke libuv functions that | |
| 55 | 60 | // initialize uv_req_t instances in a unified fashion, to allow easier | |
| 56 | 61 | // tracking of active/inactive requests. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,8 +10,24 @@ | |||
| 10 | 10 | ||
| 11 | 11 | namespace node { | |
| 12 | 12 | ||
| 13 | + class ReqWrapBase { | ||
| 14 | + public: | ||
| 15 | + explicit inline ReqWrapBase(Environment* env); | ||
| 16 | + | ||
| 17 | + virtual ~ReqWrapBase() {} | ||
| 18 | + | ||
| 19 | + virtual void Cancel() = 0; | ||
| 20 | + virtual AsyncWrap* GetAsyncWrap() = 0; | ||
| 21 | + | ||
| 22 | + private: | ||
| 23 | + friend int GenDebugSymbols(); | ||
| 24 | + friend class Environment; | ||
| 25 | + | ||
| 26 | + ListNode<ReqWrapBase> req_wrap_queue_; | ||
| 27 | + }; | ||
| 28 | + | ||
| 13 | 29 | template <typename T> | |
| 14 | - class ReqWrap : public AsyncWrap { | ||
| 30 | + class ReqWrap : public AsyncWrap, public ReqWrapBase { | ||
| 15 | 31 | public: | |
| 16 | 32 | inline ReqWrap(Environment* env, | |
| 17 | 33 | v8::Local<v8::Object> object, | |
@@ -23,21 +39,19 @@ class ReqWrap : public AsyncWrap { | |||
| 23 | 39 | // Call this after a request has finished, if re-using this object is planned. | |
| 24 | 40 | inline void Reset(); | |
| 25 | 41 | T* req() { return &req_; } | |
| 26 | - inline void Cancel(); | ||
| 42 | + inline void Cancel() final; | ||
| 43 | + inline AsyncWrap* GetAsyncWrap() override; | ||
| 27 | 44 | ||
| 28 | 45 | static ReqWrap* from_req(T* req); | |
| 29 | 46 | ||
| 30 | 47 | template <typename LibuvFunction, typename... Args> | |
| 31 | 48 | inline int Dispatch(LibuvFunction fn, Args... args); | |
| 32 | 49 | ||
| 33 | 50 | private: | |
| 34 | - friend class Environment; | ||
| 35 | 51 | friend int GenDebugSymbols(); | |
| 36 | 52 | template <typename ReqT, typename U> | |
| 37 | 53 | friend struct MakeLibuvRequestCallback; | |
| 38 | 54 | ||
| 39 | - ListNode<ReqWrap> req_wrap_queue_; | ||
| 40 | - | ||
| 41 | 55 | typedef void (*callback_t)(); | |
| 42 | 56 | callback_t original_callback_ = nullptr; | |
| 43 | 57 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments