This will differ on Linux and Darwin, at least.
[dsd: minor style tweaks]
if (!timeout)
return 0;
- r = clock_gettime(CLOCK_MONOTONIC, ¤t_time);
+ r = usbi_backend->clock_gettime(USBI_CLOCK_MONOTONIC, ¤t_time);
if (r < 0) {
usbi_err(ITRANSFER_CTX(transfer),
"failed to read monotonic clock, errno=%d", errno);
return 0;
}
- r = clock_gettime(CLOCK_REALTIME, &timeout);
+ r = usbi_backend->clock_gettime(USBI_CLOCK_REALTIME, &timeout);
if (r < 0) {
usbi_err(ctx, "failed to read realtime clock, error %d", errno);
return LIBUSB_ERROR_OTHER;
goto out;
/* get current time */
- r = clock_gettime(CLOCK_MONOTONIC, &systime_ts);
+ r = usbi_backend->clock_gettime(USBI_CLOCK_MONOTONIC, &systime_ts);
if (r < 0)
goto out;
return 0;
}
- r = clock_gettime(CLOCK_MONOTONIC, &cur_ts);
+ r = usbi_backend->clock_gettime(USBI_CLOCK_MONOTONIC, &cur_ts);
if (r < 0) {
usbi_err(ctx, "failed to read monotonic clock, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
#define USBI_TRANSFER_TIMED_OUT (1<<0)
+enum {
+ USBI_CLOCK_MONOTONIC,
+ USBI_CLOCK_REALTIME
+};
+
/* in-memory transfer layout:
*
* 1. struct usbi_transfer
int (*handle_events)(struct libusb_context *ctx,
struct pollfd *fds, nfds_t nfds, int num_ready);
+ /* Get time from specified clock. At least two clocks must be implemented
+ by the backend: USBI_CLOCK_REALTIME, and USBI_CLOCK_MONOTONIC.
+
+ Description of clocks:
+ USBI_CLOCK_REALTIME : clock returns time since system epoch.
+ USBI_CLOCK_MONOTONIC: clock returns time since unspecified start
+ time (usually boot).
+ */
+ int (*clock_gettime)(int clkid, struct timespec *tp);
+
/* Number of bytes to reserve for per-device private backend data.
* This private data area is accessible through the "os_priv" field of
* struct libusb_device. */
return r;
}
+static int op_clock_gettime(int clk_id, struct timespec *tp)
+{
+ switch (clk_id) {
+ case USBI_CLOCK_MONOTONIC:
+ return clock_gettime(CLOCK_MONOTONIC, tp);
+ case USBI_CLOCK_REALTIME:
+ return clock_gettime(CLOCK_REALTIME, tp);
+ default:
+ return LIBUSB_ERROR_INVALID_PARAM;
+ }
+}
+
const struct usbi_os_backend linux_usbfs_backend = {
.name = "Linux usbfs",
.init = op_init,
.handle_events = op_handle_events,
+ .clock_gettime = op_clock_gettime,
+
.device_priv_size = sizeof(struct linux_device_priv),
.device_handle_priv_size = sizeof(struct linux_device_handle_priv),
.transfer_priv_size = sizeof(struct linux_transfer_priv),