unix, windows: add uv_has_ref() function

This commit is contained in:
Saúl Ibarra Corretgé 2013-04-17 00:16:42 +02:00 committed by Ben Noordhuis
parent aa23eea5cf
commit a92b66fe33
5 changed files with 23 additions and 0 deletions

View File

@ -281,6 +281,7 @@ UV_EXTERN void uv_stop(uv_loop_t*);
*/
UV_EXTERN void uv_ref(uv_handle_t*);
UV_EXTERN void uv_unref(uv_handle_t*);
UV_EXTERN int uv_has_ref(const uv_handle_t*);
UV_EXTERN void uv_update_time(uv_loop_t*);
UV_EXTERN uint64_t uv_now(uv_loop_t*);

View File

@ -426,6 +426,11 @@ void uv_unref(uv_handle_t* handle) {
}
int uv_has_ref(const uv_handle_t* handle) {
return uv__has_ref(handle);
}
void uv_stop(uv_loop_t* loop) {
loop->stop_flag = 1;
}

View File

@ -186,6 +186,9 @@ void uv__fs_poll_close(uv_fs_poll_t* handle);
} \
while (0)
#define uv__has_ref(h) \
(((h)->flags & UV__HANDLE_REF) != 0)
#if defined(_WIN32)
# define uv__handle_platform_init(h)
#else

View File

@ -128,6 +128,7 @@ TEST_DECLARE (pipe_ref2)
TEST_DECLARE (pipe_ref3)
TEST_DECLARE (pipe_ref4)
TEST_DECLARE (process_ref)
TEST_DECLARE (has_ref)
TEST_DECLARE (active)
TEST_DECLARE (embed)
TEST_DECLARE (async)
@ -377,6 +378,7 @@ TASK_LIST_START
TEST_ENTRY (pipe_ref4)
TEST_HELPER (pipe_ref4, pipe_echo_server)
TEST_ENTRY (process_ref)
TEST_ENTRY (has_ref)
TEST_ENTRY (loop_handles)
TEST_ENTRY (walk_handles)

View File

@ -413,3 +413,15 @@ TEST_IMPL(process_ref) {
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(has_ref) {
uv_idle_t h;
uv_idle_init(uv_default_loop(), &h);
uv_ref((uv_handle_t*)&h);
ASSERT(uv_has_ref((uv_handle_t*)&h) == 1);
uv_unref((uv_handle_t*)&h);
ASSERT(uv_has_ref((uv_handle_t*)&h) == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}