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 <surenb@google.com>
Merged-In: If0674eda954a25f0f6c9188501ff77db8ba0813b
Change-Id: If0674eda954a25f0f6c9188501ff77db8ba0813b
This commit is contained in:
Suren Baghdasaryan 2020-04-24 16:54:55 -07:00
parent c4081918a7
commit 3f84a211e5
1 changed files with 7 additions and 9 deletions

View File

@ -216,7 +216,6 @@ static android_log_context ctx;
enum polling_update { enum polling_update {
POLLING_DO_NOT_CHANGE, POLLING_DO_NOT_CHANGE,
POLLING_START, POLLING_START,
POLLING_STOP,
POLLING_PAUSE, POLLING_PAUSE,
POLLING_RESUME, POLLING_RESUME,
}; };
@ -2990,9 +2989,12 @@ static void call_handler(struct event_handler_info* handler_info,
struct polling_params *poll_params, uint32_t events) { struct polling_params *poll_params, uint32_t events) {
struct timespec curr_tm; struct timespec curr_tm;
poll_params->update = POLLING_DO_NOT_CHANGE;
handler_info->handler(handler_info->data, events, poll_params); handler_info->handler(handler_info->data, events, poll_params);
clock_gettime(CLOCK_MONOTONIC_COARSE, &curr_tm); 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) { switch (poll_params->update) {
case POLLING_START: case POLLING_START:
@ -3004,9 +3006,6 @@ static void call_handler(struct event_handler_info* handler_info,
poll_params->poll_start_tm = curr_tm; poll_params->poll_start_tm = curr_tm;
poll_params->poll_handler = handler_info; poll_params->poll_handler = handler_info;
break; break;
case POLLING_STOP:
poll_params->poll_handler = NULL;
break;
case POLLING_PAUSE: case POLLING_PAUSE:
poll_params->paused_handler = handler_info; poll_params->paused_handler = handler_info;
poll_params->poll_handler = NULL; poll_params->poll_handler = NULL;
@ -3019,11 +3018,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) { 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 */ /* Polled for the duration of PSI window, time to stop */
poll_params->poll_handler = NULL; poll_params->poll_handler = NULL;
poll_params->paused_handler = NULL;
} }
/* WARNING: skipping the rest of the function */ break;
return;
} }
poll_params->update = POLLING_DO_NOT_CHANGE;
} }
static void mainloop(void) { static void mainloop(void) {
@ -3034,7 +3032,7 @@ static void mainloop(void) {
long delay = -1; long delay = -1;
poll_params.poll_handler = NULL; poll_params.poll_handler = NULL;
poll_params.update = POLLING_DO_NOT_CHANGE; poll_params.paused_handler = NULL;
while (1) { while (1) {
struct epoll_event events[MAX_EPOLL_EVENTS]; struct epoll_event events[MAX_EPOLL_EVENTS];