From 45f7b91ea126f8f9e607a8ee53df655d992590f2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 25 Feb 2020 22:51:54 -0800 Subject: [PATCH] libaltos: Create altos_pause_one_second API This is to wait for the reading thread to stop using the file object while cleaning up. Signed-off-by: Keith Packard --- libaltos/libaltos_common.c | 8 ++------ libaltos/libaltos_posix.c | 8 ++++++++ libaltos/libaltos_private.h | 3 +++ libaltos/libaltos_windows.c | 6 ++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libaltos/libaltos_common.c b/libaltos/libaltos_common.c index 6f0cbe61..fb8c314e 100644 --- a/libaltos/libaltos_common.c +++ b/libaltos/libaltos_common.c @@ -117,16 +117,12 @@ int altos_bt_port(struct altos_bt_device *device) { return BT_PORT_DEFAULT; } -#include - PUBLIC void altos_free(struct altos_file *file) { int i; altos_close(file); - for (i = 0; i < 10 && file->busy; i++) { - struct timespec delay = { .tv_sec = 1, .tv_nsec = 0 }; - nanosleep(&delay, NULL); - } + for (i = 0; i < 10 && file->busy; i++) + altos_pause_one_second(); free(file); } diff --git a/libaltos/libaltos_posix.c b/libaltos/libaltos_posix.c index bf5d4699..97eedd3b 100644 --- a/libaltos/libaltos_posix.c +++ b/libaltos/libaltos_posix.c @@ -200,3 +200,11 @@ altos_fill(struct altos_file *file_common, int timeout) return 0; } +#include + +void +altos_pause_one_second(void) +{ + struct timespec delay = { .tv_sec = 1, .tv_nsec = 0 }; + nanosleep(&delay, NULL); +} diff --git a/libaltos/libaltos_private.h b/libaltos/libaltos_private.h index 45e141f9..f356eb6b 100644 --- a/libaltos/libaltos_private.h +++ b/libaltos/libaltos_private.h @@ -65,4 +65,7 @@ altos_fill(struct altos_file *file, int timeout); int altos_bt_port(struct altos_bt_device *device); +void +altos_pause_one_second(void); + #endif /* _LIBALTOS_PRIVATE_H_ */ diff --git a/libaltos/libaltos_windows.c b/libaltos/libaltos_windows.c index 846e2217..03c2958f 100644 --- a/libaltos/libaltos_windows.c +++ b/libaltos/libaltos_windows.c @@ -760,3 +760,9 @@ altos_bt_open(struct altos_bt_device *device) } return &file->file; } + +void +altos_pause_one_second(void) +{ + Sleep(1000); +} -- 2.30.2