timing.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef _PCILIB_TIMING_H
  2. #define _PCILIB_TIMING_H
  3. #include <sys/time.h>
  4. #include <pcilib.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /**
  9. * Add the specified number of microseconds to the time stored in \p tv
  10. * @param[in,out] tv - timestamp
  11. * @param[in] timeout - number of microseconds to add
  12. * @return - error code or 0 for correctness
  13. */
  14. int pcilib_add_timeout(struct timeval *tv, pcilib_timeout_t timeout);
  15. /**
  16. * Computes the deadline by adding the specified number of microseconds to the current timestamp
  17. * @param[out] tv - the deadline
  18. * @param[in] timeout - number of microseconds to add
  19. * @return - error code or 0 for correctness
  20. */
  21. int pcilib_calc_deadline(struct timeval *tv, pcilib_timeout_t timeout);
  22. /**
  23. * Check if we are within \p timeout microseconds before the specified deadline or already past it
  24. * @param[in] tv - the deadline
  25. * @param[in] timeout - maximum number of microseconds before deadline
  26. * @return - 1 if we are within \p timeout microseconds before deadline or past it, 0 - otherwise
  27. */
  28. int pcilib_check_deadline(struct timeval *tv, pcilib_timeout_t timeout);
  29. /**
  30. * Compute the remaining time to deadline
  31. * @param[in] tv - the deadline
  32. * @return - number of microseconds until deadline or 0 if we are already past it
  33. */
  34. pcilib_timeout_t pcilib_calc_time_to_deadline(struct timeval *tv);
  35. /**
  36. * Executes sleep until the specified deadline
  37. * Real-time capabilities are not used. TThe sleep could wake slightly after the specified deadline.
  38. * @param[in] tv - the deadline
  39. * @return - error code or 0 for correctness
  40. */
  41. int pcilib_sleep_until_deadline(struct timeval *tv);
  42. /**
  43. * Computes the number of microseconds between 2 timestamps.
  44. * This function expects that \p tve is after \p tvs.
  45. * @param[in] tve - the end of the time interval
  46. * @param[in] tvs - the beginning of the time interval
  47. * @return - number of microseconds between two timestamps
  48. */
  49. pcilib_timeout_t pcilib_timediff(struct timeval *tve, struct timeval *tvs);
  50. /**
  51. * Compares two timestamps
  52. * @param[in] tv1 - the first timestamp
  53. * @param[in] tv2 - the second timestamp
  54. * @return - 0 if timestamps are equal, 1 if the first timestamp is after the second, or -1 if the second is after the first.
  55. */
  56. int pcilib_timecmp(struct timeval *tv1, struct timeval *tv2);
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* _PCILIB_TIMING_H */