diff --git a/include/uv-private/ev.h b/include/uv-private/ev.h index 5d2d7a1e3..11e81cda5 100644 --- a/include/uv-private/ev.h +++ b/include/uv-private/ev.h @@ -562,6 +562,8 @@ EV_MAYBE_UNUSED ev_is_default_loop (EV_P) /* create and destroy alternative loops that don't handle signals */ struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); +int ev_loop_refcount (EV_P); + ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ #else diff --git a/include/uv.h b/include/uv.h index a20070875..5928b4c16 100644 --- a/include/uv.h +++ b/include/uv.h @@ -200,6 +200,9 @@ typedef struct uv_work_s uv_work_t; UV_EXTERN uv_loop_t* uv_loop_new(void); UV_EXTERN void uv_loop_delete(uv_loop_t*); +/* This is a debugging tool. It's NOT part of the official API. */ +UV_EXTERN int uv_loop_refcount(const uv_loop_t*); + /* * Returns the default loop. diff --git a/src/unix/core.c b/src/unix/core.c index 486e83514..40fb3d95e 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -175,6 +175,11 @@ void uv_loop_delete(uv_loop_t* loop) { } +int uv_loop_refcount(const uv_loop_t* loop) { + return ev_loop_refcount(loop->ev); +} + + uv_loop_t* uv_default_loop(void) { if (!default_loop_ptr) { default_loop_ptr = &default_loop_struct; diff --git a/src/unix/ev/ev.c b/src/unix/ev/ev.c index a3bec43fb..b6e190f75 100644 --- a/src/unix/ev/ev.c +++ b/src/unix/ev/ev.c @@ -1958,6 +1958,12 @@ ev_loop_new (unsigned int flags) #endif /* multiplicity */ +int +ev_loop_refcount (EV_P) +{ + return activecnt; +} + #if EV_VERIFY static void noinline verify_watcher (EV_P_ W w) diff --git a/src/win/core.c b/src/win/core.c index 72fee1c80..b55c3cea4 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -116,6 +116,11 @@ void uv_loop_delete(uv_loop_t* loop) { } +int uv_loop_refcount(const uv_loop_t* loop) { + return loop->refs; +} + + void uv_ref(uv_loop_t* loop) { loop->refs++; }