From f21867a15cf16a1bd04df33c92acba7edcc724c2 Mon Sep 17 00:00:00 2001 From: Utkarsh Maheshwari Date: Fri, 30 Mar 2018 20:39:29 +0530 Subject: [PATCH] timer_pause: stop the timer resource (#8199) If the timer isn't stopped, it still emits events which consume some CPU. Fix #8188 --- src/nvim/eval.c | 6 ++++++ src/nvim/testdir/test_timers.vim | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0f7a1eb004..7bdfe7c9ee 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -16861,6 +16861,12 @@ static void f_timer_pause(typval_T *argvars, typval_T *unused, FunPtr fptr) int paused = (bool)tv_get_number(&argvars[1]); timer_T *timer = pmap_get(uint64_t)(timers, tv_get_number(&argvars[0])); if (timer != NULL) { + if (!timer->paused && paused) { + time_watcher_stop(&timer->tw); + } else if (timer->paused && !paused) { + time_watcher_start(&timer->tw, timer_due_cb, timer->timeout, + timer->timeout); + } timer->paused = paused; } } diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index d377062780..81ac2b6171 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -119,7 +119,7 @@ func Test_paused() let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call assert_inrange(0, 60, slept) + call assert_inrange(0, 100, slept) else call assert_inrange(0, 10, slept) endif