From 51b53a89896a63d49e7e622133faf58dc681ce13 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Mon, 18 Jul 2011 01:07:04 +0200 Subject: Change timeout definition in Events API from struct timespec to pcilib_timeout_t --- event.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'event.c') diff --git a/event.c b/event.c index 8f00472..cc58c79 100644 --- a/event.c +++ b/event.c @@ -12,12 +12,21 @@ #include #include #include +#include #include "pci.h" #include "tools.h" #include "error.h" +#ifndef __timespec_defined +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif /* __timespec_defined */ + + pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event) { int i; pcilib_register_bank_t res; @@ -85,7 +94,7 @@ int pcilib_stop(pcilib_t *ctx) { return 0; } -pcilib_event_id_t pcilib_get_next_event(pcilib_t *ctx, pcilib_event_t event_mask, const struct timespec *timeout) { +pcilib_event_id_t pcilib_get_next_event(pcilib_t *ctx, pcilib_event_t event_mask, pcilib_timeout_t timeout) { pcilib_event_api_description_t *api; pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); @@ -221,15 +230,19 @@ static int pcilib_grab_callback(pcilib_event_t event, pcilib_event_id_t event_id return 0; } -int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **data, const struct timespec *timeout) { +int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **data, pcilib_timeout_t timeout) { int err; + struct timespec ts; pcilib_grab_callback_user_data_t user = {ctx, size, data}; err = pcilib_start(ctx, event_mask, pcilib_grab_callback, &user); if (!err) { - if (timeout) nanosleep(timeout, NULL); - else err = pcilib_trigger(ctx, event_mask, 0, NULL); + if (timeout) { + ts.tv_sec = timeout / 1000000; + ts.tv_nsec = 1000 * (timeout % 1000000); + nanosleep(&ts, NULL); + } else err = pcilib_trigger(ctx, event_mask, 0, NULL); } pcilib_stop(ctx); return 0; -- cgit v1.2.3