timeval.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef footimevalhfoo
  2. #define footimevalhfoo
  3. /***
  4. This file is part of PulseAudio.
  5. Copyright 2004-2006 Lennart Poettering
  6. Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
  7. PulseAudio is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as
  9. published by the Free Software Foundation; either version 2.1 of the
  10. License, or (at your option) any later version.
  11. PulseAudio is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
  17. ***/
  18. #include <pulse/cdecl.h>
  19. #include <pulse/gccmacro.h>
  20. #include <pulse/sample.h>
  21. #include <pulse/version.h>
  22. /** \file
  23. * Utility functions for handling timeval calculations */
  24. PA_C_DECL_BEGIN
  25. /** The number of milliseconds in a second */
  26. #define PA_MSEC_PER_SEC ((pa_usec_t) 1000ULL)
  27. /** The number of microseconds in a second */
  28. #define PA_USEC_PER_SEC ((pa_usec_t) 1000000ULL)
  29. /** The number of nanoseconds in a second */
  30. #define PA_NSEC_PER_SEC ((unsigned long long) 1000000000ULL)
  31. /** The number of microseconds in a millisecond */
  32. #define PA_USEC_PER_MSEC ((pa_usec_t) 1000ULL)
  33. /** The number of nanoseconds in a millisecond */
  34. #define PA_NSEC_PER_MSEC ((unsigned long long) 1000000ULL)
  35. /** The number of nanoseconds in a microsecond */
  36. #define PA_NSEC_PER_USEC ((unsigned long long) 1000ULL)
  37. /** Invalid time in usec. \since 0.9.15 */
  38. #define PA_USEC_INVALID ((pa_usec_t) -1)
  39. /** Biggest time in usec. \since 0.9.18 */
  40. #define PA_USEC_MAX ((pa_usec_t) -2)
  41. struct timeval;
  42. /** Return the current wallclock timestamp, just like UNIX gettimeofday(). */
  43. struct timeval *pa_gettimeofday(struct timeval *tv);
  44. /** Calculate the difference between the two specified timeval
  45. * structs. */
  46. pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) PA_GCC_PURE;
  47. /** Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwise */
  48. int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) PA_GCC_PURE;
  49. /** Return the time difference between now and the specified timestamp */
  50. pa_usec_t pa_timeval_age(const struct timeval *tv);
  51. /** Add the specified time in microseconds to the specified timeval structure */
  52. struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v);
  53. /** Subtract the specified time in microseconds to the specified timeval structure. \since 0.9.11 */
  54. struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v);
  55. /** Store the specified usec value in the timeval struct. \since 0.9.7 */
  56. struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v);
  57. /** Load the specified tv value and return it in usec. \since 0.9.7 */
  58. pa_usec_t pa_timeval_load(const struct timeval *tv);
  59. PA_C_DECL_END
  60. #endif