From: Keith Packard Date: Wed, 26 Feb 2020 06:51:54 +0000 (-0800) Subject: libaltos: Create altos_pause_one_second API X-Git-Tag: 1.9.2~1^2^2~2 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=45f7b91ea126f8f9e607a8ee53df655d992590f2 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 --- 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); +}