summaryrefslogtreecommitdiff
path: root/src/handle_wrap.h
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-04-26 12:01:46 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2016-04-27 16:26:05 +0200
commitcad1a62d325b011887349687962700dfe7510525 (patch)
tree2b6d543bb4cc90870fa13be80f0c4ea81a1795bb /src/handle_wrap.h
parent23818c6d0ba5503263f97bcd888b1c227b3177af (diff)
downloadandroid-node-v8-cad1a62d325b011887349687962700dfe7510525.tar.gz
android-node-v8-cad1a62d325b011887349687962700dfe7510525.tar.bz2
android-node-v8-cad1a62d325b011887349687962700dfe7510525.zip
src: use libuv's refcounting directly
Don't implement an additional reference counting scheme on top of libuv. Libuv is the canonical source for that information so use it directly. PR-URL: https://github.com/nodejs/node/pull/6395 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/handle_wrap.h')
-rw-r--r--src/handle_wrap.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/handle_wrap.h b/src/handle_wrap.h
index d945143d31..fe3c5a8d9d 100644
--- a/src/handle_wrap.h
+++ b/src/handle_wrap.h
@@ -38,7 +38,15 @@ class HandleWrap : public AsyncWrap {
static void Unrefed(const v8::FunctionCallbackInfo<v8::Value>& args);
static inline bool IsAlive(const HandleWrap* wrap) {
- return wrap != nullptr && wrap->GetHandle() != nullptr;
+ // XXX(bnoordhuis) It's debatable whether only kInitialized should
+ // count as alive but it's compatible with the check that it replaces.
+ return wrap != nullptr && wrap->state_ == kInitialized;
+ }
+
+ static inline bool HasRef(const HandleWrap* wrap) {
+ return wrap != nullptr &&
+ wrap->state_ != kClosed &&
+ uv_has_ref(wrap->GetHandle());
}
inline uv_handle_t* GetHandle() const { return handle__; }
@@ -56,13 +64,10 @@ class HandleWrap : public AsyncWrap {
friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
static void OnClose(uv_handle_t* handle);
ListNode<HandleWrap> handle_wrap_queue_;
- unsigned int flags_;
+ enum { kInitialized, kClosing, kClosingWithCallback, kClosed } state_;
// Using double underscore due to handle_ member in tcp_wrap. Probably
// tcp_wrap should rename it's member to 'handle'.
- uv_handle_t* handle__;
-
- static const unsigned int kUnref = 1;
- static const unsigned int kCloseCallback = 2;
+ uv_handle_t* const handle__;
};