Integrate the new poll function

Replace the manual polling, implemented using a combination of the
dc_iostream_get_available and dc_iostream_sleep functions, with the new
and more efficient poll function.
This commit is contained in:
Jef Driesen 2019-09-06 22:15:04 +02:00
parent f6fa2b84bc
commit af5716d685
3 changed files with 4 additions and 18 deletions

View File

@ -326,15 +326,7 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
}
if (delay && device->available == 0) {
unsigned int count = delay / 100;
for (unsigned int i = 0; i < count; ++i) {
size_t available = 0;
status = dc_iostream_get_available (device->iostream, &available);
if (status == DC_STATUS_SUCCESS && available > 0)
break;
dc_iostream_sleep (device->iostream, 100);
}
dc_iostream_poll (device->iostream, delay);
}
if (cmd != EXIT) {

View File

@ -177,13 +177,11 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Wait until some data arrives.
size_t available = 0;
while (dc_iostream_get_available (device->iostream, &available) == DC_STATUS_SUCCESS && available == 0) {
while (dc_iostream_poll (device->iostream, 100) == DC_STATUS_TIMEOUT) {
if (device_is_cancelled (abstract))
return DC_STATUS_CANCELLED;
device_event_emit (abstract, DC_EVENT_WAITING, NULL);
dc_iostream_sleep (device->iostream, 100);
}
// Receive the header of the package.

View File

@ -309,14 +309,13 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_device_t *abstract = (dc_device_t *) device;
size_t available = 0;
// Enable progress notifications.
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress);
// Waiting for greeting message.
while (dc_iostream_get_available (device->iostream, &available) == DC_STATUS_SUCCESS && available == 0) {
while (dc_iostream_poll (device->iostream, 300) == DC_STATUS_TIMEOUT) {
if (device_is_cancelled (abstract))
return DC_STATUS_CANCELLED;
@ -330,8 +329,6 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
ERROR (abstract->context, "Failed to reject the packet.");
return status;
}
dc_iostream_sleep (device->iostream, 300);
}
// Read the ID string.
@ -385,12 +382,11 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
}
// Wait for the data packet.
while (dc_iostream_get_available (device->iostream, &available) == DC_STATUS_SUCCESS && available == 0) {
while (dc_iostream_poll (device->iostream, 100) == DC_STATUS_TIMEOUT) {
if (device_is_cancelled (abstract))
return DC_STATUS_CANCELLED;
device_event_emit (&device->base, DC_EVENT_WAITING, NULL);
dc_iostream_sleep (device->iostream, 100);
}
// Fetch the current system time.