timer_pause: stop the timer resource (#8199)

If the timer isn't stopped, it still emits events which consume some CPU.

Fix #8188
This commit is contained in:
Utkarsh Maheshwari
2018-03-30 20:39:29 +05:30
committed by Justin M. Keyes
parent e54ff10d44
commit f21867a15c
2 changed files with 7 additions and 1 deletions

View File

@@ -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;
}
}