From 9ca5334683a7fa5e8bb56add0cd6b4d7ac28fb59 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Fri, 24 Apr 2020 16:54:55 -0700 Subject: [PATCH] lmkd: polling code cleanup - Remove unused POLLING_STOP state - Simplify POLLING_DO_NOT_CHANGE state handling - Correct last_poll_tm assignment logic Bug: 147315292 Test: lmkd_unit_test Signed-off-by: Suren Baghdasaryan Change-Id: If0674eda954a25f0f6c9188501ff77db8ba0813b --- lmkd.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lmkd.cpp b/lmkd.cpp index 701ada1..8691ad1 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -214,7 +214,6 @@ static android_log_context ctx; enum polling_update { POLLING_DO_NOT_CHANGE, POLLING_START, - POLLING_STOP, POLLING_PAUSE, POLLING_RESUME, }; @@ -2938,9 +2937,12 @@ static void call_handler(struct event_handler_info* handler_info, struct polling_params *poll_params, uint32_t events) { struct timespec curr_tm; + poll_params->update = POLLING_DO_NOT_CHANGE; handler_info->handler(handler_info->data, events, poll_params); clock_gettime(CLOCK_MONOTONIC_COARSE, &curr_tm); - poll_params->last_poll_tm = curr_tm; + if (poll_params->poll_handler == handler_info) { + poll_params->last_poll_tm = curr_tm; + } switch (poll_params->update) { case POLLING_START: @@ -2952,9 +2954,6 @@ static void call_handler(struct event_handler_info* handler_info, poll_params->poll_start_tm = curr_tm; poll_params->poll_handler = handler_info; break; - case POLLING_STOP: - poll_params->poll_handler = NULL; - break; case POLLING_PAUSE: poll_params->paused_handler = handler_info; poll_params->poll_handler = NULL; @@ -2967,11 +2966,10 @@ static void call_handler(struct event_handler_info* handler_info, if (get_time_diff_ms(&poll_params->poll_start_tm, &curr_tm) > PSI_WINDOW_SIZE_MS) { /* Polled for the duration of PSI window, time to stop */ poll_params->poll_handler = NULL; + poll_params->paused_handler = NULL; } - /* WARNING: skipping the rest of the function */ - return; + break; } - poll_params->update = POLLING_DO_NOT_CHANGE; } static void mainloop(void) { @@ -2982,7 +2980,7 @@ static void mainloop(void) { long delay = -1; poll_params.poll_handler = NULL; - poll_params.update = POLLING_DO_NOT_CHANGE; + poll_params.paused_handler = NULL; while (1) { struct epoll_event events[maxevents];