ff-timer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2015 John R. Bradley <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include <libavutil/avutil.h>
  18. #include <pthread.h>
  19. #include <stdbool.h>
  20. typedef void (*ff_timer_callback)(void *opaque);
  21. struct ff_timer {
  22. ff_timer_callback callback;
  23. void *opaque;
  24. pthread_mutex_t mutex;
  25. pthread_mutexattr_t mutexattr;
  26. pthread_cond_t cond;
  27. pthread_t timer_thread;
  28. uint64_t next_wake;
  29. bool needs_wake;
  30. bool abort;
  31. };
  32. typedef struct ff_timer ff_timer_t;
  33. bool ff_timer_init(struct ff_timer *timer,
  34. ff_timer_callback callback, void *opaque);
  35. void ff_timer_free(struct ff_timer *timer);
  36. void ff_timer_schedule(struct ff_timer *timer, uint64_t microseconds);