[ I notice that I lost the subsurface list, because Miika just sent
the strace to me in private. So when I replied with a test patch, it
only went to Miika and Dirk ]
On Thu, Jul 12, 2018 at 1:31 PM Linus Torvalds
<[email protected]> wrote:
>
> So considering that this clearly works for *some* people, maybe it's
> literally some timing issue.
.. and looking around in libdivecomputer history, this *used* do be
dc_serial_sleep(), and that just did a nanosleep() internally - and we
never overrode it in our custom serial implementation, because why
would we?
So as libdivecomputer switched "dc_serial_sleep()" to
"dc_iostream_sleep()", we subtly lost the sleep entirely unless the
custom IO implemented it.
In other words, my test patch looks like it really could be very
relevant. Any divecomputer that actually depended on the delay
suddenly got none.
So here's the patch attached again, this time for the whole list in
case somebody else can test it too (eg Anton).
Still entirely untested, but it *did* compile at least once by pure
luck. And this time I added the ftdi case too - which also didn't have
the actual sleep callback, although it did implement the function.
So this could have affected ftdi in addition to bluetooth.
Linus
core/qtserialbluetooth.cpp | 11 +++++++++--
core/serial_ftdi.c | 8 +++++---
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp
index 0d3e798cf..93c12c59d 100644
--- a/core/qtserialbluetooth.cpp
+++ b/core/qtserialbluetooth.cpp
@@ -6,6 +6,7 @@
#include <QEventLoop>
#include <QTimer>
#include <QDebug>
+#include <QThread>
#include <libdivecomputer/version.h>
#include <libdivecomputer/context.h>
@@ -367,6 +368,12 @@ static dc_status_t qt_serial_set_timeout(void *io, int timeout)
return DC_STATUS_SUCCESS;
}
+static dc_status_t qt_custom_sleep(void *io, unsigned int timeout)
+{
+ QThread::msleep(timeout);
+ return DC_STATUS_SUCCESS;
+}
+
#ifdef BLE_SUPPORT
dc_status_t
ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr, void *userdata)
@@ -387,7 +394,7 @@ ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* dev
qt_ble_write, /* write */
NULL, /* flush */
NULL, /* purge */
- NULL, /* sleep */
+ qt_custom_sleep, /* sleep */
qt_ble_close, /* close */
};
@@ -420,7 +427,7 @@ rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char*
qt_serial_write, /* write */
NULL, /* flush */
qt_serial_purge, /* purge */
- NULL, /* sleep */
+ qt_custom_sleep, /* sleep */
qt_serial_close, /* close */
};
diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c
index 6d99672f2..9bcf7aba0 100644
--- a/core/serial_ftdi.c
+++ b/core/serial_ftdi.c
@@ -98,12 +98,14 @@ static dc_status_t serial_ftdi_get_transmitted (ftdi_serial_t *device)
return DC_STATUS_UNSUPPORTED;
}
-static dc_status_t serial_ftdi_sleep (ftdi_serial_t *device, unsigned long timeout)
+static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout)
{
+ ftdi_serial_t *device = io;
+
if (device == NULL)
return DC_STATUS_INVALIDARGS;
- INFO (device->context, "Sleep: value=%lu", timeout);
+ INFO (device->context, "Sleep: value=%u", timeout);
struct timespec ts;
ts.tv_sec = (timeout / 1000);
@@ -541,7 +543,7 @@ dc_status_t ftdi_open(dc_iostream_t **iostream, dc_context_t *context)
serial_ftdi_write, /* write */
NULL, /* flush */
serial_ftdi_purge, /* purge */
- NULL, /* sleep */
+ serial_ftdi_sleep, /* sleep */
serial_ftdi_close, /* close */
};
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface