From 9dd14b2946eb821c1b8e5a5a8f81653710826a01 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Nov 2023 15:52:07 -0500 Subject: cmUVHandlePtr: Add uv_timer_ptr::stop method This was missing w.r.t. the pattern established for other handle wrappers. --- Source/cmUVHandlePtr.cxx | 6 ++++++ Source/cmUVHandlePtr.h | 2 ++ Tests/CMakeLib/testUVHandlePtr.cxx | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/Source/cmUVHandlePtr.cxx b/Source/cmUVHandlePtr.cxx index 951ef3b..ecd9030 100644 --- a/Source/cmUVHandlePtr.cxx +++ b/Source/cmUVHandlePtr.cxx @@ -241,6 +241,12 @@ int uv_timer_ptr::start(uv_timer_cb cb, uint64_t timeout, uint64_t repeat) return uv_timer_start(*this, cb, timeout, repeat); } +void uv_timer_ptr::stop() +{ + assert(this->handle); + uv_timer_stop(*this); +} + #ifndef CMAKE_BOOTSTRAP uv_tty_ptr::operator uv_stream_t*() const { diff --git a/Source/cmUVHandlePtr.h b/Source/cmUVHandlePtr.h index e1bf0d0..7f70b36 100644 --- a/Source/cmUVHandlePtr.h +++ b/Source/cmUVHandlePtr.h @@ -238,6 +238,8 @@ struct uv_timer_ptr : public uv_handle_ptr_ int init(uv_loop_t& loop, void* data = nullptr); int start(uv_timer_cb cb, uint64_t timeout, uint64_t repeat); + + void stop(); }; struct uv_tty_ptr : public uv_handle_ptr_ diff --git a/Tests/CMakeLib/testUVHandlePtr.cxx b/Tests/CMakeLib/testUVHandlePtr.cxx index 02f8954..d6fdb77 100644 --- a/Tests/CMakeLib/testUVHandlePtr.cxx +++ b/Tests/CMakeLib/testUVHandlePtr.cxx @@ -53,6 +53,16 @@ static bool testTimer() return false; } + timed = false; + timer.start(cb, 10, 0); + timer.stop(); + uv_run(loop, UV_RUN_DEFAULT); + + if (timed) { + std::cerr << "uv_timer_ptr::stop did not stop callback" << std::endl; + return false; + } + return true; } -- cgit v0.12