From decff0061739c00db9abc0e20a49c998ee26f212 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Thu, 29 Oct 2020 23:43:35 -0500 Subject: [PATCH] cdba-server: Change watch timers to ms In order to sleep for fractions of a second in alpaca, change the timeout from seconds to milliseconds. Signed-off-by: Bjorn Andersson --- cdba-server.c | 7 +++++-- cdba-server.h | 2 +- device.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cdba-server.c b/cdba-server.c index 784d1c4..9062aa7 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -276,9 +276,9 @@ void watch_add_readfd(int fd, int (*cb)(int, void*), void *data) list_add(&read_watches, &w->node); } -void watch_timer_add(int timeout, void (*cb)(void *), void *data) +void watch_timer_add(int timeout_ms, void (*cb)(void *), void *data) { - struct timeval tv_timeout = { timeout, }; + struct timeval tv_timeout; struct timeval now; struct timer *t; @@ -286,6 +286,9 @@ void watch_timer_add(int timeout, void (*cb)(void *), void *data) gettimeofday(&now, NULL); + tv_timeout.tv_sec = timeout_ms / 1000; + tv_timeout.tv_usec = (timeout_ms % 1000) * 1000; + t->cb = cb; t->data = data; timeradd(&now, &tv_timeout, &t->tv); diff --git a/cdba-server.h b/cdba-server.h index f0402db..5c870d7 100644 --- a/cdba-server.h +++ b/cdba-server.h @@ -8,7 +8,7 @@ void watch_add_readfd(int fd, int (*cb)(int, void*), void *data); int watch_add_quit(int (*cb)(int, void*), void *data); -void watch_timer_add(int timeout, void (*cb)(void *), void *data); +void watch_timer_add(int timeout_ms, void (*cb)(void *), void *data); void watch_quit(void); int watch_run(void); diff --git a/device.c b/device.c index d929b8c..25f185d 100644 --- a/device.c +++ b/device.c @@ -128,7 +128,7 @@ int device_power_on(struct device *device) device->power_on(device); if (device->fastboot_key_timeout) - watch_timer_add(device->fastboot_key_timeout, device_release_fastboot_key, device); + watch_timer_add(device->fastboot_key_timeout * 1000, device_release_fastboot_key, device); return 0; }