libaltos: Create altos_pause_one_second API
authorKeith Packard <keithp@keithp.com>
Wed, 26 Feb 2020 06:51:54 +0000 (22:51 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 26 Feb 2020 06:52:40 +0000 (22:52 -0800)
This is to wait for the reading thread to stop using the file object
while cleaning up.

Signed-off-by: Keith Packard <keithp@keithp.com>
libaltos/libaltos_common.c
libaltos/libaltos_posix.c
libaltos/libaltos_private.h
libaltos/libaltos_windows.c

index 6f0cbe6137d898ce2998de3628eb46213cd78575..fb8c314e3ae1b5f233d605090bbed39147f8a8e2 100644 (file)
@@ -117,16 +117,12 @@ int altos_bt_port(struct altos_bt_device *device) {
        return BT_PORT_DEFAULT;
 }
 
        return BT_PORT_DEFAULT;
 }
 
-#include <time.h>
-
 PUBLIC void
 altos_free(struct altos_file *file)
 {
        int i;
        altos_close(file);
 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);
 }
        free(file);
 }
index bf5d46998b19f10dbf321fae72458f13e38df07a..97eedd3be084dcae1a9c9962644bdbd58bdcf7cd 100644 (file)
@@ -200,3 +200,11 @@ altos_fill(struct altos_file *file_common, int timeout)
        return 0;
 }
 
        return 0;
 }
 
+#include <time.h>
+
+void
+altos_pause_one_second(void)
+{
+       struct timespec delay = { .tv_sec = 1, .tv_nsec = 0 };
+       nanosleep(&delay, NULL);
+}
index 45e141f9a0126b559c37ceac89817c9a967d9eff..f356eb6b4907996f4cfda52d0fa3588e80b06cac 100644 (file)
@@ -65,4 +65,7 @@ altos_fill(struct altos_file *file, int timeout);
 int
 altos_bt_port(struct altos_bt_device *device);
 
 int
 altos_bt_port(struct altos_bt_device *device);
 
+void
+altos_pause_one_second(void);
+
 #endif /* _LIBALTOS_PRIVATE_H_ */
 #endif /* _LIBALTOS_PRIVATE_H_ */
index 846e2217b4c7799ec155cd9870264eb798165b77..03c2958f52bc1a63b1a0dc71c01eb43a82472e8a 100644 (file)
@@ -760,3 +760,9 @@ altos_bt_open(struct altos_bt_device *device)
        }
        return &file->file;
 }
        }
        return &file->file;
 }
+
+void
+altos_pause_one_second(void)
+{
+       Sleep(1000);
+}